@@ -58,4 +58,45 @@ class TypesTest {
58
58
Assert .fail(xs.mkString(" \n " ))
59
59
}
60
60
}
61
+
62
+ @ Test
63
+ def testSameTypesLub (): Unit = {
64
+ def testSameType (tpe : Type , num : Int = 5 ) = assert(lub(List .fill(num)(tpe)) =:= tpe)
65
+
66
+ testSameType(IntTpe )
67
+ testSameType(StringTpe )
68
+ testSameType(typeOf[Class [String ]])
69
+ testSameType(LiteralType (Constant (1 )))
70
+ testSameType(LiteralType (Constant (" test" )))
71
+ }
72
+
73
+ @ Test
74
+ def testTypesLub (): Unit = {
75
+ val interestingCombos : Map [Type , List [List [Type ]]] = Map (
76
+ IntTpe -> List (List (LiteralType (Constant (0 )), LiteralType (Constant (1 ))),
77
+ List (LiteralType (Constant (0 )), IntTpe ),
78
+ List (ConstantType (Constant (0 )), IntTpe ),
79
+ List (ConstantType (Constant (0 )), LiteralType (Constant (1 ))),
80
+ List (ConstantType (Constant (1 )), LiteralType (Constant (1 ))), // Should this be LiteralType(Constant(1))?
81
+
82
+ List (LiteralType (Constant (1 )), ConstantType (Constant (1 ))), // Same here
83
+ List (LiteralType (Constant (0 )), ConstantType (Constant (1 )))),
84
+ StringTpe -> List (List (LiteralType (Constant (" a" )), LiteralType (Constant (" b" ))),
85
+ List (LiteralType (Constant (" a" )), StringTpe ),
86
+ List (ConstantType (Constant (" a" )), LiteralType (Constant (" a" ))), // Should this be LiteralType(Constant("a"))?
87
+ List (LiteralType (Constant (" a" )), ConstantType (Constant (" a" ))), // Same here
88
+ List (ConstantType (Constant (" a" )), StringTpe ),
89
+ List (ConstantType (Constant (" a" )), LiteralType (Constant (" b" ))),
90
+ List (ConstantType (Constant (" a" )), LiteralType (Constant (" b" )))),
91
+ LiteralType (Constant (1 )) -> List (List (LiteralType (Constant (1 )), LiteralType (Constant (1 )))),
92
+ LiteralType (Constant (" a" )) -> List (List (LiteralType (Constant (" a" )), LiteralType (Constant (" a" )))),
93
+ AnyValTpe -> List (List (LiteralType (Constant (1 )), IntTpe , DoubleTpe )),
94
+ typeOf[Class [String ]] -> List (List (typeOf[Class [String ]], typeOf[Class [String ]])),
95
+ typeOf[Class [_ >: String <: Object ]] -> List (List (typeOf[Class [String ]], typeOf[Class [Object ]]))
96
+ )
97
+
98
+ interestingCombos foreach { case (result, checks) =>
99
+ checks.foreach(check => assert(lub(check) =:= result))
100
+ }
101
+ }
61
102
}
0 commit comments