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());
}
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();
}
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();
}
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();
}
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)"));
}
Aggregations