-
Notifications
You must be signed in to change notification settings - Fork 35
/
expand_parser_test.go
122 lines (95 loc) · 2.55 KB
/
expand_parser_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
116
117
118
119
120
121
122
package godata
import (
"testing"
)
func TestTrivialExpand(t *testing.T) {
input := "Products/Categories"
output, err := ParseExpandString(input)
if err != nil {
t.Error(err)
return
}
if output.ExpandItems[0].Path[0].Value != "Products" {
t.Error("First path item is not 'Products'")
return
}
if output.ExpandItems[0].Path[1].Value != "Categories" {
t.Error("Second path item is not 'Categories'")
return
}
}
func TestSimpleExpand(t *testing.T) {
input := "Products($filter=DiscontinuedDate eq null)"
output, err := ParseExpandString(input)
if err != nil {
t.Error(err)
return
}
if output.ExpandItems[0].Path[0].Value != "Products" {
t.Error("First path item is not 'Products'")
return
}
if output.ExpandItems[0].Filter == nil {
t.Error("Filter not parsed")
return
}
if output.ExpandItems[0].Filter.Tree == nil {
t.Error("Filter tree is null")
return
}
if output.ExpandItems[0].Filter.Tree.Token.Value != "eq" {
t.Error("Filter not parsed correctly")
return
}
}
func TestExpandNestedCommas(t *testing.T) {
input := "DirectReports($select=FirstName,LastName;$levels=4)"
output, err := ParseExpandString(input)
if err != nil {
t.Error(err)
return
}
if output.ExpandItems[0].Path[0].Value != "DirectReports" {
t.Error("First path item is not 'DirectReports'")
return
}
if output.ExpandItems[0].Select.SelectItems[0].Segments[0].Value != "FirstName" {
actual := output.ExpandItems[0].Select.SelectItems[0].Segments[0]
t.Error("First select segment is '" + actual.Value + "' not 'FirstName'")
return
}
if output.ExpandItems[0].Select.SelectItems[1].Segments[0].Value != "LastName" {
actual := output.ExpandItems[0].Select.SelectItems[1].Segments[0]
t.Error("First select segment is '" + actual.Value + "' not 'LastName'")
return
}
if output.ExpandItems[0].Levels != 4 {
t.Error("Levels does not equal 4")
return
}
}
func TestExpandNestedParens(t *testing.T) {
input := "Products($filter=not (DiscontinuedDate eq null))"
output, err := ParseExpandString(input)
if err != nil {
t.Error(err)
return
}
if output.ExpandItems[0].Path[0].Value != "Products" {
t.Error("First path item is not 'Products'")
return
}
if output.ExpandItems[0].Filter == nil {
t.Error("Filter not parsed")
return
}
if output.ExpandItems[0].Filter.Tree == nil {
t.Error("Filter tree is null")
return
}
if output.ExpandItems[0].Filter.Tree.Token.Value != "not" {
actual := output.ExpandItems[0].Filter.Tree.Token.Value
t.Error("Root filter value is '" + actual + "', expected 'not'")
return
}
}