MCPcopy
hub / github.com/google/mangle / TestParseDecl

Function TestParseDecl

parse/parse_test.go:46–224  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestParseDecl(t *testing.T) {
47 inclConstraint := ast.NewInclusionConstraint([]ast.Atom{
48 ast.NewAtom("bar", ast.Variable{"X"}),
49 ast.NewAtom("baz", ast.Variable{"X"}),
50 ast.NewAtom("bak", ast.Variable{"X"}, ast.Variable{"Y"}),
51 })
52 tests := []struct {
53 name string
54 str string
55 want []ast.Decl
56 }{
57 {
58 name: "one decl",
59 str: "Decl foo(X,Y).",
60 want: []ast.Decl{makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}), emptyDoc, nil, nil)},
61 },
62 {
63 name: "one decl one bound",
64 str: "Decl foo(X,Y) bound [/string, fn:List(/string)].",
65 want: []ast.Decl{makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}),
66 nil,
67 []ast.BoundDecl{
68 ast.NewBoundDecl(ast.StringBound, ast.ApplyFn{symbols.ListType, []ast.BaseTerm{ast.StringBound}}),
69 },
70 nil)},
71 },
72 {
73 name: "one decl one bound fancy syntax",
74 str: "Decl foo(X,Y) bound [/string, .List</string>].",
75 want: []ast.Decl{makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}),
76 nil,
77 []ast.BoundDecl{
78 ast.NewBoundDecl(ast.StringBound, ast.ApplyFn{Function: ast.FunctionSym{"fn:List", -1}, Args: []ast.BaseTerm{ast.StringBound}}),
79 },
80 nil)},
81 },
82 {
83 name: "one decl two bounds w/ whitespace",
84 str: "Decl foo(X,Y) bound[ /string, /string ]bound[/number, /number].",
85 want: []ast.Decl{makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}),
86 emptyDoc,
87 []ast.BoundDecl{
88 ast.NewBoundDecl(ast.StringBound, ast.StringBound),
89 ast.NewBoundDecl(ast.NumberBound, ast.NumberBound),
90 },
91 nil)},
92 },
93 {
94 name: "one decl one inclusion",
95 str: "Decl foo(X,Y) inclusion[bar(X), baz(X), bak(X, Y)].",
96 want: []ast.Decl{makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}), emptyDoc, nil, &inclConstraint)},
97 },
98 {
99 name: "one decl one bound one inclusion",
100 str: "Decl foo(X,Y) bound[/string, .Pair</string, /number>] inclusion[bar(X), baz(X), bak(X, Y)].",
101 want: []ast.Decl{
102 makeDecl(t, ast.NewAtom("foo", ast.Variable{"X"}, ast.Variable{"Y"}),
103 emptyDoc,

Callers

nothing calls this directly

Calls 7

NewInclusionConstraintFunction · 0.92
NewAtomFunction · 0.92
NewBoundDeclFunction · 0.92
StringFunction · 0.92
UnitFunction · 0.85
makeDeclFunction · 0.70
nameFunction · 0.70

Tested by

no test coverage detected