Skip to content

Commit

Permalink
🦄 refactor: Revise test for regex
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 12, 2024
1 parent fc617b0 commit 2ad894b
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@ public class TestSwc4jAstRegex extends BaseTestSuiteSwc4jAst {
@Test
public void testExpAndFlags() throws Swc4jCoreException {
String code = "/abc/ig";
Swc4jParseOutput output = swc4j.parse(code, tsScriptParseOptions);
Swc4jParseOutput output = swc4j.parse(code, jsScriptParseOptions);
Swc4jAstScript script = output.getProgram().as(Swc4jAstScript.class);
Swc4jAstExprStmt exprStmt = assertAst(
script, script.getBody().get(0).as(Swc4jAstExprStmt.class), Swc4jAstType.ExprStmt, 0, 7);
Swc4jAstRegex regex = assertAst(
exprStmt, exprStmt.getExpr().as(Swc4jAstRegex.class), Swc4jAstType.Regex, 0, 7);
assertEquals("abc", regex.getExp());
assertEquals("ig", regex.getFlags());
assertEquals(code, regex.toString());
assertSpan(code, script);
}

@Test
public void testExpOnly() throws Swc4jCoreException {
String code = "/abc/";
Swc4jParseOutput output = swc4j.parse(code, tsScriptParseOptions);
Swc4jParseOutput output = swc4j.parse(code, jsScriptParseOptions);
Swc4jAstScript script = output.getProgram().as(Swc4jAstScript.class);
Swc4jAstExprStmt exprStmt = assertAst(
script, script.getBody().get(0).as(Swc4jAstExprStmt.class), Swc4jAstType.ExprStmt, 0, 5);
Swc4jAstRegex regex = assertAst(
exprStmt, exprStmt.getExpr().as(Swc4jAstRegex.class), Swc4jAstType.Regex, 0, 5);
assertEquals("abc", regex.getExp());
assertEquals("", regex.getFlags());
assertEquals(code, regex.toString());
assertSpan(code, script);
}
}

0 comments on commit 2ad894b

Please sign in to comment.