test/com/google/javascript/rhino/jstype/UnionTypeTest.java
/** Tests subtyping of union types. */
Tests subtyping of union types.
Tests subtyping of union types .
@Test
  public void testSubtypingUnionTypes() {
    assertTrue(BOOLEAN_TYPE.
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE)));
    assertTrue(createUnionType(BOOLEAN_TYPE, STRING_TYPE).
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE)));
    assertTrue(createUnionType(BOOLEAN_TYPE, STRING_TYPE).
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE, NULL_TYPE)));
    assertTrue(createUnionType(BOOLEAN_TYPE, STRING_TYPE).
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE, NULL_TYPE)));
    assertTrue(createUnionType(BOOLEAN_TYPE).
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE, NULL_TYPE)));
    assertTrue(createUnionType(STRING_TYPE).
        isSubtypeOf(createUnionType(BOOLEAN_TYPE, STRING_TYPE, NULL_TYPE)));
    assertTrue(createUnionType(STRING_TYPE, NULL_TYPE).isSubtypeOf(ALL_TYPE));
    assertTrue(createUnionType(DATE_TYPE, REGEXP_TYPE).isSubtypeOf(OBJECT_TYPE));
    assertTrue(createUnionType(sub1, sub2).isSubtypeOf(base));
    assertTrue(createUnionType(sub1, sub2).isSubtypeOf(OBJECT_TYPE));
    assertFalse(createUnionType(STRING_TYPE, NULL_TYPE).isSubtypeOf(NO_TYPE));
    assertFalse(createUnionType(STRING_TYPE, NULL_TYPE).
        isSubtypeOf(NO_OBJECT_TYPE));
    assertFalse(createUnionType(NO_OBJECT_TYPE, NULL_TYPE).
        isSubtypeOf(OBJECT_TYPE));
    assertTrue(NUMBER_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING));
    assertTrue(OBJECT_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING));
    assertTrue(STRING_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING));
    assertTrue(NO_OBJECT_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING));
    assertTrue(NUMBER_TYPE.isSubtypeOf(NUMBER_STRING_BOOLEAN));
    assertTrue(BOOLEAN_TYPE.isSubtypeOf(NUMBER_STRING_BOOLEAN));
    assertTrue(STRING_TYPE.isSubtypeOf(NUMBER_STRING_BOOLEAN));
    assertTrue(NUMBER_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING_BOOLEAN));
    assertTrue(OBJECT_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING_BOOLEAN));
    assertTrue(STRING_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING_BOOLEAN));
    assertTrue(BOOLEAN_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING_BOOLEAN));
    assertTrue(NO_OBJECT_TYPE.isSubtypeOf(OBJECT_NUMBER_STRING_BOOLEAN));
  }
@ Test public void testSubtypingUnionTypes ( ) { assertTrue ( BOOLEAN_TYPE . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE ) ) ) ; assertTrue ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE ) . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE ) ) ) ; assertTrue ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE ) . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE , NULL_TYPE ) ) ) ; assertTrue ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE ) . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE , NULL_TYPE ) ) ) ; assertTrue ( createUnionType ( BOOLEAN_TYPE ) . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE , NULL_TYPE ) ) ) ; assertTrue ( createUnionType ( STRING_TYPE ) . isSubtypeOf ( createUnionType ( BOOLEAN_TYPE , STRING_TYPE , NULL_TYPE ) ) ) ; assertTrue ( createUnionType ( STRING_TYPE , NULL_TYPE ) . isSubtypeOf ( ALL_TYPE ) ) ; assertTrue ( createUnionType ( DATE_TYPE , REGEXP_TYPE ) . isSubtypeOf ( OBJECT_TYPE ) ) ; assertTrue ( createUnionType ( sub1 , sub2 ) . isSubtypeOf ( base ) ) ; assertTrue ( createUnionType ( sub1 , sub2 ) . isSubtypeOf ( OBJECT_TYPE ) ) ; assertFalse ( createUnionType ( STRING_TYPE , NULL_TYPE ) . isSubtypeOf ( NO_TYPE ) ) ; assertFalse ( createUnionType ( STRING_TYPE , NULL_TYPE ) . isSubtypeOf ( NO_OBJECT_TYPE ) ) ; assertFalse ( createUnionType ( NO_OBJECT_TYPE , NULL_TYPE ) . isSubtypeOf ( OBJECT_TYPE ) ) ; assertTrue ( NUMBER_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING ) ) ; assertTrue ( OBJECT_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING ) ) ; assertTrue ( STRING_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING ) ) ; assertTrue ( NO_OBJECT_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING ) ) ; assertTrue ( NUMBER_TYPE . isSubtypeOf ( NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( BOOLEAN_TYPE . isSubtypeOf ( NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( STRING_TYPE . isSubtypeOf ( NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( NUMBER_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( OBJECT_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( STRING_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( BOOLEAN_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING_BOOLEAN ) ) ; assertTrue ( NO_OBJECT_TYPE . isSubtypeOf ( OBJECT_NUMBER_STRING_BOOLEAN ) ) ; }
Tests subtyping of union types.
Tests subtyping of union types .
// subtypes // not subtypes // defined unions