Beispiel #1
0
  protected void scanOnce(String source) {
    _scanner.setSource(source);

    try {
      _scanner.nextToken();
    } catch (Throwable e) {
      fail(e.getMessage());
    }
  }
Beispiel #2
0
  /**
   * 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());
    }
  }
Beispiel #3
0
  /**
   * 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());
      }
    }
  }