Skip to content

Commit

Permalink
🧪 test: Add test for ident
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 14, 2024
1 parent 2ad894b commit b244aad
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024. caoccao.com Sam Cao
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.caoccao.javet.swc4j.ast.expr;

import com.caoccao.javet.swc4j.ast.BaseTestSuiteSwc4jAst;
import com.caoccao.javet.swc4j.ast.enums.Swc4jAstType;
import com.caoccao.javet.swc4j.ast.program.Swc4jAstScript;
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstExprStmt;
import com.caoccao.javet.swc4j.outputs.Swc4jParseOutput;
import com.caoccao.javet.swc4j.utils.SimpleList;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class TestSwc4jAstIdent extends BaseTestSuiteSwc4jAst {
@Test
public void testValidNonOptional() {
SimpleList.of("a", "x0", "_a", "$abc").forEach(code -> {
Swc4jParseOutput output = null;
try {
output = swc4j.parse(code, jsScriptParseOptions);
} catch (Throwable t) {
fail(t);
}
Swc4jAstScript script = output.getProgram().as(Swc4jAstScript.class);
Swc4jAstExprStmt exprStmt = assertAst(
script, script.getBody().get(0).as(Swc4jAstExprStmt.class), Swc4jAstType.ExprStmt, 0, code.length());
Swc4jAstIdent ident = assertAst(
exprStmt, exprStmt.getExpr().as(Swc4jAstIdent.class), Swc4jAstType.Ident, 0, code.length());
assertEquals(code, ident.getSym());
assertFalse(ident.isOptional());
assertSpan(code, script);
});
}
}

0 comments on commit b244aad

Please sign in to comment.