Exemple #1
0
func TestComposeContains(t *testing.T) {
	expr := &ast.Expr{
		Function: &ast.Function{
			Name: "contains",
			Params: []*ast.Expr{
				{
					Function: &ast.Function{
						Name: "nfkc",
						Params: []*ast.Expr{
							{
								Terminal: &ast.Terminal{
									Variable: &ast.Variable{
										Name: "a.a.a",
										Type: types.SINGLE_STRING,
									},
								},
							},
						},
					},
				},
				{
					Function: &ast.Function{
						Name: "nfkc",
						Params: []*ast.Expr{
							{
								Terminal: &ast.Terminal{
									StringValue: proto.String("TheStreet"),
								},
							},
						},
					},
				},
			},
		},
	}
	b, err := NewBool(expr)
	if err != nil {
		panic(err)
	}
	r, err := b.Eval(serialize.NewStringValue("TheStreet"))
	if err != nil {
		panic(err)
	}
	if r != true {
		t.Fatalf("expected true")
	}
	r, err = b.Eval(serialize.NewStringValue("ThatStreet"))
	if err != nil {
		panic(err)
	}
	if r != false {
		t.Fatalf("expected false")
	}
	if strings.Contains(funcs.Sprint(b.Func), "nfkc(`TheStreet`)") {
		t.Fatalf("trimming did not work")
	}
}
Exemple #2
0
func TestComposeStringEq(t *testing.T) {
	expr := &ast.Expr{
		Function: &ast.Function{
			Name: "eq",
			Params: []*ast.Expr{
				{
					Function: &ast.Function{
						Name: "nfkc",
						Params: []*ast.Expr{
							{
								Terminal: &ast.Terminal{
									Variable: &ast.Variable{
										Name: "a.a.a",
										Type: types.SINGLE_STRING,
									},
								},
							},
						},
					},
				},
				{
					Function: &ast.Function{
						Name: "nfkc",
						Params: []*ast.Expr{
							{
								Terminal: &ast.Terminal{
									StringValue: proto.String("TheStreet"),
								},
							},
						},
					},
				},
			},
		},
	}
	b, err := NewBool(expr)
	if err != nil {
		panic(err)
	}
	r, err := b.Eval(serialize.NewStringValue("TheStreet"))
	if err != nil {
		panic(err)
	}
	if r != true {
		t.Fatalf("expected true")
	}
}
Exemple #3
0
func TestNoTrim(t *testing.T) {
	expr := &ast.Expr{
		Function: &ast.Function{
			Name: "eq",
			Params: []*ast.Expr{
				{
					Function: &ast.Function{
						Name: "elem",
						Params: []*ast.Expr{
							{
								List: &ast.List{
									Type: types.LIST_STRING,
									Elems: []*ast.Expr{
										{
											Function: &ast.Function{
												Name: "print",
												Params: []*ast.Expr{
													{
														Terminal: &ast.Terminal{
															Variable: &ast.Variable{
																Name: "a.a.a",
																Type: types.SINGLE_STRING,
															},
														},
													},
												},
											},
										},
									},
								},
							},
							{
								Terminal: &ast.Terminal{
									Int64Value: proto.Int64(0),
								},
							},
						},
					},
				},
				{
					Terminal: &ast.Terminal{
						StringValue: proto.String("abc"),
					},
				},
			},
		},
	}
	b, err := NewBool(expr)
	if err != nil {
		panic(err)
	}
	str := funcs.Sprint(b.Func)
	if str == "false" {
		t.Fatalf("too much trimming")
	}
	t.Logf("trimmed = %s", str)
	r, err := b.Eval(serialize.NewStringValue("abc"))
	if err != nil {
		panic(err)
	}
	if r != true {
		t.Fatalf("expected true")
	}
}