Skip to content

Sip-23 unit tests #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/junit/scala/reflect/internal/TypesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,45 @@ class TypesTest {
Assert.fail(xs.mkString("\n"))
}
}

@Test
def testSameTypesLub(): Unit = {
def testSameType(tpe: Type, num: Int = 5) = assert(lub(List.fill(num)(tpe)) =:= tpe)

testSameType(IntTpe)
testSameType(StringTpe)
testSameType(typeOf[Class[String]])
testSameType(LiteralType(Constant(1)))
testSameType(LiteralType(Constant("test")))
}

@Test
def testTypesLub(): Unit = {
val interestingCombos: Map[Type, List[List[Type]]] = Map(
IntTpe -> List(List(LiteralType(Constant(0)), LiteralType(Constant(1))),
List(LiteralType(Constant(0)), IntTpe),
List(ConstantType(Constant(0)), IntTpe),
List(ConstantType(Constant(0)), LiteralType(Constant(1))),
List(ConstantType(Constant(1)), LiteralType(Constant(1))), // Should this be LiteralType(Constant(1))?
Copy link
Author

@folone folone Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember not completely understanding why LUB of these two is Int and not LiteralType(Constant(1)) or ConstantType(Constant(1)).


List(LiteralType(Constant(1)), ConstantType(Constant(1))), // Same here
List(LiteralType(Constant(0)), ConstantType(Constant(1)))),
StringTpe -> List(List(LiteralType(Constant("a")), LiteralType(Constant("b"))),
List(LiteralType(Constant("a")), StringTpe),
List(ConstantType(Constant("a")), LiteralType(Constant("a"))), // Should this be LiteralType(Constant("a"))?
List(LiteralType(Constant("a")), ConstantType(Constant("a"))), // Same here
List(ConstantType(Constant("a")), StringTpe),
List(ConstantType(Constant("a")), LiteralType(Constant("b"))),
List(ConstantType(Constant("a")), LiteralType(Constant("b")))),
LiteralType(Constant(1)) -> List(List(LiteralType(Constant(1)), LiteralType(Constant(1)))),
LiteralType(Constant("a")) -> List(List(LiteralType(Constant("a")), LiteralType(Constant("a")))),
AnyValTpe -> List(List(LiteralType(Constant(1)), IntTpe, DoubleTpe)),
typeOf[Class[String]] -> List(List(typeOf[Class[String]], typeOf[Class[String]])),
typeOf[Class[_ >: String <: Object]] -> List(List(typeOf[Class[String]], typeOf[Class[Object]]))
)

interestingCombos foreach { case (result, checks) =>
checks.foreach(check => assert(lub(check) =:= result))
}
}
}