XPathScanner { public XPathToken nextToken() { mState = mStartState; mStartState = State.START; mOutput = new StringBuilder(); mFinnished = false; mType = TokenType.INVALID; mLastPos = mPos; do { mInput = mQuery.charAt(mPos); switch (mState) { case START: scanStart(); break; case NUMBER: scanNumber(); break; case TEXT: scanText(); break; case SPECIAL2: scanTwoDigitSpecial(); break; case COMMENT: scanComment(); break; case E_NUM: scanENum(); break; default: mPos++; mFinnished = true; } } while (!mFinnished || mPos >= mQuery.length()); if (mCommentCount > 0) { throw new IllegalStateException("Error in Query. Comment does not end."); } return new VariableXPathToken(mOutput.toString(), mType); } XPathScanner(final String paramQuery); XPathToken nextToken(); XPathToken lookUpTokens(final int paramNext); String begin(); int getPos(); @Override String toString();  }
@Test public void testScan() throws IOException { assertEquals(TokenType.SLASH, scanner.nextToken().getType()); assertEquals(TokenType.TEXT, scanner.nextToken().getType()); assertEquals(TokenType.SLASH, scanner.nextToken().getType()); assertEquals(TokenType.TEXT, scanner.nextToken().getType()); assertEquals(TokenType.COLON, scanner.nextToken().getType()); assertEquals(TokenType.TEXT, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.SLASH, scanner.nextToken().getType()); assertEquals(TokenType.VALUE, scanner.nextToken().getType()); assertEquals(TokenType.DESC_STEP, scanner.nextToken().getType()); assertEquals(TokenType.CLOSE_SQP, scanner.nextToken().getType()); assertEquals(TokenType.AT, scanner.nextToken().getType()); assertEquals(TokenType.TEXT, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.EQ, scanner.nextToken().getType()); assertEquals(TokenType.EQ, scanner.nextToken().getType()); assertEquals(TokenType.VALUE, scanner.nextToken().getType()); assertEquals(TokenType.E_NUMBER, scanner.nextToken().getType()); assertEquals(TokenType.PLUS, scanner.nextToken().getType()); assertEquals(TokenType.VALUE, scanner.nextToken().getType()); assertEquals(TokenType.E_NUMBER, scanner.nextToken().getType()); assertEquals(TokenType.OPEN_SQP, scanner.nextToken().getType()); assertEquals(TokenType.TEXT, scanner.nextToken().getType()); assertEquals(TokenType.SPACE, scanner.nextToken().getType()); assertEquals(TokenType.COMP, scanner.nextToken().getType()); assertEquals(TokenType.AT, scanner.nextToken().getType()); assertEquals(TokenType.STAR, scanner.nextToken().getType()); assertEquals(TokenType.INTERROGATION, scanner.nextToken().getType()); assertEquals(TokenType.L_SHIFT, scanner.nextToken().getType()); assertEquals(TokenType.COMP, scanner.nextToken().getType()); assertEquals(TokenType.COMP, scanner.nextToken().getType()); assertEquals(TokenType.COMP, scanner.nextToken().getType()); }
@Test public void testComment() throws IOException { assertEquals(TokenType.OPEN_BR, scanner2.nextToken().getType()); assertEquals(TokenType.SLASH, scanner2.nextToken().getType()); assertEquals(TokenType.TEXT, scanner2.nextToken().getType()); assertEquals(TokenType.COLON, scanner2.nextToken().getType()); assertEquals(TokenType.COLON, scanner2.nextToken().getType()); assertEquals(TokenType.CLOSE_BR, scanner2.nextToken().getType()); assertEquals(TokenType.TEXT, scanner2.nextToken().getType()); assertEquals(TokenType.SLASH, scanner2.nextToken().getType()); assertEquals(TokenType.TEXT, scanner2.nextToken().getType()); assertEquals(TokenType.DESC_STEP, scanner2.nextToken().getType()); assertEquals(TokenType.CLOSE_SQP, scanner2.nextToken().getType()); assertEquals(TokenType.AT, scanner2.nextToken().getType()); assertEquals(TokenType.TEXT, scanner2.nextToken().getType()); assertEquals(TokenType.SPACE, scanner2.nextToken().getType()); assertEquals(TokenType.EQ, scanner2.nextToken().getType()); assertEquals(TokenType.EQ, scanner2.nextToken().getType()); assertEquals(TokenType.VALUE, scanner2.nextToken().getType()); assertEquals(TokenType.OPEN_SQP, scanner2.nextToken().getType()); assertEquals(TokenType.TEXT, scanner2.nextToken().getType()); assertEquals(TokenType.SPACE, scanner2.nextToken().getType()); assertEquals(TokenType.COMP, scanner2.nextToken().getType()); assertEquals(TokenType.STAR, scanner2.nextToken().getType()); }