MCPcopy Index your code
hub / github.com/google/mangle / TestBoundsAnalyzer

Function TestBoundsAnalyzer

analysis/validation_test.go:606–771  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

604}
605
606func TestBoundsAnalyzer(t *testing.T) {
607 tests := []boundsTestCase{
608 newBoundsTestCase(t, []ast.Clause{
609 clause("foo(X) :- bar(X), X = 3."),
610 }, []ast.Decl{
611 makeSimpleDecl(atom("foo(X)"), ast.NumberBound),
612 makeSimpleDecl(atom("bar(X)"), ast.NumberBound),
613 }),
614 newBoundsTestCase(t, []ast.Clause{
615 clause("foo(X, Y, Z) :- bar(X, Y), baz(Y, Z)."),
616 }, []ast.Decl{
617 makeSimpleDecl(atom("foo(X, Y, Z)"), ast.StringBound, ast.NumberBound, ast.NumberBound),
618 makeSimpleDecl(atom("bar(A, B)"), ast.StringBound, ast.NumberBound),
619 makeSimpleDecl(atom("baz(E, F)"), ast.NumberBound, ast.NumberBound),
620 }),
621 newBoundsTestCase(t, []ast.Clause{
622 clause("foo(X, X) :- bar(X)."),
623 }, []ast.Decl{
624 makeSimpleDecl(atom("foo(X, Y)"), ast.NumberBound, ast.NumberBound),
625 makeSimpleDecl(atom("bar(A)"), ast.NumberBound),
626 }),
627 newBoundsTestCase(t, []ast.Clause{
628 clause("foo(X) :- bar(X)."),
629 clause("foo(X) :- baz(X)."),
630 }, []ast.Decl{
631 makeSimpleDecl(atom("foo(X)"), ast.ApplyFn{symbols.UnionType, []ast.BaseTerm{ast.StringBound, ast.NumberBound}}),
632 makeSimpleDecl(atom("bar(A)"), ast.StringBound),
633 makeSimpleDecl(atom("baz(A)"), ast.NumberBound),
634 }),
635 newBoundsTestCase(t, []ast.Clause{
636 clause("foo(X) :- bar(X)."),
637 clause("foo(X) :- baz(X)."),
638 }, []ast.Decl{
639 makeSimpleDecl(atom("foo(X)"), ast.NumberBound),
640 makeSimpleDecl(atom("bar(A)"), ast.NumberBound),
641 makeSimpleDecl(atom("baz(A)"), ast.NumberBound),
642 }),
643 newBoundsTestCase(t, []ast.Clause{
644 clause("foo(1)."),
645 clause("foo(X) :- bar(X)."),
646 clause("bar(X) :- foo(X)."),
647 }, []ast.Decl{
648 makeSimpleDecl(atom("foo(X)"), ast.NumberBound),
649 makeSimpleDecl(atom("bar(A)"), ast.NumberBound),
650 }),
651 newBoundsTestCase(t, []ast.Clause{
652 clause("foo(1)."),
653 clause("foo(['a'])."),
654 clause("foo(X) :- bar(X)."),
655 clause("bar(X) :- foo(X)."),
656 }, []ast.Decl{
657 ast.Decl{
658 DeclaredAtom: atom("foo(X)"),
659 Bounds: []ast.BoundDecl{
660 ast.NewBoundDecl(ast.NumberBound),
661 ast.NewBoundDecl(symbols.NewListType(ast.StringBound)),
662 },
663 },

Callers

nothing calls this directly

Calls 15

NewBoundDeclFunction · 0.92
NewListTypeFunction · 0.92
NewMapTypeFunction · 0.92
NewStructTypeFunction · 0.92
NewOptionTypeFunction · 0.92
NewPairTypeFunction · 0.92
NewTupleTypeFunction · 0.92
NewUnionTypeFunction · 0.92
NewNameTrieFunction · 0.92
newBoundsTestCaseFunction · 0.85
makeSimpleDeclFunction · 0.85
newBoundsAnalyzerFunction · 0.85

Tested by

no test coverage detected