1 15 package org.apache.hivemind.conditional; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 19 25 public class TestLexer extends HiveMindTestCase 26 { 27 public void testKeywords() 28 { 29 Lexer l = new Lexer("and OR Not class Property"); 30 31 assertSame(TokenType.AND, l.next().getType()); 32 assertSame(TokenType.OR, l.next().getType()); 33 assertSame(TokenType.NOT, l.next().getType()); 34 assertSame(TokenType.CLASS, l.next().getType()); 35 assertSame(TokenType.PROPERTY, l.next().getType()); 36 37 assertNull(l.next()); 38 } 39 40 public void testComplexSymbol() 41 { 42 Lexer l = new Lexer("property foo.bar-baz"); 43 44 assertSame(TokenType.PROPERTY, l.next().getType()); 45 46 Token t = l.next(); 47 48 assertSame(TokenType.SYMBOL, t.getType()); 49 assertEquals("foo.bar-baz", t.getValue()); 50 } 51 52 public void testParens() 53 { 54 Lexer l = new Lexer("not (property foo)"); 55 assertSame(TokenType.NOT, l.next().getType()); 56 assertSame(TokenType.OPAREN, l.next().getType()); 57 assertSame(TokenType.PROPERTY, l.next().getType()); 58 59 Token t = l.next(); 60 61 assertSame(TokenType.SYMBOL, t.getType()); 62 assertEquals("foo", t.getValue()); 63 64 assertSame(TokenType.CPAREN, l.next().getType()); 65 66 assertNull(l.next()); 67 } 68 69 public void testInvalidCharacter() 70 { 71 Lexer l = new Lexer("not[property foo]"); 72 73 assertSame(TokenType.NOT, l.next().getType()); 74 75 try 76 { 77 l.next(); 78 unreachable(); 79 } 80 catch (RuntimeException ex) 81 { 82 assertEquals( 83 "Unexpected character '[' at position 4 of input string 'not[property foo]'.", 84 ex.getMessage()); 85 } 86 } 87 88 public void testSymbolAtEnd() 89 { 90 Lexer l = new Lexer("property foo.bar.Baz"); 91 assertSame(TokenType.PROPERTY, l.next().getType()); 92 93 Token t = l.next(); 94 95 assertSame(TokenType.SYMBOL, t.getType()); 96 assertEquals("foo.bar.Baz", t.getValue()); 97 98 assertNull(l.next()); 99 } 100 } | Popular Tags |