This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwith_test.go
115 lines (97 loc) · 1.72 KB
/
with_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package go_cypherdsl
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestWithConfig_ToString(t *testing.T) {
req := require.New(t)
//one
conf := WithConfig{
Parts: []WithPart{
{
Name: "test",
},
},
}
cypher, err := conf.ToString()
req.Nil(err)
req.EqualValues("test", cypher)
//two
conf = WithConfig{
Parts: []WithPart{
{
Name: "test",
},
{
Name: "t",
As: "woo",
},
},
}
cypher, err = conf.ToString()
req.Nil(err)
req.EqualValues("test, t AS woo", cypher)
//empty
conf = WithConfig{}
_, err = conf.ToString()
req.NotNil(err)
}
func TestWithPart_ToString(t *testing.T) {
req := require.New(t)
//test function
part := WithPart{
Function: &FunctionConfig{
Name: "test",
},
}
cypher, err := part.ToString()
req.Nil(err)
req.EqualValues("test()", cypher)
//test function as
part = WithPart{
Function: &FunctionConfig{
Name: "test",
},
As: "TEST",
}
cypher, err = part.ToString()
req.Nil(err)
req.EqualValues("test() AS TEST", cypher)
//test name
part = WithPart{
Name: "test",
}
cypher, err = part.ToString()
req.Nil(err)
req.EqualValues("test", cypher)
//test name field
part = WithPart{
Name: "test",
Field: "t",
}
cypher, err = part.ToString()
req.Nil(err)
req.EqualValues("test.t", cypher)
//test name field as
part = WithPart{
Name: "test",
Field: "t",
As: "TEST",
}
cypher, err = part.ToString()
req.Nil(err)
req.EqualValues("test.t AS TEST", cypher)
//test nothing defined
part = WithPart{}
_, err = part.ToString()
req.NotNil(err)
//test function with name (error)
part = WithPart{
Function: &FunctionConfig{
Name: "t",
},
Name: "test",
}
_, err = part.ToString()
req.NotNil(err)
}