use of com.redhat.ceylon.model.typechecker.model.IntersectionType in project ceylon-compiler by ceylon.
the class TypeParserTests method testIntersectionAndUnion.
@Test
public void testIntersectionAndUnion() {
Type type = new TypeParser(MockLoader.instance).decodeType("a&b|c", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof UnionType);
UnionType union = (UnionType) declaration;
List<Type> unionTypes = union.getCaseTypes();
Assert.assertEquals(2, unionTypes.size());
Assert.assertTrue(unionTypes.get(0).getDeclaration() instanceof IntersectionType);
IntersectionType intersection = (IntersectionType) unionTypes.get(0).getDeclaration();
List<Type> intersectionTypes = intersection.getSatisfiedTypes();
Assert.assertEquals(2, intersectionTypes.size());
Assert.assertEquals("a", intersectionTypes.get(0).getDeclaration().getName());
Assert.assertTrue(intersectionTypes.get(0).getDeclaration() instanceof Class);
Assert.assertEquals("b", intersectionTypes.get(1).getDeclaration().getName());
Assert.assertTrue(intersectionTypes.get(1).getDeclaration() instanceof Class);
Assert.assertEquals("c", unionTypes.get(1).getDeclaration().getName());
Assert.assertTrue(unionTypes.get(1).getDeclaration() instanceof Class);
}
use of com.redhat.ceylon.model.typechecker.model.IntersectionType in project ceylon-compiler by ceylon.
the class TypeParserTests method testIntersection.
@Test
public void testIntersection() {
Type type = new TypeParser(MockLoader.instance).decodeType("a&b&c", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof IntersectionType);
IntersectionType intersection = (IntersectionType) declaration;
List<Type> types = intersection.getSatisfiedTypes();
Assert.assertEquals(3, types.size());
Assert.assertEquals("a", types.get(0).getDeclaration().getName());
Assert.assertTrue(types.get(0).getDeclaration() instanceof Class);
Assert.assertEquals("b", types.get(1).getDeclaration().getName());
Assert.assertTrue(types.get(1).getDeclaration() instanceof Class);
Assert.assertEquals("c", types.get(2).getDeclaration().getName());
Assert.assertTrue(types.get(2).getDeclaration() instanceof Class);
}
use of com.redhat.ceylon.model.typechecker.model.IntersectionType in project ceylon-compiler by ceylon.
the class TypeParserTests method testComplexQualified.
@Test
public void testComplexQualified() {
Type type = new TypeParser(MockLoader.instance).decodeType("<pkg::u&pkg::v>.w", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Class);
Assert.assertEquals("pkg::v.w", declaration.getQualifiedNameString());
Type qualifyingType = type.getQualifyingType();
Assert.assertNotNull(qualifyingType);
TypeDeclaration qualifyingDeclaration = qualifyingType.getDeclaration();
Assert.assertNotNull(qualifyingDeclaration);
Assert.assertTrue(qualifyingDeclaration instanceof IntersectionType);
Assert.assertEquals("u&v", qualifyingDeclaration.getName());
}
use of com.redhat.ceylon.model.typechecker.model.IntersectionType in project ceylon-compiler by ceylon.
the class TypeParserTests method testOptionalAbbrev.
@Test
public void testOptionalAbbrev() {
Type type = new TypeParser(MockLoader.instance).decodeType("a?", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof UnionType);
Assert.assertEquals("ceylon.language::Null|a", printType(type));
Assert.assertNull(type.getQualifyingType());
type = new TypeParser(MockLoader.instance).decodeType("pkg::u&pkg::v?", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof IntersectionType);
Assert.assertEquals("pkg::u&<ceylon.language::Null|pkg::v>", printType(type));
Assert.assertNull(type.getQualifyingType());
type = new TypeParser(MockLoader.instance).decodeType("pkg::u|pkg::v[]?", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof UnionType);
Assert.assertEquals("pkg::u|ceylon.language::Null|ceylon.language::Sequential<pkg::v>", printType(type));
Assert.assertNull(type.getQualifyingType());
}
Aggregations