Skip to content

Commit

Permalink
Use outer group and relative ref to clarify evaluation context
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Jul 8, 2024
1 parent 757bad9 commit 41cf501
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/test/java/org/javarosa/xpath/expr/IndexedRepeatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,34 @@ public void getsIndexedValueInSingleRepeat() throws Exception {
model(
mainInstance(t("data id=\"indexed-repeat\"",
t("index"),
t("repeat",
t("inside")),
t("outer_group", // included to clarify intended evaluation context for index references
t("repeat",
t("inside"))),
t("calc")
)),
bind("/data/calc").calculate("indexed-repeat(/data/repeat/inside, /data/repeat, /data/index)")
bind("/data/calc").calculate("indexed-repeat(/data/outer_group/repeat/inside, /data/outer_group/repeat, ../index)")
)
),
body(
input("/data/index"),
repeat("/data/repeat",
input("/data/repeat/inside"))
repeat("/data/outer_group/repeat",
input("/data/outer_group/repeat/inside"))
))
);

scenario.createNewRepeat("/data/repeat");
scenario.answer("/data/repeat[1]/inside", "index1");
scenario.createNewRepeat("/data/outer_group[1]/repeat");
scenario.answer("/data/outer_group/repeat[1]/inside", "index1");

scenario.createNewRepeat("/data/repeat");
scenario.answer("/data/repeat[2]/inside", "index2");
scenario.createNewRepeat("/data/outer_group[1]/repeat");
scenario.answer("/data/outer_group/repeat[2]/inside", "index2");

scenario.createNewRepeat("/data/repeat");
scenario.answer("/data/repeat[3]/inside", "index3");
scenario.createNewRepeat("/data/outer_group[1]/repeat");
scenario.answer("/data/outer_group/repeat[3]/inside", "index3");

scenario.answer("/data/index", "2");
scenario.answer("/data/outer_group/index", "2");
assertThat(scenario.answerOf("/data/calc"), is(stringAnswer("index2")));

scenario.answer("/data/index", "1");
scenario.answer("/data/outer_group/index", "1");
assertThat(scenario.answerOf("/data/calc"), is(stringAnswer("index1")));
}

Expand Down

0 comments on commit 41cf501

Please sign in to comment.