forked from hofstadter-io/structural
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_test.go
50 lines (39 loc) · 1.16 KB
/
query_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
package structural_test
import (
"regexp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/hofstadter-io/structural"
)
type QueryTestSuite struct {
suite.Suite
queryRT *structural.CueRuntime
}
func (suit *QueryTestSuite) TestQuery() {
input := "{b : 2, c:3, d: {a: 1, d:2, x: \"hi\"}}"
result, err := structural.CueQuery("[int]", input)
assert.Nil(suit.T(), err)
expected := `[3, 2]`
space := regexp.MustCompile(`\s+`)
result = space.ReplaceAllString(result, " ")
expected = space.ReplaceAllString(expected, " ")
assert.Equal(suit.T(), result, expected)
result, err = structural.CueQuery("[_]", input)
assert.Nil(suit.T(), err)
expected = `[3, 2, {
x: "hi"
a: 1
d: 2
}]`
space = regexp.MustCompile(`\s+`)
result = space.ReplaceAllString(result, " ")
expected = space.ReplaceAllString(expected, " ")
assert.Equal(suit.T(), result, expected)
result, err = structural.CueQuery("[_,string]", input)
assert.Nil(suit.T(), err)
expected = `["hi"]`
space = regexp.MustCompile(`\s+`)
result = space.ReplaceAllString(result, " ")
expected = space.ReplaceAllString(expected, " ")
assert.Equal(suit.T(), result, expected)
}