protected void scanOnce(String source) { _scanner.setSource(source); try { _scanner.nextToken(); } catch (Throwable e) { fail(e.getMessage()); } }
/** * assertTokenType * * @param source * @param type * @throws Exception */ protected void assertTokenType(String source, JSTokenType type) { _scanner.setSource(source); try { Symbol token = _scanner.nextToken(); int id = token.getId(); int length = token.getEnd() - token.getStart() + 1; assertEquals("unexpected token type", type.getIndex(), id); assertEquals("token length does not match source length: " + source, source.length(), length); } catch (Throwable e) { fail(e.getMessage()); } }
/** * assertTokenTypes * * @param source * @param types * @throws Exception */ protected void assertTokenTypes(String source, JSTokenType... types) { _scanner.setSource(source); for (int i = 0; i < types.length; i++) { try { JSTokenType type = types[i]; Symbol token = _scanner.nextToken(); int id = token.getId(); assertEquals("in '" + source + "' at token index " + i, type.getIndex(), id); } catch (Throwable e) { fail(e.getMessage()); } } }
@Test public void testMultiLineComment() { scanOnce("/*\n * this is a multi-line comment\n */"); // , JSTokenType.MULTILINE_COMMENT); assertEquals(1, _scanner.getMultiLineComments().size()); }
@Test public void testSingleLineComment() { scanOnce("// this is a singe line comment"); // , JSTokenType.SINGLELINE_COMMENT); assertEquals(1, _scanner.getSingleLineComments().size()); }
@Test public void testSDocComment() { scanOnce("/**\n * this is an sdoc comment\n */"); // , JSTokenType.SDOC); assertEquals(1, _scanner.getSDocComments().size()); }
@Test public void testVSDocComment() { scanOnce("/// this is a vsdoc comment"); // , JSTokenType.VSDOC); assertEquals(1, _scanner.getVSDocComments().size()); }