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

Function TestTypeCheck

builtin/builtin_test.go:508–532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

506}
507
508func TestTypeCheck(t *testing.T) {
509 fooDecl, err := ast.NewDecl(
510 ast.NewAtom("foo", ast.Variable{"SomeNum"}, ast.Variable{"SomeStr"}, ast.Variable{"SomeName"}),
511 nil,
512 []ast.BoundDecl{
513 ast.NewBoundDecl(ast.NumberBound, symbols.NewStructType(name("/bar"), symbols.NewListType(ast.StringBound)), ast.NameBound)}, nil)
514 if err != nil {
515 t.Fatal(err)
516 }
517 decls := map[ast.PredicateSym]ast.Decl{
518 ast.PredicateSym{"foo", 3}: fooDecl,
519 }
520 checker, err := NewTypeChecker(decls)
521 if err != nil {
522 t.Fatalf("bad test setup, cannot construct type checker: %v", err)
523 }
524 okFact := evAtom("foo(12, {/bar: ['aaa']}, /bar)")
525 if err := checker.CheckTypeBounds(okFact); err != nil {
526 t.Errorf("CheckTypeBounds(%v) failed %v", okFact, err)
527 }
528 badFact := evAtom("foo('aaa', {/bar: ['b12']}, /bar)")
529 if err := checker.CheckTypeBounds(badFact); err == nil { // if NO error
530 t.Errorf("CheckTypeBounds(%v) succeeded expected error", badFact)
531 }
532}
533
534func TestCheckTypeExpressionStructured(t *testing.T) {
535 tests := []struct {

Callers

nothing calls this directly

Calls 9

CheckTypeBoundsMethod · 0.95
NewDeclFunction · 0.92
NewAtomFunction · 0.92
NewBoundDeclFunction · 0.92
NewStructTypeFunction · 0.92
NewListTypeFunction · 0.92
NewTypeCheckerFunction · 0.85
nameFunction · 0.70
evAtomFunction · 0.70

Tested by

no test coverage detected