Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 06132b3

Browse files
committed
Add more tests, especially for manifests
1 parent 610860d commit 06132b3

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/test/scala/com/ckkloverdos/convert/ConvertersTest.scala

+10
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@ class ConvertersTest {
102102
case _: Exception =>
103103
}
104104
}
105+
106+
@Test
107+
def testPrimitiveArray: Unit = {
108+
val convertersB = new StdConvertersBuilder()
109+
convertersB.register[Array[Int], Long](true) { array (0 /: array)(_+_)}
110+
val converters = convertersB.build
111+
val sum = converters.convertEx[Long](Array(1, 2, 3))
112+
// by the way, also test the sum, though we shouldn't for several reasons
113+
assertEquals((1 + 2 + 3), sum)
114+
}
105115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.manifest
18+
19+
import org.junit.Assert
20+
import org.junit.Test
21+
22+
/**
23+
*
24+
* @author Christos KK Loverdos <loverdos@gmail.com>.
25+
*/
26+
class ManifestTest {
27+
28+
val infoList = List(
29+
(1: Byte, Manifest.Byte, Array[Byte](), manifest[Array[Byte]]),
30+
(true, Manifest.Boolean, Array[Boolean](), manifest[Array[Boolean]]),
31+
(1: Short, Manifest.Short, Array[Short](), manifest[Array[Short]]),
32+
(' ', Manifest.Char, Array[Char](), manifest[Array[Char]]),
33+
(1: Int, Manifest.Int, Array[Int](), manifest[Array[Int]]),
34+
(1: Long, Manifest.Long, Array[Long](), manifest[Array[Long]]),
35+
(1: Float, Manifest.Float, Array[Float](), manifest[Array[Float]]),
36+
(1: Double, Manifest.Double, Array[Double](), manifest[Array[Double]])//,
37+
// ((), Manifest.Unit, Array[Unit](), manifest[Array[Unit]]) // we have a bug in scalac here...
38+
)
39+
40+
val valueList = infoList map { case (v, m, _, _) (v, m) }
41+
val arrayList = infoList map { case (_, _, av, am) (av, am) }
42+
43+
def id[A](a: A) = a
44+
45+
def _checkValue[T](value: T, expected: OptManifest[_], info: String = ""): Unit = {
46+
val computed = ManifestHelpers.manifestOfAny(value)
47+
Assert.assertEquals("%sManifest for value %s".format(info, value), expected, computed)
48+
}
49+
50+
@Test
51+
def testValues: Unit = {
52+
for((value, manifest) <- valueList) {
53+
// println("Testing value %s of manifest %s".format(value, manifest))
54+
_checkValue(value, manifest)
55+
}
56+
}
57+
58+
@Test
59+
def testValues2: Unit = {
60+
val v2 = valueList map { case (v, m) => (id(v), m) }
61+
for((value, manifest) <- v2) {
62+
// println("Testing(2) value %s of manifest %s".format(value, manifest))
63+
_checkValue(value, manifest)
64+
}
65+
}
66+
67+
@Test
68+
def testNull: Unit = {
69+
_checkValue(null, Manifest.Null)
70+
}
71+
72+
@Test
73+
def testArray: Unit = {
74+
for((av, am) <- arrayList) {
75+
_checkValue(av, am)
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)