-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_test.go
86 lines (68 loc) · 1.9 KB
/
type_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
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
package jot
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTypeString(t *testing.T) {
b := new(bytes.Buffer)
spec := TypeString("testType")
err := spec.Write(b)
assert.Nil(t, err)
output := b.String()
expect := "testType"
assert.Equal(t, expect, output, "Output mismatch.")
}
func TestTypeFrom(t *testing.T) {
b := new(bytes.Buffer)
spec := TypeString("testType").From(Import("imaginarypkg"))
file := File("type_test").AddVariable(Variable("test", spec))
err := file.Write(b)
assert.Nil(t, err)
output := b.String()
expect := "package type_test\nimport (\n\"imaginarypkg\"\n)\nvar test testType\n"
assert.Equal(t, expect, output, "Output mismatch.")
// Make sure what we write can be generated.
b.Reset()
err = file.Generate(b)
assert.Nil(t, err)
}
func TestPtr(t *testing.T) {
}
func TestArray(t *testing.T) {
}
func TestMap(t *testing.T) {
b := new(bytes.Buffer)
spec := Map(TypeString("key"), TypeString("value"))
err := spec.Write(b)
assert.Nil(t, err)
output := b.String()
expect := "map[key]value"
assert.Equal(t, expect, output, "Output mismatch.")
// Make sure what we write can be generated.
b.Reset()
err = File("test_map").AddVariable(Variable("TestMap", spec)).Generate(b)
assert.Nil(t, err)
}
func TestChan(t *testing.T) {
b := new(bytes.Buffer)
spec := Chan(TypeString("test"))
err := spec.Write(b)
assert.Nil(t, err)
output := b.String()
expect := "chan test"
assert.Equal(t, expect, output, "Output mismatch.")
// Make sure what we write can be generated.
b.Reset()
err = File("test_chan").AddVariable(Variable("TestChan", spec)).Generate(b)
assert.Nil(t, err)
}
func TestFunc(t *testing.T) {
b := new(bytes.Buffer)
spec := Func().AddReturnType(TypeString("a")).AddParameter(TypeString("b"))
err := spec.Write(b)
assert.Nil(t, err)
output := b.String()
expect := "func(b) a"
assert.Equal(t, expect, output, "Output mismatch.")
}