MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestParseMathSubs

Function TestParseMathSubs

dql/parser_test.go:31–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestParseMathSubs(t *testing.T) {
32 q := `query test($a: int) {
33 q(func: uid(0x1)) {
34 x as count(uid)
35 p : math(x + $a)
36 }
37}`
38
39 r := Request{
40 Str: q,
41 Variables: map[string]string{"$a": "3"},
42 }
43 gq, err := Parse(r)
44 require.NoError(t, err)
45 val := gq.Query[0].Children[1].MathExp.Child[1].Const
46 require.NotNil(t, val)
47 require.Equal(t, val.Tid, types.IntID)
48 require.Equal(t, val.Value, int64(3))
49
50 r = Request{
51 Str: q,
52 Variables: map[string]string{"$a": "3.3"},
53 }
54 _, err = Parse(r)
55 require.Error(t, err)
56 require.Contains(t, err.Error(), "Expected an int but got 3.3")
57}
58
59func TestParseCountValError(t *testing.T) {
60 query := `

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected