Example #1
0
func assertConditionGroup(expected bool, data ...interface{}) {
	l := len(data)
	group := &ConditionGroup{
		joins:       make([]LogicalOperator, 0, l/2),
		verifiables: make([]Verifiable, 0, l-l/2),
	}
	for i := 0; i < l; i += 2 {
		group.verifiables = append(group.verifiables, data[i].(Verifiable))
		if i+1 < l {
			group.joins = append(group.joins, data[i+1].(LogicalOperator))
		}
	}

	t.Expect(group.IsTrue(nil)).To.Equal(expected)
}
Example #2
0
func assertCondition(expected bool, left Value, op ComparisonOperator, right Value) {
	data := map[string]interface{}{
		"[]int":         []int{1, 2, 3},
		"[]int2":        []int{2, 3, 1},
		"[]int3":        []int{},
		"[]interface{}": []interface{}{2, "a", true},
		"string":        "astring",
		"now":           time.Now(),
		"yesterday":     time.Now().Add(time.Hour * -24),
		"map[string]int": map[string]int{
			"hello": 44,
		},
	}
	c := &Condition{left, op, right}
	t.Expect(c.IsTrue(&Context{Data: data})).To.Equal(expected)
}
Example #3
0
func assertErrorValue(data string, expected string) {
	p := NewParser([]byte(data))
	value, err := p.ReadValue()
	t.Expect(err.Error()).To.Equal(expected)
	t.Expect(value).To.Equal(nil)
}
Example #4
0
func assertStaticValue(data string, expected interface{}) {
	p := NewParser([]byte(data))
	value, err := p.ReadValue()
	t.Expect(err).To.Equal(nil)
	t.Expect(value.Resolve(nil)).To.Equal(expected)
}