(t *testing.T)
| 466 | } |
| 467 | |
| 468 | func 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 | |
| 504 | func TestTransform(t *testing.T) { |
| 505 | store := factstore.NewSimpleInMemoryStore() |
nothing calls this directly
no test coverage detected