-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeserializeTest.scala
108 lines (88 loc) · 3.87 KB
/
DeserializeTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package galliatest.suites.single
import gallia._
// ===========================================================================
object DeserializeTest extends gallia.testing.Suite { // formerly UntuplifyTest
import enumeratum.{Enum, EnumEntry}
sealed trait DeserializeEnum extends EnumEntry
object DeserializeEnum extends Enum[DeserializeEnum] {
val values = findValues
// ---------------------------------------------------------------------------
case object str extends DeserializeEnum
case object int extends DeserializeEnum
}
// ===========================================================================
override def test() {
// ---------------------------------------------------------------------------
// deserialize1
bobj('f -> Seq("foo", "3"))
.deserialize1z('f ~> 'F).asNewKeys[DeserializeEnum]
.check(
bobj('F -> bobj('str -> "foo", 'int -> "3")))
bobj('f -> Seq("foo", "3"))
.deserialize1z('f ~> 'F).asNewKeys('str, 'int)
.check(
bobj('F -> bobj('str -> "foo", 'int -> "3")))
// ---------------------------------------------------------------------------
bobj('f -> "foo|3")
.deserialize1a('f ~> 'F).withSplitter(_.split("\\|")).asNewKeys('str, 'int)
.check(
bobj('F -> bobj('str -> "foo", 'int -> "3")))
bobj('f -> Seq("foo|3", "bar|4"))
.deserialize1a('f ~> 'F).withSplitter(_.split("\\|")).asNewKeys('str, 'int)
.check(
bobj('F -> Seq(bobj('str -> "foo", 'int -> "3"), bobj('str -> "bar", 'int -> "4"))))
bobj('f -> Seq("foo|3", "bar|4"))
//.deserialize1c('f ~> 'F).withSeparator(entry = "|").as('str, 'int),
.deserialize1a('f ~> 'F)
.withSplitter("|").asNewKeys('str, 'int)
.check(
bobj('F -> Seq(
bobj('str -> "foo", 'int -> "3"),
bobj('str -> "bar", 'int -> "4")) ))
// ---------------------------------------------------------------------------
bobj('f -> "foo|3,bar|4")
.deserialize1b('f ~> 'F)
.withSplitters(",", "|")
.asNewKeys('str, 'int)
.check(
bobj('F -> Seq(
bobj('str -> "foo", 'int -> "3"),
bobj('str -> "bar", 'int -> "4")) ))
// ===========================================================================
// deserialize2
bobj('f -> Seq("str=foo", "int=3"))
.deserialize2z('f ~> 'F)
.withSplitter("=")
.asNewKeys('str, 'int)
.check(
bobj('F -> bobj('str -> "foo", 'int -> "3")))
// ---------------------------------------------------------------------------
bobj('f -> "str=foo|int=3")
.deserialize2a('f ~> 'F)
.withSplitters("|", "=")
.asNewKeys('str, 'int)
.check(
bobj('F -> bobj('str /* = */ -> "foo" /* ; */, 'int -> "3")))
// ---------------------------------------------------------------------------
bobj('f -> Seq("str=foo;int=3", "str=bar;int=4", "str=baz;int=5"))
.deserialize2a('f ~> 'F)
.withSplitters(";", "=")
.asNewKeys('str, 'int)
.check(
bobj('F -> Seq(
bobj('str /* = */ -> "foo" /* ; */, 'int -> "3"),
bobj('str /* = */ -> "bar" /* ; */, 'int -> "4"),
bobj('str /* = */ -> "baz" /* ; */, 'int -> "5"))))
// ---------------------------------------------------------------------------
bobj('f -> "str=foo;int=3,str=bar;int=4,str=baz;int=5")
.deserialize2b('f ~> 'F)
.withSplitters(",", ";", "=")
.asNewKeys('str, 'int)
.check(
bobj('F -> /* , */ Seq(
bobj('str /* = */ -> "foo" /* ; */, 'int -> "3"),
bobj('str /* = */ -> "bar" /* ; */, 'int -> "4"),
bobj('str /* = */ -> "baz" /* ; */, 'int -> "5"))))
}
}
// ===========================================================================