Пример #1
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)
	}
}
Пример #2
0
func TestSimplifyContainsFalseTreeNode(t *testing.T) {
	input := ast.NewContains(ast.NewTreeNode(ast.NewAnyNameExcept(ast.NewAnyName()), ast.NewZAny()))
	expected := ast.NewNot(ast.NewZAny())
	output := NewSimplifier(input.Grammar()).Simplify(input)
	t.Logf("%v", output)
	if !expected.Equal(output) {
		t.Fatalf("expected %v, but got %v", expected, output)
	}
}
Пример #3
0
func exprToName(e *ast.Expr) *ast.NameExpr {
	if e.GetBuiltIn() != nil {
		if e.GetBuiltIn().GetSymbol().String() == "==" {
			if e.GetBuiltIn().GetExpr().GetTerminal() != nil {
				t := e.GetBuiltIn().GetExpr().GetTerminal()
				if t.DoubleValue != nil {
					return ast.NewDoubleName(t.GetDoubleValue())
				}
				if t.IntValue != nil {
					return ast.NewIntName(t.GetIntValue())
				}
				if t.UintValue != nil {
					return ast.NewUintName(t.GetUintValue())
				}
				if t.BoolValue != nil {
					return ast.NewBoolName(t.GetBoolValue())
				}
				if t.StringValue != nil {
					return ast.NewStringName(t.GetStringValue())
				}
				if t.BytesValue != nil {
					return ast.NewBytesName(t.GetBytesValue())
				}
			} else {
				panic("todo")
			}
		} else {
			panic("todo")
		}
	}
	if e.GetFunction() != nil {
		if e.GetFunction().GetName() == "not" {
			return ast.NewAnyNameExcept(exprToName(e.GetFunction().GetParams()[0]))
		}
		if e.GetFunction().GetName() == "or" {
			return ast.NewNameChoice(
				exprToName(e.GetFunction().GetParams()[0]),
				exprToName(e.GetFunction().GetParams()[1]),
			)
		}
		panic("todo")
	}
	if e.GetTerminal() != nil {
		if e.GetTerminal().BoolValue != nil {
			if e.GetTerminal().GetBoolValue() {
				return ast.NewAnyName()
			} else {
				panic("todo")
			}
		} else {
			panic("todo")
		}
	}
	panic("todo")
}