(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func 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, |
nothing calls this directly
no test coverage detected