示例#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)
}
示例#2
0
func TestNotUnreachable(t *testing.T) {
	p := ast.NewTreeNode(ast.NewAnyNameExcept(ast.NewStringName("NotC")), ast.NewTreeNode(ast.NewStringName("C"), ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny())))
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err == nil {
		t.Fatalf("Expected: AnyNameExcept Not Supported Error: Name: !(NotC), but got %v", gkey)
	}
}
示例#3
0
func TestUnreachable(t *testing.T) {
	p := ast.NewTreeNode(ast.NewStringName("NotC"), ast.NewTreeNode(ast.NewStringName("C"), ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny())))
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err == nil {
		t.Fatalf("Expected: Unknown Field Error: Name: NotC, Msg: Debug, but got %v", gkey)
	}
}
示例#4
0
func TestKeyLeaf(t *testing.T) {
	p := ast.NewLeafNode(ast.NewStringVar())
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
}
示例#5
0
func TestKeyAnyName(t *testing.T) {
	p := ast.NewOr(
		ast.NewTreeNode(ast.NewNameChoice(ast.NewAnyName(), ast.NewStringName("C")), ast.NewZAny()),
		ast.NewTreeNode(ast.NewStringName("B"), ast.NewZAny()),
	)
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err == nil {
		t.Fatalf("Expected: Any Field Not Supported: Name: _, but got %v", gkey)
	}
}
示例#6
0
func TestKeyRecursive(t *testing.T) {
	p := ast.NewOr(
		ast.NewTreeNode(ast.NewStringName("C"), ast.NewReference("main")),
		ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
	)
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
}
示例#7
0
func TestKeyField(t *testing.T) {
	p := ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny())
	t.Logf("%v", p)
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
	if gkey.GetTopPattern().GetTreeNode().GetName().GetName().GetUintValue() != 1 {
		t.Fatalf("expected field 1, but got %v", gkey)
	}
}
示例#8
0
func TestRandomDebug(t *testing.T) {
	p := NewProtoNameParser("debug", "Debug", debug.DebugDescription())
	data, err := proto.Marshal(debug.Input)
	if err != nil {
		panic(err)
	}
	for i := 0; i < 10; i++ {
		if err := p.Init(data); err != nil {
			t.Fatal(err)
		}
		//l := debug.NewLogger(p, debug.NewLineLogger())
		debug.RandomWalk(p, debug.NewRand(), 10, 3)
		//t.Logf("original %v vs random %v", debug.Output, m)
	}
}
示例#9
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)
	}
}
示例#10
0
func TestKeyLeftRecursive(t *testing.T) {
	p := ast.NewOr(
		ast.NewReference("a"),
		ast.NewTreeNode(ast.NewStringName("C"), ast.NewReference("main")),
		ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
	)
	g := p.Grammar().AddRef("a", ast.NewReference("main"))
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	if gkey.GetTopPattern().GetOr().GetRightPattern().GetOr().GetLeftPattern().GetTreeNode().GetName().GetName().GetUintValue() != 3 {
		t.Fatalf("expected field 3, but got %v", gkey)
	}
	check(t, gkey)
}
示例#11
0
func TestKeyAnyArrayIndex(t *testing.T) {
	p := ast.NewConcat(
		ast.NewZAny(),
		ast.NewTreeNode(ast.NewStringName("E"),
			ast.NewTreeNode(ast.NewAnyName(),
				ast.NewConcat(
					ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
					ast.NewTreeNode(ast.NewStringName("B"), ast.NewZAny()),
				),
			),
		),
		ast.NewZAny(),
	)
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
}
示例#12
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")
	}
}