v
v copied to clipboard
Decision tables support
trafficstars
There are some situations like the following
- table-based testing
- decision tables (https://en.wikipedia.org/wiki/Decision_table)
where it'd be desirable for us to setup a MxN table for processing. Here is an example from go
func TestParseExpression(t *testing.T) {
testData := []struct {
name string
input string
expected string
}{
{"base", `results`, `results`},
{"nested", `results.name`, `results|name`},
{"padding", `.results.name`, `results|name`},
{"filter", `results[gender=female]`, `results[gender=female]`},
{"nestedfilter", `..results[name.title=Miss]`, `results[name.title=Miss]`},
}
for _, testcase := range testData {
output, _ := parseExpression(testcase.input)
expectedTokens := strings.Split(testcase.expected, "|")
if !reflect.DeepEqual(expectedTokens, output) {
t.Errorf("%s --> failed", testcase.name)
}
}
}
It'd be nice if v can allow for this to allow building the decision tables inside a fn
The idea comes from OOP concepts where an entire behavior (equivalent to a class) can be encapsulated inside a fn
That's obviously Go code - can you provide a link to the full source?
sure thing - https://github.com/prashanth-hegde/jpath/blob/main/parser/expr_test.go