本文整理汇总了Java中com.google.javascript.rhino.testing.Asserts类的典型用法代码示例。如果您正苦于以下问题:Java Asserts类的具体用法?Java Asserts怎么用?Java Asserts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Asserts类属于com.google.javascript.rhino.testing包,在下文中一共展示了Asserts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGoogBar
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the goog.Bar type.
*/
public void testGoogBar() throws Exception {
assertTrue(namedGoogBar.isInstanceType());
assertFalse(googBar.isInstanceType());
assertFalse(namedGoogBar.isConstructor());
assertTrue(googBar.isConstructor());
assertTrue(googBar.getInstanceType().isInstanceType());
assertTrue(namedGoogBar.getConstructor().isConstructor());
assertTrue(namedGoogBar.getImplicitPrototype().isFunctionPrototypeType());
// canAssignTo
assertTypeCanAssignToItself(googBar);
assertTypeCanAssignToItself(namedGoogBar);
googBar.canAssignTo(namedGoogBar);
namedGoogBar.canAssignTo(googBar);
assertTrue(googBar.equals(googBar));
assertFalse(googBar.equals(googSubBar));
Asserts.assertResolvesToSame(googBar);
Asserts.assertResolvesToSame(googSubBar);
}
示例2: testGoogBar
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the goog.Bar type.
*/
public void testGoogBar() throws Exception {
assertTrue(namedGoogBar.isInstanceType());
assertFalse(googBar.isInstanceType());
assertFalse(namedGoogBar.isConstructor());
assertTrue(googBar.isConstructor());
assertTrue(googBar.getInstanceType().isInstanceType());
assertTrue(namedGoogBar.getConstructor().isConstructor());
assertTrue(namedGoogBar.getImplicitPrototype().isFunctionPrototypeType());
// canAssignTo
assertTypeCanAssignToItself(googBar);
assertTypeCanAssignToItself(namedGoogBar);
googBar.canAssignTo(namedGoogBar);
namedGoogBar.canAssignTo(googBar);
assertTrue(googBar.isEquivalentTo(googBar));
assertFalse(googBar.isEquivalentTo(googSubBar));
Asserts.assertResolvesToSame(googBar);
Asserts.assertResolvesToSame(googSubBar);
}
示例3: testCheckedUnknownType
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the behavior of the checked unknown type.
*/
public void testCheckedUnknownType() throws Exception {
// isPropertyType*
assertPropertyTypeUnknown(CHECKED_UNKNOWN_TYPE, "XXX");
// toString
assertEquals("??", CHECKED_UNKNOWN_TYPE.toString());
assertTrue(CHECKED_UNKNOWN_TYPE.hasDisplayName());
assertEquals("Unknown", CHECKED_UNKNOWN_TYPE.getDisplayName());
Asserts.assertResolvesToSame(CHECKED_UNKNOWN_TYPE);
assertFalse(CHECKED_UNKNOWN_TYPE.isNominalConstructor());
assertEquals(CHECKED_UNKNOWN_TYPE,
CHECKED_UNKNOWN_TYPE.getPropertyType("abc"));
}
示例4: testGoogBar
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the goog.Bar type.
*/
public void testGoogBar() throws Exception {
assertTrue(namedGoogBar.isInstanceType());
assertFalse(googBar.isInstanceType());
assertFalse(namedGoogBar.isConstructor());
assertTrue(googBar.isConstructor());
assertTrue(googBar.getInstanceType().isInstanceType());
assertTrue(namedGoogBar.getConstructor().isConstructor());
assertTrue(namedGoogBar.getImplicitPrototype().isFunctionPrototypeType());
// isSubtype
assertTypeCanAssignToItself(googBar);
assertTypeCanAssignToItself(namedGoogBar);
googBar.isSubtype(namedGoogBar);
namedGoogBar.isSubtype(googBar);
assertTypeEquals(googBar, googBar);
assertTypeNotEquals(googBar, googSubBar);
Asserts.assertResolvesToSame(googBar);
Asserts.assertResolvesToSame(googSubBar);
}
示例5: testRecursiveRecord
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testRecursiveRecord() {
ProxyObjectType loop = new ProxyObjectType(registry, NUMBER_TYPE);
JSType record = new RecordTypeBuilder(registry)
.addProperty("loop", loop, null)
.addProperty("number", NUMBER_TYPE, null)
.addProperty("string", STRING_TYPE, null)
.build();
assertEquals("{loop: number, number: number, string: string}",
record.toString());
loop.setReferencedType(record);
assertEquals("{loop: {...}, number: number, string: string}",
record.toString());
assertEquals("{loop: ?, number: number, string: string}",
record.toAnnotationString());
Asserts.assertEquivalenceOperations(record, loop);
}
示例6: testIsEquivalentToParams
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testIsEquivalentToParams() {
FunctionType oneNum = new FunctionBuilder(registry)
.withParamsNode(registry.createParameters(NUMBER_TYPE))
.build();
FunctionType optNum = new FunctionBuilder(registry)
.withParamsNode(registry.createOptionalParameters(NUMBER_TYPE))
.build();
FunctionType varNum = new FunctionBuilder(registry)
.withParamsNode(registry.createParametersWithVarArgs(NUMBER_TYPE))
.build();
Asserts.assertEquivalenceOperations(oneNum, oneNum);
Asserts.assertEquivalenceOperations(optNum, optNum);
Asserts.assertEquivalenceOperations(varNum, varNum);
assertFalse(oneNum.isEquivalentTo(optNum));
assertFalse(oneNum.isEquivalentTo(varNum));
assertFalse(optNum.isEquivalentTo(varNum));
}
示例7: testNamespacedFunctionStubLocal
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testNamespacedFunctionStubLocal() {
testSame(
"(function() {" +
"var goog = {};" +
"/** @param {number} x */ goog.foo;" +
"});");
ObjectType goog = (ObjectType) findNameType("goog", lastLocalScope);
assertTrue(goog.hasProperty("foo"));
assertEquals("function (number): ?",
goog.getPropertyType("foo").toString());
assertTrue(goog.isPropertyTypeDeclared("foo"));
Asserts.assertTypeEquals(lastLocalScope.getVar("goog.foo").getType(),
goog.getPropertyType("foo"));
}
示例8: testPropertiesOnInterface
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testPropertiesOnInterface() throws Exception {
testSame("/** @interface */ var I = function() {};" +
"/** @type {number} */ I.prototype.bar;" +
"I.prototype.baz = function(){};");
Var i = globalScope.getVar("I");
assertEquals("function (this:I): ?", i.getType().toString());
assertTrue(i.getType().isInterface());
ObjectType iPrototype = (ObjectType)
((ObjectType) i.getType()).getPropertyType("prototype");
assertEquals("I.prototype", iPrototype.toString());
assertTrue(iPrototype.isFunctionPrototypeType());
assertEquals("number", iPrototype.getPropertyType("bar").toString());
assertEquals("function (this:I): undefined",
iPrototype.getPropertyType("baz").toString());
Asserts.assertTypeEquals(iPrototype, globalScope.getVar("I.prototype").getType());
}
示例9: testRecursiveRecord
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testRecursiveRecord() {
ProxyObjectType loop = new ProxyObjectType(registry, NUMBER_TYPE);
JSType record = new RecordTypeBuilder(registry)
.addProperty("loop", loop, null)
.addProperty("number", NUMBER_TYPE, null)
.addProperty("string", STRING_TYPE, null)
.build();
assertEquals("{\n loop: number,\n number: number,\n string: string\n}",
record.toString());
loop.setReferencedType(record);
assertEquals("{\n loop: {...},\n number: number,\n string: string\n}",
record.toString());
assertEquals("{loop: ?, number: number, string: string}",
record.toAnnotationString(Nullability.EXPLICIT));
Asserts.assertEquivalenceOperations(record, loop);
}
示例10: testNamespacedFunctionStubLocal
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testNamespacedFunctionStubLocal() {
testSame(
"(function() {" +
"var goog = {};" +
"/** @param {number} x */ goog.foo;" +
"});");
ObjectType goog = (ObjectType) findNameType("goog", lastLocalScope);
assertTrue(goog.hasProperty("foo"));
assertEquals("function(number): ?",
goog.getPropertyType("foo").toString());
assertTrue(goog.isPropertyTypeDeclared("foo"));
Asserts.assertTypeEquals(lastLocalScope.getVar("goog.foo").getType(),
goog.getPropertyType("foo"));
}
示例11: testPropertiesOnInterface
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testPropertiesOnInterface() throws Exception {
testSame("/** @interface */ var I = function() {};" +
"/** @type {number} */ I.prototype.bar;" +
"I.prototype.baz = function(){};");
TypedVar i = globalScope.getVar("I");
assertEquals("function(this:I): ?", i.getType().toString());
assertTrue(i.getType().isInterface());
ObjectType iPrototype = (ObjectType)
((ObjectType) i.getType()).getPropertyType("prototype");
assertEquals("I.prototype", iPrototype.toString());
assertTrue(iPrototype.isFunctionPrototypeType());
assertEquals("number", iPrototype.getPropertyType("bar").toString());
assertEquals("function(this:I): undefined",
iPrototype.getPropertyType("baz").toString());
Asserts.assertTypeEquals(iPrototype, globalScope.getVar("I.prototype").getType());
}
示例12: testStringEnumType
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testStringEnumType() throws Exception {
EnumElementType stringEnum =
new EnumType(registry, "Enum", STRING_TYPE).getElementsType();
assertEquals(UNKNOWN_TYPE, stringEnum.getPropertyType("length"));
assertEquals(NUMBER_TYPE, stringEnum.findPropertyType("length"));
assertEquals(false, stringEnum.hasProperty("length"));
assertEquals(STRING_OBJECT_TYPE, stringEnum.autoboxesTo());
assertNull(stringEnum.getConstructor());
Asserts.assertResolvesToSame(stringEnum);
}
示例13: testNamedGoogBar
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the named type goog.Bar.
*/
public void testNamedGoogBar() throws Exception {
// isXxx
assertFalse(namedGoogBar.isFunctionPrototypeType());
assertTrue(namedGoogBar.getImplicitPrototype().isFunctionPrototypeType());
// canAssignTo
assertTrue(namedGoogBar.canAssignTo(ALL_TYPE));
assertFalse(namedGoogBar.canAssignTo(STRING_OBJECT_TYPE));
assertFalse(namedGoogBar.canAssignTo(NUMBER_TYPE));
assertFalse(namedGoogBar.canAssignTo(functionType));
assertFalse(namedGoogBar.canAssignTo(NULL_TYPE));
assertTrue(namedGoogBar.canAssignTo(OBJECT_TYPE));
assertFalse(namedGoogBar.canAssignTo(DATE_TYPE));
assertTrue(namedGoogBar.canAssignTo(namedGoogBar));
assertTrue(namedGoogBar.canAssignTo(unresolvedNamedType));
assertFalse(namedGoogBar.canAssignTo(REGEXP_TYPE));
assertFalse(namedGoogBar.canAssignTo(ARRAY_TYPE));
// autoboxesTo
assertNull(namedGoogBar.autoboxesTo());
// properties
assertEquals(DATE_TYPE, namedGoogBar.getPropertyType("date"));
assertFalse(namedGoogBar.isNativeObjectType());
assertFalse(namedGoogBar.getImplicitPrototype().isNativeObjectType());
JSType resolvedNamedGoogBar = Asserts.assertValidResolve(namedGoogBar);
assertNotSame(resolvedNamedGoogBar, namedGoogBar);
assertSame(resolvedNamedGoogBar, googBar.getInstanceType());
}
示例14: testNamedTypeEquals2
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
/**
* Tests the {@link NamedType#equals} function against other types.
*/
public void testNamedTypeEquals2() {
// test == if references are equal
NamedType a = new NamedType(registry, "typeA", "source", 1, 0);
NamedType b = new NamedType(registry, "typeB", "source", 1, 0);
ObjectType realA = registry.createConstructorType(
"typeA", null, null, null).getInstanceType();
ObjectType realB = registry.createEnumType(
"typeB", NUMBER_TYPE).getElementsType();
registry.declareType("typeA", realA);
registry.declareType("typeB", realB);
assertEquals(a.hashCode(), realA.hashCode());
assertEquals(a, realA);
assertEquals(b.hashCode(), realB.hashCode());
assertEquals(b, realB);
a.resolve(null, null);
b.resolve(null, null);
assertTrue(a.isResolved());
assertTrue(b.isResolved());
assertEquals(a.hashCode(), realA.hashCode());
assertEquals(a, realA);
assertEquals(b.hashCode(), realB.hashCode());
assertEquals(b, realB);
JSType resolvedA = Asserts.assertValidResolve(a);
assertNotSame(resolvedA, a);
assertSame(resolvedA, realA);
JSType resolvedB = Asserts.assertValidResolve(b);
assertNotSame(resolvedB, b);
assertSame(resolvedB, realB);
}
示例15: testStringEnumType
import com.google.javascript.rhino.testing.Asserts; //导入依赖的package包/类
public void testStringEnumType() throws Exception {
EnumElementType stringEnum =
new EnumType(registry, "Enum", STRING_TYPE).getElementsType();
assertTypeEquals(UNKNOWN_TYPE, stringEnum.getPropertyType("length"));
assertTypeEquals(NUMBER_TYPE, stringEnum.findPropertyType("length"));
assertEquals(false, stringEnum.hasProperty("length"));
assertTypeEquals(STRING_OBJECT_TYPE, stringEnum.autoboxesTo());
assertNull(stringEnum.getConstructor());
Asserts.assertResolvesToSame(stringEnum);
}