Skip to content

Commit

Permalink
Merge pull request #1169 from nyaruka/fix-has-ward
Browse files Browse the repository at this point in the history
Fix has_ward ordering
  • Loading branch information
rowanseymour authored Jul 10, 2023
2 parents afbc5ca + 2366a8a commit 2226f19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions flows/routers/cases/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@ func HasDistrict(env envs.Environment, args ...types.XValue) types.XValue {

// HasWard tests whether a ward name is contained in the `text`
//
// @(has_ward("Gisozi", "Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo > Gisozi
// @(has_ward("I live in Gisozi", "Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo > Gisozi
// @(has_ward("Gisozi", "Gasabo", "Brooklyn")) -> false
// @(has_ward("Gisozi", "Brooklyn", "Kigali")) -> false
// @(has_ward("Brooklyn", "Gasabo", "Kigali")) -> false
// @(has_ward("Gisozi", "Kigali", "Gasabo").match) -> Rwanda > Kigali City > Gasabo > Gisozi
// @(has_ward("I live in Gisozi", "Kigali", "Gasabo").match) -> Rwanda > Kigali City > Gasabo > Gisozi
// @(has_ward("Gisozi", "Brooklyn" , "Gasabo")) -> false
// @(has_ward("Gisozi", "Kigali", "Brooklyn")) -> false
// @(has_ward("Brooklyn", "Kigali", "Gasabo")) -> false
// @(has_ward("Gasabo")) -> false
// @(has_ward("Gisozi").match) -> Rwanda > Kigali City > Gasabo > Gisozi
//
Expand All @@ -691,10 +691,11 @@ func HasWard(env envs.Environment, args ...types.XValue) types.XValue {
return xerr
}
if len(args) == 3 {
if districtText, xerr = types.ToXText(env, args[1]); xerr != nil {
if stateText, xerr = types.ToXText(env, args[1]); xerr != nil {
return xerr
}
if stateText, xerr = types.ToXText(env, args[2]); xerr != nil {

if districtText, xerr = types.ToXText(env, args[2]); xerr != nil {
return xerr
}
}
Expand Down
6 changes: 3 additions & 3 deletions flows/routers/cases/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ var testTests = []struct {
{"has_district", []types.XValue{xs("xyz"), xs("kigali")}, falseResult},
{"has_district", []types.XValue{ERROR}, ERROR},

{"has_ward", []types.XValue{xs("Gisozi"), xs("Gasabo"), xs("kigali")}, result(xs("Rwanda > Kigali City > Gasabo > Gisozi"))},
{"has_ward", []types.XValue{xs("I live in gisozi"), xs("Gasabo"), xs("kigali")}, result(xs("Rwanda > Kigali City > Gasabo > Gisozi"))},
{"has_ward", []types.XValue{xs("Gisozi"), xs("kigali"), xs("Gasabo")}, result(xs("Rwanda > Kigali City > Gasabo > Gisozi"))},
{"has_ward", []types.XValue{xs("I live in gisozi"), xs("kigali"), xs("Gasabo")}, result(xs("Rwanda > Kigali City > Gasabo > Gisozi"))},
{"has_ward", []types.XValue{xs("Gisozi")}, result(xs("Rwanda > Kigali City > Gasabo > Gisozi"))},
{"has_ward", []types.XValue{xs("xyz"), xs("Gasabo"), xs("kigali")}, falseResult},
{"has_ward", []types.XValue{xs("xyz"), xs("kigali"), xs("Gasabo")}, falseResult},
{"has_ward", []types.XValue{ERROR}, ERROR},

{
Expand Down

0 comments on commit 2226f19

Please sign in to comment.