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

Function TestListMapStruct

engine/seminaivebottomup_test.go:468–502  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

466}
467
468func TestListMapStruct(t *testing.T) {
469 store := factstore.NewSimpleInMemoryStore()
470 program := []ast.Clause{
471 // List
472 clause(`bar(1).`),
473 clause(`foo(X) :- bar(Y), X = [Y].`),
474 clause(`baz(Y) :- X = [0,1,2], Y = fn:list:get(X, 1).`),
475 // Map
476 clause(`bar_map([ "foo" : /foo, "bar": /bar ]).`),
477 clause(`bar_map([ "foo" : /hoo, "bar": /zar ]).`),
478 clause(`bar_entry(Y, Z) :- bar_map(X), :match_entry(X, "foo", Y), :match_entry(X, "bar", Z).`),
479 // Struct
480 clause(`bar_struct({ /foo : 1, /bar : "barbar"}).`),
481 clause(`bar_extracted(Y, Z) :- bar_struct(X), :match_field(X, /foo, Y), :match_field(X, /bar, Z).`),
482 }
483
484 if err := analyzeAndEvalProgram(t, program, store); err != nil {
485 t.Errorf("Program evaluation failed %v program %v", err, program)
486 return
487 }
488
489 expected := []ast.Atom{
490 ast.NewAtom("foo", ast.List([]ast.Constant{ast.Number(1)})),
491 atom("baz(1)"),
492 atom("bar_entry(/foo, /bar)"),
493 atom("bar_entry(/hoo, /zar)"),
494 ast.NewAtom("bar_extracted", ast.Number(1), ast.String("barbar")),
495 }
496
497 for _, fact := range expected {
498 if !store.Contains(fact) {
499 t.Errorf("expected fact %v in store %v", fact, store)
500 }
501 }
502}
503
504func TestTransform(t *testing.T) {
505 store := factstore.NewSimpleInMemoryStore()

Callers

nothing calls this directly

Calls 9

ContainsMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.92
NewAtomFunction · 0.92
ListFunction · 0.92
NumberFunction · 0.92
StringFunction · 0.92
analyzeAndEvalProgramFunction · 0.85
clauseFunction · 0.70
atomFunction · 0.70

Tested by

no test coverage detected