Search in sources :

Example 76 with TestExternsBuilder

use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.

the class ClosureIntegrationTest method testDuplicateClosureNamespacesError.

@Test
public void testDuplicateClosureNamespacesError() {
    CompilerOptions options = createCompilerOptions();
    options.setClosurePass(true);
    externs = ImmutableList.<SourceFile>builder().addAll(externs).add(SourceFile.fromCode("closure_externs.js", new TestExternsBuilder().addClosureExterns().build())).build();
    ImmutableList<String> namespaces = ImmutableList.of("goog.provide('a.b.c');", "goog.module('a.b.c');", "goog.declareModuleId('a.b.c'); export {};", "goog.module('a.b.c'); goog.module.declareLegacyNamespace();");
    for (String firstNs : namespaces) {
        for (String secondNs : namespaces) {
            test(options, new String[] { firstNs, secondNs }, DiagnosticGroups.DUPLICATE_NAMESPACES);
        }
    }
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 77 with TestExternsBuilder

use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.

the class ES2022IntegrationTest method publicClassFields_supportedInOptimizationsMode2.

@Test
public void publicClassFields_supportedInOptimizationsMode2() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    test(options, lines("/** @dict */", // 
    "class MyClass {", "  ['f1'] = 2;", "  'f2' = 'hi';", "  2 = 4;", "  ['m1']() { return this['f1']; }", "}", "console.log(new MyClass()['f1']);", "console.log(new MyClass()[2]);", "console.log(new MyClass()['m1']());"), lines(// 
    "class a {", "  f1 = 2;", "  f2= 'hi';", "  2 = 4;", "  m1() { return this.f1; }", "}", "console.log((new a).f1);", "console.log((new a)[2]);", "console.log((new a).m1());"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 78 with TestExternsBuilder

use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.

the class ES2022IntegrationTest method computedPublicClassFields_supportedInChecksOnlyMode.

@Test
public void computedPublicClassFields_supportedInChecksOnlyMode() {
    CompilerOptions options = checksOnlyCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    testNoWarnings(options, lines(// 
    "/** @dict */", "class MyClass {", "  [3 + 4] = 5;", "  [6];", "  'x' = 2;", "}", "console.log(new MyClass()[6]);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 79 with TestExternsBuilder

use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.

the class AstFactoryTest method testCreateArgumentsReference_colors.

@Test
public void testCreateArgumentsReference_colors() {
    Node root = parseAndAddColors(new TestExternsBuilder().addArguments().build(), "function f() { arguments; }");
    AstFactory astFactory = createTestAstFactoryWithColors();
    Node block = NodeUtil.getFunctionBody(root.getFirstFirstChild());
    Node argumentsReferenceNode = block.getFirstFirstChild();
    Color argumentsReferenceColor = argumentsReferenceNode.getColor();
    Node argumentsNode = astFactory.createArgumentsReference();
    assertNode(argumentsNode).matchesName("arguments");
    assertNode(argumentsNode).hasColorThat().isEqualTo(argumentsReferenceColor);
}
Also used : Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Color(com.google.javascript.jscomp.colors.Color) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 80 with TestExternsBuilder

use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.

the class AstFactoryTest method testCreateArgumentsReference_jstypes.

@Test
public void testCreateArgumentsReference_jstypes() {
    // Make sure the compiler's type registry includes the standard externs definition for
    // Arguments.
    parseAndAddTypes(new TestExternsBuilder().addArguments().build(), "");
    AstFactory astFactory = createTestAstFactory();
    Node argumentsNode = astFactory.createArgumentsReference();
    assertNode(argumentsNode).matchesName("arguments");
    assertType(argumentsNode.getJSType()).isEqualTo(getRegistry().getGlobalType("Arguments"));
}
Also used : Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Aggregations

TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)107 Test (org.junit.Test)106 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)58 Node (com.google.javascript.rhino.Node)17 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)17 Compiler (com.google.javascript.jscomp.Compiler)8 SourceFile (com.google.javascript.jscomp.SourceFile)7 Color (com.google.javascript.jscomp.colors.Color)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CodeSubTree (com.google.javascript.jscomp.testing.CodeSubTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 NoninjectingCompiler (com.google.javascript.jscomp.testing.NoninjectingCompiler)1 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)1 SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 File (java.io.File)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1