Skip to content

Commit

Permalink
Fix test cases to work with new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tsandall committed Feb 10, 2017
1 parent b1349c8 commit 49a963f
Show file tree
Hide file tree
Showing 26 changed files with 1,819 additions and 1,910 deletions.
12 changes: 7 additions & 5 deletions ast/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestCompare(t *testing.T) {
{`{1: 2, 3: 4, 5: 6}`, `{1: 2, 3: 4}`, 1},

// Array comprehensions
{`[ null | true ]`, `[ false | null ]`, -1},
{`[null | true]`, `[false | null]`, -1},

// Expressions
{`a = b`, `b = a`, -1},
Expand All @@ -44,8 +44,8 @@ func TestCompare(t *testing.T) {
{`a = b with input.foo as bar`, `a = b with input.foo as bar with input.baz as qux`, -1},

// Body
{`a = b`, `a = b, b = a`, -1},
{`a = b, b = a`, `a = b`, 1},
{`a = b`, `a = b; b = a`, -1},
{`a = b; b = a`, `a = b`, 1},
}
for _, tc := range tests {
var a, b interface{}
Expand All @@ -72,9 +72,11 @@ func TestCompareModule(t *testing.T) {
}

a = MustParseModule(`package a.b.c
import input.x.y`)
import input.x.y`)
b = MustParseModule(`package a.b.c
import input.x.z`)
import input.x.z`)
result = Compare(a, b)

if result != -1 {
Expand Down
30 changes: 15 additions & 15 deletions ast/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type Compiler struct {
// following module:
//
// package ex
// p[1] :- true
// p[2] :- true
// q :- true
// p[1] { true }
// p[2] { true }
// q = true
//
// root
// |
Expand Down Expand Up @@ -207,8 +207,8 @@ func (c *Compiler) Failed() bool {
//
// package a.b.c
//
// p[k] = v :- ... # rule1
// p[k1] = v1 :- ... # rule2
// p[k] = v { ... } # rule1
// p[k1] = v1 { ... } # rule2
//
// The following calls yield the rules on the right.
//
Expand All @@ -235,8 +235,8 @@ func (c *Compiler) GetRulesExact(ref Ref) (rules []*Rule) {
//
// package a.b.c
//
// p[k] = v :- ... # rule1
// p[k1] = v1 :- ... # rule2
// p[k] = v { ... } # rule1
// p[k1] = v1 { ... } # rule2
//
// The following calls yield the rules on the right.
//
Expand Down Expand Up @@ -266,9 +266,9 @@ func (c *Compiler) GetRulesForVirtualDocument(ref Ref) (rules []*Rule) {
//
// package a.b.c
//
// p[x] = y :- ... # rule1
// p[k] = v :- ... # rule2
// q :- ... # rule3
// p[x] = y { ... } # rule1
// p[k] = v { ... } # rule2
// q { ... } # rule3
//
// The following calls yield the rules on the right.
//
Expand Down Expand Up @@ -306,8 +306,8 @@ func (c *Compiler) GetRulesWithPrefix(ref Ref) (rules []*Rule) {
//
// package a.b.c
//
// p[x] = y :- q[x] = y, ... # rule1
// q[x] = y :- ... # rule2
// p[x] = y { q[x] = y; ... } # rule1
// q[x] = y { ... } # rule2
//
// The following calls yield the rules on the right.
//
Expand Down Expand Up @@ -516,7 +516,7 @@ func (c *Compiler) getExports() *util.HashMap {
//
// package a.b
// import data.foo.bar
// p[x] :- bar[_] = x
// p[x] { bar[_] = x }
//
// The reference "bar[_]" would be resolved to "data.foo.bar[_]".
func (c *Compiler) resolveAllRefs() {
Expand Down Expand Up @@ -574,11 +574,11 @@ func (c *Compiler) resolveAllRefs() {
//
// For instance, given the following rule:
//
// p[{"foo": data.foo[i]}] :- i < 100
// p[{"foo": data.foo[i]}] { i < 100 }
//
// The rule would be re-written as:
//
// p[__local0__] :- i < 100, __local0__ = {"foo": data.foo[i]}
// p[__local0__] { i < 100; __local0__ = {"foo": data.foo[i]} }
func (c *Compiler) rewriteRefsInHead() {
for _, mod := range c.Modules {
generator := newLocalVarGenerator(mod)
Expand Down
Loading

0 comments on commit 49a963f

Please sign in to comment.