1
+ /*
2
+ * Copyright 2011 Christos KK Loverdos
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .ckkloverdos .convert
18
+
19
+
20
+ import org .junit .Assert
21
+ import org .junit .Test
22
+
23
+ /**
24
+ *
25
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
26
+ */
27
+ class TypeTest {
28
+
29
+ val infoList = List (
30
+ (1 : Byte , Manifest .Byte , Array [Byte ](), typeOf[Array [Byte ]]),
31
+ (true , Manifest .Boolean , Array [Boolean ](), typeOf[Array [Boolean ]]),
32
+ (1 : Short , Manifest .Short , Array [Short ](), typeOf[Array [Short ]]),
33
+ (' ' , Manifest .Char , Array [Char ](), typeOf[Array [Char ]]),
34
+ (1 : Int , Manifest .Int , Array [Int ](), typeOf[Array [Int ]]),
35
+ (1 : Long , Manifest .Long , Array [Long ](), typeOf[Array [Long ]]),
36
+ (1 : Float , Manifest .Float , Array [Float ](), typeOf[Array [Float ]]),
37
+ (1 : Double , Manifest .Double , Array [Double ](), typeOf[Array [Double ]]) // ,
38
+ // ((), Manifest.Unit, Array[Unit](), manifest[Array[Unit]]) // we have a bug in scalac here...
39
+ )
40
+
41
+ val valueList = infoList map {
42
+ case (v, m, _, _) ⇒ (v, m)
43
+ }
44
+ val arrayList = infoList map {
45
+ case (_, _, av, am) ⇒ (av, am)
46
+ }
47
+
48
+ def id [A ](a : A ) = a
49
+
50
+ def _checkValue [T ](value : T , expectedType : Type [_], info : String = " " ): Unit = {
51
+ val computedType = typeOfAny(value)
52
+ Assert .assertEquals(" %sType for value %s" .format(info, value), expectedType, computedType)
53
+ }
54
+
55
+ @ Test
56
+ def testValues : Unit = {
57
+ for ((value, tpe) <- valueList) {
58
+ // println("Testing value %s of manifest %s".format(value, manifest))
59
+ _checkValue(value, tpe)
60
+ }
61
+ }
62
+
63
+ @ Test
64
+ def testValues2 : Unit = {
65
+ val v2 = valueList map {
66
+ case (v, m) => (id(v), m)
67
+ }
68
+ for ((value, tpe) <- v2) {
69
+ // println("Testing(2) value %s of manifest %s".format(value, manifest))
70
+ _checkValue(value, tpe)
71
+ }
72
+ }
73
+
74
+ @ Test
75
+ def testNull : Unit = {
76
+ _checkValue(null , typeOf[Null ])
77
+ }
78
+
79
+ @ Test
80
+ def testArray : Unit = {
81
+ for ((av, am) <- arrayList) {
82
+ _checkValue(av, am)
83
+ }
84
+ }
85
+ }
0 commit comments