Example #1
0
func TestSkipRepeated2(t *testing.T) {
	p := NewProtoNameParser("debug", "Debug", debug.DebugDescription())
	data, err := proto.Marshal(debug.Input)
	if err != nil {
		panic(err)
	}
	if err := p.Init(data); err != nil {
		t.Fatal(err)
	}
	parser := debug.NewLogger(p, debug.NewLineLogger())
	next(t, parser)
	if _, err := parser.String(); err != nil {
		t.Fatal(err)
	}
	next(t, parser)
	if _, err := parser.String(); err != nil {
		t.Fatal(err)
	}
	parser.Down()
	next(t, parser)
	if _, err := parser.Int(); err != nil {
		t.Fatal(err)
	}
	parser.Up()
	next(t, parser)
}
Example #2
0
func testXML(t *testing.T, s string) {
	x := NewXMLParser()
	if err := x.Init([]byte(s)); err != nil {
		panic(err)
	}
	m := debug.Walk(debug.NewLogger(x, debug.NewLineLogger()))
	data, err := json.Marshal(m)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf(string(data))
}
Example #3
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)
	}
}
Example #4
0
func TestDebug(t *testing.T) {
	p := NewProtoNameParser("debug", "Debug", debug.DebugDescription())
	data, err := proto.Marshal(debug.Input)
	if err != nil {
		panic(err)
	}
	if err := p.Init(data); err != nil {
		t.Fatal(err)
	}
	parser := debug.NewLogger(p, debug.NewLineLogger())
	m := debug.Walk(parser)
	if !m.Equal(debug.Output) {
		t.Fatalf("expected %s but got %s", debug.Output, m)
	}
}
Example #5
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
}
Example #6
0
func TestIndexIsNotAString(t *testing.T) {
	p := NewProtoNameParser("debug", "Debug", debug.DebugDescription())
	data, err := proto.Marshal(debug.Input)
	if err != nil {
		panic(err)
	}
	if err := p.Init(data); err != nil {
		t.Fatal(err)
	}
	parser := debug.NewLogger(p, debug.NewLineLogger())
	next(t, parser)
	if _, err := parser.String(); err != nil {
		t.Fatal(err)
	}
	next(t, parser)
	if _, err := parser.String(); err != nil {
		t.Fatal(err)
	}
	parser.Down()
	next(t, parser)
	if _, err := parser.String(); err == nil {
		t.Fatal("expected error, since an index is not a string")
	}
}