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

Function TestTopDown

engine/topdown_test.go:26–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestTopDown(t *testing.T) {
27 store := factstore.NewSimpleInMemoryStore()
28 clauses := []ast.Clause{
29 clause(`
30missing_required(RequiredList, EnabledList, Witness) :-
31 :list:member(Witness, RequiredList),
32 !:list:member(Witness, EnabledList).`),
33 }
34
35 missingRequiredDecl, err := ast.NewDecl(atom("missing_required(EnabledList, RequiredList, Witness)"), []ast.Atom{
36 atom("mode('+', '+', '-')"),
37 atom("deferred()"),
38 }, nil, nil)
39 if err != nil {
40 t.Fatal(err)
41 }
42 decls := []ast.Decl{missingRequiredDecl}
43 if err := analyzeAndEvalProgramWithDecls(t, clauses, decls, store); err != nil {
44 t.Errorf("Program evaluation failed %v program %v", err, clauses)
45 return
46 }
47 query, err := functional.EvalAtom(atom("missing_required(['foo'], ['bar'], Witness)"), nil)
48 if err != nil {
49 t.Fatal(err)
50 }
51 want, err := functional.EvalAtom(atom("missing_required(['foo'], ['bar'],'foo')"), nil)
52 if err != nil {
53 t.Fatal(err)
54 }
55 context := QueryContext{PredToRules: map[ast.PredicateSym][]ast.Clause{
56 ast.PredicateSym{"missing_required", 3}: clauses,
57 },
58 PredToDecl: map[ast.PredicateSym]*ast.Decl{
59 ast.PredicateSym{"missing_required", 3}: &missingRequiredDecl,
60 },
61 Store: store,
62 }
63
64 uf := unionfind.New()
65 if err != nil {
66 t.Fatal(err)
67 }
68 found := false
69 err = context.EvalQuery(query, []ast.ArgMode{ast.ArgModeInput, ast.ArgModeInput, ast.ArgModeOutput}, uf, func(got ast.Atom) error {
70 found = true
71 if !got.Equals(want) {
72 t.Errorf("got: %v want: %v", got, want)
73 }
74 return nil
75 })
76 if err != nil {
77 t.Fatal(err)
78 }
79 if !found {
80 t.Errorf("got nothing want: %v", want)
81 }
82}

Callers

nothing calls this directly

Calls 9

EvalQueryMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.92
NewDeclFunction · 0.92
EvalAtomFunction · 0.92
NewFunction · 0.92
clauseFunction · 0.70
atomFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected