-
Notifications
You must be signed in to change notification settings - Fork 1
/
printer_test.go
58 lines (50 loc) · 2.09 KB
/
printer_test.go
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
package main
import "testing"
func TestPrimitivePrinter(t *testing.T) {
intPrinter := NewPrimitivePrinter(1, "test_int", "int", " ")
inthql := intPrinter.Print()
expecthql := " test_int int"
if inthql != expecthql {
t.Errorf("result of print should be \n%q\nbut\n%q", expecthql, inthql)
}
}
func TestStructPrinter(t *testing.T) {
childPrinterA := NewPrimitivePrinter(2, "childa", "int", ":")
childPrinterB := NewPrimitivePrinter(2, "childb", "string", ":")
plist := []Printer{childPrinterA, childPrinterB}
structPrinter := NewStructPrinter(1, "structprinter", " ", plist)
structhql := structPrinter.Print()
expecthql := " structprinter struct<\n childa:int,\n childb:string\n >"
if structhql != expecthql {
t.Errorf("result of print should be \n%q\nbut\n%q", expecthql, structhql)
}
}
func TestPrimitiveArrayPrinter(t *testing.T) {
arrayPrinter := NewPrimitiveArrayPrinter(1, "arrayprinter", " ", "int")
arrayhql := arrayPrinter.Print()
expecthql := " arrayprinter array<int>"
if arrayhql != expecthql {
t.Errorf("result of print should be \n%q\nbut\n%q", expecthql, arrayhql)
}
}
func TestStructArrayPrinter(t *testing.T) {
childPrinterA := NewPrimitivePrinter(3, "childa", "int", ":")
childPrinterB := NewPrimitivePrinter(3, "childb", "string", ":")
plist := []Printer{childPrinterA, childPrinterB}
arrayPrinter := NewStructArrayPrinter(1, "structarrayprinter", " ", plist)
arrayhql := arrayPrinter.Print()
expecthql := " structarrayprinter array<\n struct<\n childa:int,\n childb:string\n >\n >"
if arrayhql != expecthql {
t.Errorf("result of print should be \n%q\nbut\n%q", expecthql, arrayhql)
}
}
func TestMultipleArrayPrinter(t *testing.T) {
descendant := NewPrimitiveArrayPrinter(3, "", "", "int")
child := NewMultipleArrayPrinter(2, "", "", descendant)
arrayPrinter := NewMultipleArrayPrinter(1, "multiarrayprinter", " ", child)
arrayhql := arrayPrinter.Print()
expecthql := " multiarrayprinter array<\n array<\n array<int>\n >\n >"
if arrayhql != expecthql {
t.Errorf("result of print should be \n%q\nbut\n%q", expecthql, arrayhql)
}
}