本文整理汇总了Golang中github.com/katydid/katydid/relapse/ast.NewZAny函数的典型用法代码示例。如果您正苦于以下问题:Golang NewZAny函数的具体用法?Golang NewZAny怎么用?Golang NewZAny使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewZAny函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSimplifyTree
func TestSimplifyTree(t *testing.T) {
left := ast.NewTreeNode(ast.NewStringName("A"),
ast.NewTreeNode(ast.NewStringName("B"), ast.NewContains(
ast.NewTreeNode(ast.NewStringName("C"), ast.NewZAny()),
)),
)
right := ast.NewTreeNode(ast.NewStringName("A"),
ast.NewTreeNode(ast.NewStringName("B"), ast.NewContains(
ast.NewTreeNode(ast.NewStringName("D"), ast.NewZAny()),
)),
)
input := ast.NewAnd(left, right)
expected := ast.NewTreeNode(ast.NewStringName("A"),
ast.NewTreeNode(ast.NewStringName("B"), ast.NewAnd(
ast.NewContains(
ast.NewTreeNode(ast.NewStringName("C"), ast.NewZAny()),
),
ast.NewContains(
ast.NewTreeNode(ast.NewStringName("D"), 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)
}
}
示例2: TestSimplify1
func TestSimplify1(t *testing.T) {
c := ast.NewConcat(ast.NewNot(ast.NewZAny()), ast.NewZAny())
s := NewSimplifier(c.Grammar()).Simplify(c)
if !s.Equal(ast.NewNot(ast.NewZAny())) {
t.Fatalf("Expected EmptySet, but got %s", s)
}
}
示例3: TestSimplifyContainsFalseTreeNode
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)
}
}
示例4: TestSimplifyTreeNodeWithNotZanyChild
func TestSimplifyTreeNodeWithNotZanyChild(t *testing.T) {
input := ast.NewTreeNode(ast.NewAnyName(), ast.NewNot(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)
}
}
示例5: TestKeyAnyName
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: TestNotUnreachableArray
func TestNotUnreachableArray(t *testing.T) {
p := ast.NewTreeNode(ast.NewAnyNameExcept(ast.NewStringName("NotC")), ast.NewTreeNode(ast.NewStringName("F"),
ast.NewConcat(ast.NewZAny(), ast.NewTreeNode(ast.NewAnyName(),
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)
}
}
示例7: TestAnyIndex
func TestAnyIndex(t *testing.T) {
p := ast.NewTreeNode(ast.NewStringName("KeyValue"), ast.NewTreeNode(ast.NewAnyName(), ast.NewConcat(
ast.NewTreeNode(ast.NewStringName("Key"), ast.NewZAny()),
ast.NewTreeNode(ast.NewStringName("Value"), ast.NewZAny()),
)))
gkey, err := FieldNamesToNumbers("protonum", "ProtoNum", ProtonumDescription(), p.Grammar())
if err != nil {
t.Fatal(err)
}
t.Logf("%v", gkey)
check(t, gkey)
}
示例8: derivReturn
func derivReturn(refs ast.RefLookup, p *ast.Pattern, patterns []*ast.Pattern) (*ast.Pattern, []*ast.Pattern) {
typ := p.GetValue()
switch v := typ.(type) {
case *ast.Empty:
return ast.NewNot(ast.NewZAny()), patterns
case *ast.ZAny:
return ast.NewZAny(), patterns
case *ast.TreeNode:
if Nullable(refs, patterns[0]) {
return ast.NewEmpty(), patterns[1:]
}
return ast.NewNot(ast.NewZAny()), patterns[1:]
case *ast.LeafNode:
if Nullable(refs, patterns[0]) {
return ast.NewEmpty(), patterns[1:]
}
return ast.NewNot(ast.NewZAny()), patterns[1:]
case *ast.Concat:
l, leftRest := derivReturn(refs, v.GetLeftPattern(), patterns)
leftConcat := ast.NewConcat(l, v.GetRightPattern())
if !Nullable(refs, v.GetLeftPattern()) {
return leftConcat, leftRest
}
r, rightRest := derivReturn(refs, v.GetRightPattern(), leftRest)
return ast.NewOr(leftConcat, r), rightRest
case *ast.Or:
l, leftRest := derivReturn(refs, v.GetLeftPattern(), patterns)
r, rightRest := derivReturn(refs, v.GetRightPattern(), leftRest)
return ast.NewOr(l, r), rightRest
case *ast.And:
l, leftRest := derivReturn(refs, v.GetLeftPattern(), patterns)
r, rightRest := derivReturn(refs, v.GetRightPattern(), leftRest)
return ast.NewAnd(l, r), rightRest
case *ast.Interleave:
l, leftRest := derivReturn(refs, v.GetLeftPattern(), patterns)
r, rightRest := derivReturn(refs, v.GetRightPattern(), leftRest)
return ast.NewOr(ast.NewInterleave(l, v.GetRightPattern()), ast.NewInterleave(r, v.GetLeftPattern())), rightRest
case *ast.ZeroOrMore:
c, rest := derivReturn(refs, v.GetPattern(), patterns)
return ast.NewConcat(c, p), rest
case *ast.Reference:
return derivReturn(refs, refs[v.GetName()], patterns)
case *ast.Not:
c, rest := derivReturn(refs, v.GetPattern(), patterns)
return ast.NewNot(c), rest
case *ast.Contains:
return derivReturn(refs, ast.NewConcat(ast.NewZAny(), ast.NewConcat(v.GetPattern(), ast.NewZAny())), patterns)
case *ast.Optional:
return derivReturn(refs, ast.NewOr(v.GetPattern(), ast.NewEmpty()), patterns)
}
panic(fmt.Sprintf("unknown pattern typ %T", typ))
}
示例9: TestTopsyTurvy
func TestTopsyTurvy(t *testing.T) {
p := ast.NewTreeNode(ast.NewAnyName(), ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()))
gkey, err := FieldNamesToNumbers("protonum", "TopsyTurvy", ProtonumDescription(), p.Grammar())
if err == nil {
t.Fatalf("Expected: Any Field Not Supported: Name: _, but got %v", gkey)
}
}
示例10: simplifyContains
func simplifyContains(p *ast.Pattern) *ast.Pattern {
if isEmpty(p) || isZany(p) {
return ast.NewZAny()
}
if isNotZany(p) {
return p
}
return ast.NewContains(p)
}
示例11: TestSimplifyFalseLeaf
func TestSimplifyFalseLeaf(t *testing.T) {
input := combinator.Value(funcs.And(funcs.StringEq(funcs.StringVar(), funcs.StringConst("a")), funcs.StringEq(funcs.StringVar(), funcs.StringConst("b"))))
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)
}
}
示例12: TestKeyOr
func TestKeyOr(t *testing.T) {
p := ast.NewOr(
ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
ast.NewTreeNode(ast.NewStringName("B"), 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)
if gkey.GetTopPattern().GetOr().GetLeftPattern().GetTreeNode().GetName().GetName().GetUintValue() != 1 {
t.Fatalf("expected field 1, but got %v", gkey)
}
if gkey.GetTopPattern().GetOr().GetRightPattern().GetTreeNode().GetName().GetName().GetUintValue() != 2 {
t.Fatalf("expected field 2, but got %v", gkey)
}
}
示例13: newList
func newList(nameOrPattern *NameOrPattern) *ast.Pattern {
regexStr, nullable, err := listToRegex(nameOrPattern)
if err != nil {
return ast.NewNot(ast.NewZAny())
}
val := combinator.Value(&list{nil, funcs.StringVar(), funcs.StringConst("^" + regexStr + "$")})
if !nullable {
return val
}
return ast.NewOr(val, ast.NewEmpty())
}
示例14: TestKeyAnyArrayIndex
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)
}
示例15: TestRepeatedMessageWithNoFieldsOfTypeMessage
func TestRepeatedMessageWithNoFieldsOfTypeMessage(t *testing.T) {
p := ast.NewConcat(
ast.NewZAny(),
ast.NewTreeNode(ast.NewStringName("KeyValue"),
ast.NewTreeNode(ast.NewAnyName(),
ast.NewConcat(
ast.NewTreeNode(ast.NewStringName("Key"), ast.NewZAny()),
ast.NewTreeNode(ast.NewStringName("Value"), ast.NewZAny()),
),
),
),
ast.NewZAny(),
)
g := p.Grammar()
gkey, err := FieldNamesToNumbers("protonum", "ProtoNum", ProtonumDescription(), g)
if err != nil {
t.Fatal(err)
}
t.Logf("%v", gkey)
check(t, gkey)
}