1 61 62 63 64 package org.jaxen.saxpath.base; 65 66 import junit.framework.TestCase; 67 68 public class XPathLexerTokenTest extends TestCase 69 { 70 public XPathLexerTokenTest(String name) 71 { 72 super( name ); 73 } 74 75 public void testIdentifier() 76 { 77 runTest( "identifier", new int[]{ TokenTypes.IDENTIFIER, TokenTypes.EOF } ); 78 } 79 80 public void testNumberInteger() 81 { 82 runTest( "42", new int[]{ TokenTypes.INTEGER, TokenTypes.EOF } ); 83 } 84 85 public void testNumberDouble() 86 { 87 runTest( "42.42", new int[]{ TokenTypes.DOUBLE, TokenTypes.EOF } ); 88 } 89 90 public void testComma() 91 { 92 runTest( ",", new int[]{ TokenTypes.COMMA, TokenTypes.EOF } ); 93 } 94 95 public void testEquals() 96 { 97 runTest( "=", new int[]{ TokenTypes.EQUALS, TokenTypes.EOF } ); 98 } 99 100 public void testMinus() 101 { 102 runTest( "-", new int[]{ TokenTypes.MINUS, TokenTypes.EOF } ); 103 } 104 105 public void testPlus() 106 { 107 runTest( "+", new int[]{ TokenTypes.PLUS, TokenTypes.EOF } ); 108 } 109 110 public void testDollar() 111 { 112 runTest( "$", new int[]{ TokenTypes.DOLLAR, TokenTypes.EOF } ); 113 } 114 115 public void testPipe() 116 { 117 runTest( "|", new int[]{ TokenTypes.PIPE, TokenTypes.EOF } ); 118 } 119 120 public void testAt() 121 { 122 runTest( "@", new int[]{ TokenTypes.AT, TokenTypes.EOF } ); 123 } 124 125 public void testColon() 126 { 127 runTest( ":", new int[]{ TokenTypes.COLON, TokenTypes.EOF } ); 128 } 129 130 public void testDoubleColon() 131 { 132 runTest( "::", new int[]{ TokenTypes.DOUBLE_COLON, TokenTypes.EOF } ); 133 } 134 135 public void testNot() 136 { 137 runTest( "!", new int[]{ TokenTypes.NOT, TokenTypes.EOF } ); 138 } 139 140 public void testNotEquals() 141 { 142 runTest( "!=", new int[]{ TokenTypes.NOT_EQUALS, TokenTypes.EOF } ); 143 } 144 145 public void testStar() 146 { 147 runTest( "*", new int[]{ TokenTypes.STAR, TokenTypes.EOF } ); 148 } 149 150 public void testLiteralSingleQuote() 151 { 152 runTest( "'literal'", new int[]{ TokenTypes.LITERAL, TokenTypes.EOF } ); 153 } 154 155 public void testLiteralDoubleQuote() 156 { 157 runTest( "\"literal\"", new int[]{ TokenTypes.LITERAL, TokenTypes.EOF } ); 158 } 159 160 public void testSingleDot() 161 { 162 runTest( ".", new int[]{ TokenTypes.DOT, TokenTypes.EOF } ); 163 } 164 165 public void testDoubleDot() 166 { 167 runTest( "..", new int[]{ TokenTypes.DOT_DOT, TokenTypes.EOF }); 168 } 169 170 public void testLeftBracket() 171 { 172 runTest( "[", new int[]{ TokenTypes.LEFT_BRACKET, TokenTypes.EOF } ); 173 } 174 175 public void testRightBracket() 176 { 177 runTest( "]", new int[]{ TokenTypes.RIGHT_BRACKET, TokenTypes.EOF } ); 178 } 179 180 public void testLeftParen() 181 { 182 runTest( "(", new int[]{ TokenTypes.LEFT_PAREN, TokenTypes.EOF } ); 183 } 184 185 public void testSingleSlash() 186 { 187 runTest( "/", new int[]{ TokenTypes.SLASH, TokenTypes.EOF } ); 188 } 189 190 public void testDoubleSlash() 191 { 192 runTest( "//", new int[]{ TokenTypes.DOUBLE_SLASH, TokenTypes.EOF } ); 193 } 194 195 public void testLessThan() 196 { 197 runTest( "<", new int[]{ TokenTypes.LESS_THAN_SIGN, TokenTypes.EOF } ); 198 } 199 200 public void testLessThanEquals() 201 { 202 runTest( "<=", new int[]{ TokenTypes.LESS_THAN_OR_EQUALS_SIGN, TokenTypes.EOF } ); 203 } 204 205 public void testGreaterThan() 206 { 207 runTest( ">", new int[]{ TokenTypes.GREATER_THAN_SIGN, TokenTypes.EOF } ); 208 } 209 210 public void testGreaterThanEquals() 211 { 212 runTest( ">=", new int[]{ TokenTypes.GREATER_THAN_OR_EQUALS_SIGN, TokenTypes.EOF } ); 213 } 214 215 public void testOperatorAnd() 216 { 217 runTest( "identifier and", new int[]{ TokenTypes.IDENTIFIER, TokenTypes.AND, TokenTypes.EOF } ); 218 } 219 220 public void testOperatorOr() 221 { 222 runTest( "identifier or", new int[]{ TokenTypes.IDENTIFIER, TokenTypes.OR, TokenTypes.EOF } ); 223 } 224 225 public void testOperatorMod() 226 { 227 runTest( "identifier mod", new int[]{ TokenTypes.IDENTIFIER, TokenTypes.MOD, TokenTypes.EOF } ); 228 } 229 230 public void testOperatorDiv() 231 { 232 runTest( "identifier div", new int[]{ TokenTypes.IDENTIFIER, TokenTypes.DIV } ); 233 } 234 235 public void testWhitespace() 236 { 237 runTest( " \t \t \t", new int[]{ TokenTypes.EOF } ); 238 } 239 240 private void runTest(String text, 241 int[] expectedTokens) 242 { 243 XPathLexer lexer = new XPathLexer( text ); 244 245 int tokenType = 0; 246 Token token = null; 247 248 for ( int i = 0 ; i < expectedTokens.length ; ++i ) 249 { 250 tokenType = expectedTokens[i]; 251 token = lexer.nextToken(); 252 assertNotNull( token ); 253 assertEquals( tokenType, 254 token.getTokenType() ); 255 } 256 } 257 258 } 259 | Popular Tags |