Skip to content

Commit

Permalink
Fixed printing tokens - added two missing cases (#1675)
Browse files Browse the repository at this point in the history
* Fixed printing tokens - added two missing cases

* Added test for validating that _all_ tokens can be printed
  • Loading branch information
andreabergia authored Oct 4, 2024
1 parent 5b9ba19 commit 1477dfe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static enum CommentType {
public static final int
// start enum
ERROR = -1, // well-known as the only code < EOF
FIRST_TOKEN = ERROR,
EOF = ERROR + 1, // end of file token - (not EOF_CHAR)
EOL = EOF + 1, // end of line

Expand Down Expand Up @@ -586,6 +587,8 @@ public static String typeToName(int token) {
return "CONST";
case SETCONST:
return "SETCONST";
case SETCONSTVAR:
return "SETCONSTVAR";
case ARRAYCOMP:
return "ARRAYCOMP";
case WITHEXPR:
Expand All @@ -606,6 +609,12 @@ public static String typeToName(int token) {
return "YIELD_STAR";
case BIGINT:
return "BIGINT";
case GETPROP_OPTIONAL:
return "GETPROP_OPTIONAL";
case REF_SPECIAL_OPTIONAL:
return "REF_SPECIAL_OPTIONAL";
case CALL_OPTIONAL:
return "CALL_OPTIONAL";
case TEMPLATE_LITERAL:
return "TEMPLATE_LITERAL";
case TEMPLATE_CHARS:
Expand All @@ -614,6 +623,8 @@ public static String typeToName(int token) {
return "TEMPLATE_LITERAL_SUBST";
case TAGGED_TEMPLATE_LITERAL:
return "TAGGED_TEMPLATE_LITERAL";
case DOTDOTDOT:
return "DOTDOTDOT";
case QUESTION_DOT:
return "DOT_QUESTION";
}
Expand Down
16 changes: 16 additions & 0 deletions rhino/src/test/java/org/mozilla/javascript/TokenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.mozilla.javascript;

import static org.junit.Assert.assertNotNull;
import static org.mozilla.javascript.Token.FIRST_TOKEN;
import static org.mozilla.javascript.Token.LAST_TOKEN;

import org.junit.Test;

public class TokenTest {
@Test
public void allTokensHaveAName() {
for (int token = FIRST_TOKEN; token < LAST_TOKEN; ++token) {
assertNotNull(Token.typeToName(token));
}
}
}

0 comments on commit 1477dfe

Please sign in to comment.