test/com/google/javascript/rhino/jstype/UnionTypeTest.java
/**
   * Tests that special union types can assign to other types. Unions containing the unknown type
   * should be able to assign to any other type.
   */
Tests that special union types can assign to other types. Unions containing the unknown type
should be able to assign to any other type.
Tests that special union types can assign to other types . Unions containing the unknown type should be able to assign to any other type .
@SuppressWarnings("checked")
  @Test
  public void testSpecialUnionCanAssignTo() {
    UnionType numbers = (UnionType) createUnionType(NUMBER_TYPE, NUMBER_OBJECT_TYPE);
    assertFalse(numbers.isSubtype(NUMBER_TYPE));
    assertFalse(numbers.isSubtype(NUMBER_OBJECT_TYPE));
    assertFalse(numbers.isSubtype(sub1));
    UnionType strings = (UnionType) createUnionType(STRING_OBJECT_TYPE, STRING_TYPE);
    assertFalse(strings.isSubtype(STRING_TYPE));
    assertFalse(strings.isSubtype(STRING_OBJECT_TYPE));
    assertFalse(strings.isSubtype(DATE_TYPE));
    UnionType booleans = (UnionType) createUnionType(BOOLEAN_OBJECT_TYPE, BOOLEAN_TYPE);
    assertFalse(booleans.isSubtype(BOOLEAN_TYPE));
    assertFalse(booleans.isSubtype(BOOLEAN_OBJECT_TYPE));
    assertFalse(booleans.isSubtype(REGEXP_TYPE));
    JSType unknown = createUnionType(UNKNOWN_TYPE, DATE_TYPE);
    assertTrue(unknown.isSubtypeOf(STRING_TYPE));
    UnionType stringDate = (UnionType) createUnionType(STRING_OBJECT_TYPE, DATE_TYPE);
    assertTrue(stringDate.isSubtype(OBJECT_TYPE));
    assertFalse(stringDate.isSubtype(STRING_OBJECT_TYPE));
    assertFalse(stringDate.isSubtype(DATE_TYPE));
  }
@ SuppressWarnings ( "checked" ) @ Test public void testSpecialUnionCanAssignTo ( ) { UnionType numbers = ( UnionType ) createUnionType ( NUMBER_TYPE , NUMBER_OBJECT_TYPE ) ; assertFalse ( numbers . isSubtype ( NUMBER_TYPE ) ) ; assertFalse ( numbers . isSubtype ( NUMBER_OBJECT_TYPE ) ) ; assertFalse ( numbers . isSubtype ( sub1 ) ) ; UnionType strings = ( UnionType ) createUnionType ( STRING_OBJECT_TYPE , STRING_TYPE ) ; assertFalse ( strings . isSubtype ( STRING_TYPE ) ) ; assertFalse ( strings . isSubtype ( STRING_OBJECT_TYPE ) ) ; assertFalse ( strings . isSubtype ( DATE_TYPE ) ) ; UnionType booleans = ( UnionType ) createUnionType ( BOOLEAN_OBJECT_TYPE , BOOLEAN_TYPE ) ; assertFalse ( booleans . isSubtype ( BOOLEAN_TYPE ) ) ; assertFalse ( booleans . isSubtype ( BOOLEAN_OBJECT_TYPE ) ) ; assertFalse ( booleans . isSubtype ( REGEXP_TYPE ) ) ; JSType unknown = createUnionType ( UNKNOWN_TYPE , DATE_TYPE ) ; assertTrue ( unknown . isSubtypeOf ( STRING_TYPE ) ) ; UnionType stringDate = ( UnionType ) createUnionType ( STRING_OBJECT_TYPE , DATE_TYPE ) ; assertTrue ( stringDate . isSubtype ( OBJECT_TYPE ) ) ; assertFalse ( stringDate . isSubtype ( STRING_OBJECT_TYPE ) ) ; assertFalse ( stringDate . isSubtype ( DATE_TYPE ) ) ; }
Tests that special union types can assign to other types.
Tests that special union types can assign to other types .
// autoboxing quirks // unknown quirks // all members need to be assignable to