예제 #1
0
func testDebug(t *testing.T, test Test) {
	jsonp := json.NewJsonParser()
	p := debug.NewLogger(jsonp, debug.NewLineLogger())
	t.Logf("Schema = %v", string(test.Schema))
	schema, err := ParseSchema(test.Schema)
	if err != nil {
		t.Fatalf("Parser error %v", err)
	}
	t.Logf("Parsed Schema %v", schema.JsonString())
	g, err := TranslateDraft4(schema)
	if err != nil {
		t.Fatalf("Translate error %v", err)
	}
	t.Logf("Translated = %v", g)
	t.Logf("Input = %v", string(test.Data))
	if err := jsonp.Init(test.Data); err != nil {
		t.Fatalf("parser Init error %v", err)
	}
	valid, err := catch(func() bool {
		return interp.Interpret(g, p)
	})
	if err != nil {
		t.Fatalf("Interpret error %v", err)
	} else if valid != test.Valid {
		t.Fatalf("expected %v got %v", test.Valid, valid)
	}
}
예제 #2
0
func test(t *testing.T, g *ast.Grammar, p parser.Interface, expected bool, desc string) {
	if interp.HasRecursion(g) {
		t.Skipf("interp was not designed to handle left recursion")
	}
	p = debug.NewLogger(p, debug.NewLineLogger())
	match, err := interp.Interpret(g, p)
	if err != nil {
		t.Fatal(err)
	}
	if match != expected {
		t.Fatalf("Expected %v on given \n%s\n on \n%s", expected, g.String(), desc)
	}
}
예제 #3
0
파일: relaxng.go 프로젝트: katydid/relaxng
//Validates input xml against a Katydid Relapse Grammar.
func Validate(katydid *ast.Grammar, xmlContent []byte) error {
	p := NewXMLParser()
	if err := p.Init(xmlContent); err != nil {
		return err
	}
	valid, err := interp.Interpret(katydid, p)
	if err != nil {
		return err
	}
	if !valid {
		return errors.New("not valid")
	}
	return nil
}
예제 #4
0
func debugValidate(katydid *ast.Grammar, xmlContent []byte) error {
	fmt.Printf("%v\n", katydid)
	p := NewXMLParser()
	if err := p.Init(xmlContent); err != nil {
		return err
	}
	d := sdebug.NewLogger(p, sdebug.NewLineLogger())
	valid, err := interp.Interpret(katydid, d)
	if err != nil {
		return err
	}
	if !valid {
		return fmt.Errorf("not valid")
	}
	return nil
}
예제 #5
0
func TestDraft4(t *testing.T) {
	tests := buildTests(t)
	t.Logf("skipping files: %d", len(skippingFile))
	t.Logf("total number of tests: %d", len(tests))
	total := 0

	p := json.NewJsonParser()
	for _, test := range tests {
		if skippingFile[test.Filename] {
			//t.Logf("--- SKIP: %v", test)
			continue
		}
		if skippingTest[test.String()] {
			//t.Logf("--- SKIP: %v", test)
			continue
		}
		//t.Logf("--- RUN: %v", test)
		schema, err := ParseSchema(test.Schema)
		if err != nil {
			t.Errorf("--- FAIL: %v: Parse error %v", test, err)
		} else {
			g, err := TranslateDraft4(schema)
			if err != nil {
				t.Errorf("--- FAIL: %v: Translate error %v", test, err)
			} else {
				if err := p.Init(test.Data); err != nil {
					t.Errorf("--- FAIL: %v: parser Init error %v", test, err)
				}
				_ = interp.Interpret
				_ = g
				valid, err := catch(func() bool {
					return interp.Interpret(g, p)
				})
				if err != nil {
					t.Errorf("--- FAIL: %v: Interpret error %v", test, err)
				} else if valid != test.Valid {
					t.Errorf("--- FAIL: %v: expected %v got %v", test, test.Valid, valid)
				} else {
					//t.Logf("--- PASS: %v", test)
					total++
				}
			}
		}
	}
	t.Logf("number of tests passing: %d", total)
}
예제 #6
0
func BenchmarkSuite(b *testing.B) {
	if !testsuite.BenchSuiteExists() {
		b.Skip("benchsuite not available")
	}
	benches, err := testsuite.ReadBenchmarkSuite()
	if err != nil {
		b.Fatal(err)
	}
	for _, benchCase := range benches {
		b.Run(benchCase.Name, func(b *testing.B) {
			num := len(benchCase.Parsers)
			b.ResetTimer()
			for i := 0; i < b.N; i++ {
				if err := benchCase.Parsers[i%num].Reset(); err != nil {
					b.Fatal(err)
				}
				if _, err := interp.Interpret(benchCase.Grammar, benchCase.Parsers[i%num]); err != nil {
					b.Fatal(err)
				}
			}
		})
	}
}