Skip to content

Commit

Permalink
Added test for validating that _all_ tokens can be printed
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabergia committed Oct 4, 2024
1 parent b39ac0c commit bbbc557
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 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 @@ -608,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 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 bbbc557

Please sign in to comment.