Search in sources :

Example 36 with TestExternsBuilder

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

the class TypeCheckTest method testDeclareBuiltInConstructor.

@Test
public void testDeclareBuiltInConstructor() {
    // Built-in prototype properties should be accessible
    // even if the built-in constructor is declared.
    Node node = parseAndTypeCheck(new TestExternsBuilder().addString().build(), lines("/** @constructor */ var String = function(opt_str) {};", "(new String(\"x\")).charAt(0)"));
    assertTypeEquals(getNativeStringType(), node.getLastChild().getFirstChild().getJSType());
}
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)

Example 37 with TestExternsBuilder

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

the class TypeCheckTest method testMissingProperty39a.

@Test
public void testMissingProperty39a() {
    disableStrictMissingPropertyChecks();
    this.newTest().addExterns(new TestExternsBuilder().addString().build()).addSource(// 
    "/** @return {string|number} */ function f() { return 3; }", "f().length;").run();
}
Also used : TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 38 with TestExternsBuilder

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

the class TypeCheckTest method testValueOfComparison2.

@Test
public void testValueOfComparison2() {
    compiler.getOptions().setWarningLevel(DiagnosticGroups.STRICT_PRIMITIVE_OPERATORS, CheckLevel.OFF);
    newTest().addExterns(new TestExternsBuilder().addObject().build()).addSource("/** @constructor */function O() {};", "/**@override*/O.prototype.valueOf = function() { return 1; };", "/**", " * @param {!O} a", " * @param {number} b", " */", "function f(a,b) { return a < b; }").run();
}
Also used : TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 39 with TestExternsBuilder

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

the class TypeCheckNoTranspileTest method testAsyncGeneratorDeclaredReturnMustBeSupertypeOfAsyncGenerator.

@Test
public void testAsyncGeneratorDeclaredReturnMustBeSupertypeOfAsyncGenerator() {
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {!AsyncIterator<?>} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {!AsyncIterable<?>} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {!AsyncIteratorIterable<?>} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {!Object} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {*} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {?} */", "async function* asyncGen() {}").run();
    newTest().addExterns(new TestExternsBuilder().addAsyncIterable().build()).addSource(// 
    "/** @return {number} */", "async function* asyncGen() {}").addDiagnostic(lines("An async generator function must return a (supertype of) AsyncGenerator", "found   : number", "required: AsyncGenerator")).run();
}
Also used : TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 40 with TestExternsBuilder

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

the class GuardedCallbackTest method guardedAndUnguardedTest.

@Test
public void guardedAndUnguardedTest() {
    final String externs = new TestExternsBuilder().addConsole().addPromise().build();
    test(externs(externs), srcs("console.log(Promise && Promise.allSettled && Promise.finally);"), // getting passed to `console.log()`, so it is not guarded.
    expected("console.log(GUARDED_NAME && GUARDED_NAME.GUARDED_PROP && GUARDED_NAME.finally)"));
}
Also used : 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