-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ast): implement and require builtin statements
BREAKING CHANGE: The option string is now a keyword. In addition to adding and implementing the builtin keyword, option was changed to be a keyword.
- Loading branch information
1 parent
fb9573f
commit a7247c9
Showing
48 changed files
with
5,282 additions
and
2,360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package flux | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/influxdata/flux/ast" | ||
"github.com/influxdata/flux/interpreter" | ||
"github.com/influxdata/flux/values" | ||
) | ||
|
||
func TestValidatePackageBuiltins(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
pkg *interpreter.Package | ||
astPkg *ast.Package | ||
err error | ||
}{ | ||
{ | ||
name: "no errors", | ||
pkg: interpreter.NewPackageWithValues("test", values.NewObjectWithValues(map[string]values.Value{ | ||
"foo": values.NewInt(0), | ||
})), | ||
astPkg: &ast.Package{ | ||
Files: []*ast.File{{ | ||
Body: []ast.Statement{ | ||
&ast.BuiltinStatement{ | ||
ID: &ast.Identifier{Name: "foo"}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
name: "extra values", | ||
pkg: interpreter.NewPackageWithValues("test", values.NewObjectWithValues(map[string]values.Value{ | ||
"foo": values.NewInt(0), | ||
})), | ||
astPkg: &ast.Package{}, | ||
err: errors.New("missing builtin values [], extra builtin values [foo]"), | ||
}, | ||
{ | ||
name: "missing values", | ||
pkg: interpreter.NewPackageWithValues("test", values.NewObject()), | ||
astPkg: &ast.Package{ | ||
Files: []*ast.File{{ | ||
Body: []ast.Statement{ | ||
&ast.BuiltinStatement{ | ||
ID: &ast.Identifier{Name: "foo"}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
err: errors.New("missing builtin values [foo], extra builtin values []"), | ||
}, | ||
{ | ||
name: "missing and values", | ||
pkg: interpreter.NewPackageWithValues("test", values.NewObjectWithValues(map[string]values.Value{ | ||
"foo": values.NewInt(0), | ||
"bar": values.NewInt(0), | ||
})), | ||
astPkg: &ast.Package{ | ||
Files: []*ast.File{{ | ||
Body: []ast.Statement{ | ||
&ast.BuiltinStatement{ | ||
ID: &ast.Identifier{Name: "foo"}, | ||
}, | ||
&ast.BuiltinStatement{ | ||
ID: &ast.Identifier{Name: "baz"}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
err: errors.New("missing builtin values [baz], extra builtin values [bar]"), | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validatePackageBuiltins(tc.pkg, tc.astPkg) | ||
switch { | ||
case err == nil && tc.err == nil: | ||
// Test passes | ||
case err == nil && tc.err != nil: | ||
t.Errorf("expected error %v", tc.err) | ||
case err != nil && tc.err == nil: | ||
t.Errorf("unexpected error %v", err) | ||
case err != nil && tc.err != nil: | ||
if err.Error() != tc.err.Error() { | ||
t.Errorf("differing error messages -want/+got:\n%s", cmp.Diff(tc.err.Error(), err.Error())) | ||
} | ||
// else test passes | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.