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

Function TestParseLiteralOrFormulaPositive

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

Source from the content-addressed store, hash-verified

604}
605
606func TestParseLiteralOrFormulaPositive(t *testing.T) {
607 tests := []struct {
608 name string
609 str string
610 want ast.Term
611 }{
612 {
613 name: "equality 1",
614 str: "X=Y",
615 want: ast.Eq{ast.Variable{"X"}, ast.Variable{"Y"}},
616 },
617 {
618 name: "equality 2",
619 str: "X=/foo",
620 want: ast.Eq{ast.Variable{"X"}, name("/foo")},
621 },
622 {
623 name: "equality 3",
624 str: "/foo =Y",
625 want: ast.Eq{name("/foo"), ast.Variable{"Y"}},
626 },
627 {
628 name: "equality 4",
629 str: "[/foo] =Y",
630 want: ast.Eq{ast.ApplyFn{symbols.List, []ast.BaseTerm{name("/foo")}}, ast.Variable{"Y"}},
631 },
632 {
633 name: "equality 4 fn",
634 str: "fn:list(/foo) =Y",
635 want: ast.Eq{ast.ApplyFn{ast.FunctionSym{"fn:list", 1}, []ast.BaseTerm{name("/foo")}}, ast.Variable{"Y"}},
636 },
637 {
638 name: "inequality 1",
639 str: "X!=Y",
640 want: ast.Ineq{ast.Variable{"X"}, ast.Variable{"Y"}},
641 },
642 {
643 name: "inequality 2",
644 str: "X!=/foo",
645 want: ast.Ineq{ast.Variable{"X"}, name("/foo")},
646 },
647 {
648 name: "inequality 3",
649 str: "/foo!= Y",
650 want: ast.Ineq{name("/foo"), ast.Variable{"Y"}},
651 },
652 {
653 name: "builtin :lt",
654 str: "0 < 1",
655 want: ast.NewAtom(":lt", ast.Number(0), ast.Number(1)),
656 },
657 {
658 name: "builtin :le",
659 str: "0 <= 1",
660 want: ast.NewAtom(":le", ast.Number(0), ast.Number(1)),
661 },
662 {
663 name: "builtin :gt",

Callers

nothing calls this directly

Calls 6

NewAtomFunction · 0.92
NumberFunction · 0.92
NewNegAtomFunction · 0.92
LiteralOrFormulaFunction · 0.85
nameFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected