22// Literals
33// ############################################################################
44
5- // ############################################################################
5+ import scala . util .{ Failure , Success , Try }
66
77object Test {
88
9- /* I add a couple of Unicode identifier tests here temporarily */
9+ /* I add a couple of Unicode identifier tests here " temporarily" */
1010
1111 def \ u03b1\ u03c1\ u03b5\ u03c4\ u03b7 = " alpha rho epsilon tau eta"
1212
1313 case class GGG (i : Int ) {
1414 def \ u03b1\ u03b1(that : GGG ) = i + that.i
1515 }
1616
17- def check_success [a](name : String , closure : => a, expected : a): Unit = {
18- print(" test " + name)
19- try {
20- val actual : a = closure
21- if (actual == expected) {
22- print(" was successful" );
23- } else {
24- print(" failed: expected " + expected + " , found " + actual);
25- }
26- } catch {
27- case exception : Throwable => {
28- print(" raised exception " + exception);
29- }
17+ def check_success [A ](name : String , closure : => A , expected : A ): Unit =
18+ Try (closure) match {
19+ case Success (actual) => assert(actual == expected, s " test $name failed: expected $expected, found $actual" )
20+ case Failure (error) => throw new AssertionError (s " test $name raised exception $error" )
3021 }
31- println
32- }
3322
3423 def main (args : Array [String ]): Unit = {
3524 // char
@@ -39,13 +28,9 @@ object Test {
3928 check_success(" \"\\ 141\\ 142\" == \" ab\" " , " \141\142 " , " ab" )
4029 check_success(" \"\\ 0x61\\ 0x62\" .trim() == \" x61\\ 0x62\" " , " \0 x61\0 x62" .substring(1 ), " x61\0 x62" )
4130
42- println
43-
4431 // boolean
4532 check_success(" (65 : Byte) == 'A'" , (65 : Byte ) == 'A' , true ) // contrib #176
4633
47- println
48-
4934 // int
5035 check_success(" 0X01 == 1" , 0X01 , 1 )
5136 check_success(" 0x01 == 1" , 0x01 , 1 )
@@ -67,12 +52,10 @@ object Test {
6752 check_success(" 0x80000000 == -2147483648" , 0x80000000 , - 2147483648 )
6853 check_success(" 0xffffffff == -1" , 0xffffffff , - 1 )
6954
70- println
71-
7255 // long
7356 check_success(" 1l == 1L" , 1l , 1L )
7457 check_success(" 1L == 1l" , 1L , 1l )
75- check_success(" 1.asInstanceOf[Long] == 1l " , 1 .asInstanceOf [Long ], 1l )
58+ check_success(" 1.asInstanceOf[Long] == 1L " , 1 .asInstanceOf [Long ], 1L )
7659
7760 check_success(" 0x7fffffffffffffffL == 9223372036854775807L" ,
7861 0x7fffffffffffffffL, 9223372036854775807L )
@@ -81,37 +64,48 @@ object Test {
8164 check_success(" 0xffffffffffffffffL == -1L" ,
8265 0xffffffffffffffffL, - 1L )
8366
84- println
85-
8667 // see JLS at address:
8768 // http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#230798
8869
8970 // float
9071 check_success(" 1e1f == 10.0f" , 1e1f , 10.0f )
9172 check_success(" .3f == 0.3f" , .3f , 0.3f )
9273 check_success(" 0f == 0.0f" , 0f , 0.0f )
74+ check_success(" 0f == -0.000000000000000000e+00f" , 0f , - 0.000000000000000000e+00f )
75+ check_success(" 0f == -0.000000000000000000e+00F" , 0f , - 0.000000000000000000e+00F )
76+ check_success(" 0f == -0.0000000000000000e14f" , 0f , - 0.0000000000000000e14f )
77+ check_success(" 01.23f == 1.23f" , 01.23f , 1.23f )
9378 check_success(" 3.14f == 3.14f" , 3.14f , 3.14f )
9479 check_success(" 6.022e23f == 6.022e23f" , 6.022e23f , 6.022e23f )
95- check_success(" 09f == 9.0f" , 9f , 9.0f )
80+ check_success(" 9f == 9.0f" , 9f , 9.0f )
81+ check_success(" 09f == 9.0f" , 09f , 9.0f )
82+ check_success(" 1.00000017881393421514957253748434595763683319091796875001f == 1.0000001f" ,
83+ 1.00000017881393421514957253748434595763683319091796875001f ,
84+ 1.0000001f )
85+ check_success(" 3.4028235E38f == Float.MaxValue" , 3.4028235E38f , Float .MaxValue )
9686 check_success(" 1.asInstanceOf[Float] == 1.0" , 1 .asInstanceOf [Float ], 1.0f )
97- check_success(" 1l.asInstanceOf[Float] == 1.0" , 1l .asInstanceOf [Float ], 1.0f )
98-
99- println
87+ check_success(" 1L.asInstanceOf[Float] == 1.0" , 1L .asInstanceOf [Float ], 1.0f )
10088
10189 // double
10290 check_success(" 1e1 == 10.0" , 1e1 , 10.0 )
10391 check_success(" .3 == 0.3" , .3 , 0.3 )
10492 check_success(" 0.0 == 0.0" , 0.0 , 0.0 )
10593 check_success(" 0d == 0.0" , 0d , 0.0 )
106- check_success(" 01.23 == 1.23" , 1.23 , 1.23 )
94+ check_success(" 0d == 0.000000000000000000e+00d" , 0d , 0.000000000000000000e+00d )
95+ check_success(" 0d == -0.000000000000000000e+00d" , 0d , - 0.000000000000000000e+00d )
96+ check_success(" 0d == -0.000000000000000000e+00D" , 0d , - 0.000000000000000000e+00D )
97+ check_success(" 0.0 == 0.000000000000000000e+00" , 0.0 , 0.000000000000000000e+00 )
98+ check_success(" 0.0 == -0.000000000000000000e+00" , 0.0 , - 0.000000000000000000e+00 )
99+ check_success(" 1.23 == 1.23" , 1.23 , 1.23 )
100+ check_success(" 01.23 == 1.23" , 01.23 , 1.23 )
107101 check_success(" 01.23d == 1.23d" , 1.23d , 1.23d )
108102 check_success(" 3.14 == 3.14" , 3.14 , 3.14 )
109103 check_success(" 1e-9d == 1.0e-9" , 1e-9d , 1.0e-9 )
110104 check_success(" 1e137 == 1.0e137" , 1e137 , 1.0e137 )
105+ check_success(" 1.7976931348623157e308d == Double.MaxValue" , 1.7976931348623157e308d , Double .MaxValue )
111106 check_success(" 1.asInstanceOf[Double] == 1.0" , 1 .asInstanceOf [Double ], 1.0 )
112- check_success(" 1l .asInstanceOf[Double] == 1.0" , 1l .asInstanceOf [Double ], 1.0 )
107+ check_success(" 1L .asInstanceOf[Double] == 1.0" , 1L .asInstanceOf [Double ], 1.0 )
113108
114- println
115109 check_success(" \"\" .length()" , " \u001a " .length(), 1 )
116110
117111 val ggg = GGG (1 ) \ u03b1\ u03b1 GGG (2 )
0 commit comments