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 pathreturn_test.go
81 lines (66 loc) · 1.72 KB
/
return_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
package go_cypherdsl
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestReturnPart_ToString(t *testing.T) {
req := require.New(t)
literal := ReturnPart{Literal: "test"}
boolExpr := ReturnPart{BooleanExpression: "test"}
path := ReturnPart{Path: "test-test"}
nameOnly := ReturnPart{Name: "name"}
nameType := ReturnPart{Name: "name", Type: "whatever"}
nameTypeAlias := ReturnPart{Name: "name", Type: "whatever", Alias: "test"}
empty := ReturnPart{}
var err error
var cypher string
//test literal
cypher, err = literal.ToString()
req.Nil(err)
req.EqualValues("'test'", cypher)
//test bool expression
cypher, err = boolExpr.ToString()
req.Nil(err)
req.EqualValues("test", cypher)
//test path
cypher, err = path.ToString()
req.Nil(err)
req.EqualValues("test-test", cypher)
//test name only
cypher, err = nameOnly.ToString()
req.Nil(err)
req.EqualValues("name", cypher)
//test name.whatever
cypher, err = nameType.ToString()
req.Nil(err)
req.EqualValues("name.whatever", cypher)
//test name.whatever as test
cypher, err = nameTypeAlias.ToString()
req.Nil(err)
req.EqualValues("name.whatever AS test", cypher)
//test nothing defined
cypher, err = empty.ToString()
req.NotNil(err)
req.EqualValues("", cypher)
}
func TestNewReturnClause(t *testing.T) {
req := require.New(t)
//empty test
cypher, err := NewReturnClause(false)
req.NotNil(err)
req.EqualValues("", cypher)
//one part
cypher, err = NewReturnClause(false, ReturnPart{
Name: "t",
})
req.Nil(err)
req.EqualValues("RETURN t", cypher.ToString())
//two parts
cypher, err = NewReturnClause(false, ReturnPart{
Name: "t1",
}, ReturnPart{
Name: "t2",
})
req.Nil(err)
req.EqualValues("RETURN t1, t2", cypher.ToString())
}