Skip to content

Commit 5adada1

Browse files
committed
chore(v2-matching-engine): Only compare text nodes if there is no type matcher for an XML element
1 parent d6966d9 commit 5adada1

1 file changed

Lines changed: 23 additions & 36 deletions

File tree

  • rust/pact_matching/src/engine/bodies

rust/pact_matching/src/engine/bodies/xml.rs

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,29 @@ impl XMLPlanBuilder {
164164
let no_markers = remove_marker(&p);
165165
let no_indices = drop_indices(&no_markers);
166166
let matchers = context.select_best_matcher_from(&no_markers, &no_indices)
167-
.filter(|matcher| !matcher.is_type_matcher())
168167
.remove_duplicates();
169-
if !matchers.is_empty() {
170-
node.add(ExecutionPlanNode::annotation(format!("{} {}", p.last_field().unwrap_or_default(),
171-
matchers.generate_description(false))));
172-
let mut current_value = ExecutionPlanNode::action("to-string");
173-
current_value.add(ExecutionPlanNode::resolve_current_value(&p));
174-
node.add(build_matching_rule_node(&ExecutionPlanNode::value_node(text_nodes.join("")),
175-
&current_value, &matchers, false));
176-
} else {
177-
if text_nodes.is_empty() {
178-
node.add(ExecutionPlanNode::action("expect:empty")
179-
.add(ExecutionPlanNode::action("to-string")
180-
.add(ExecutionPlanNode::resolve_current_value(&p))));
168+
if !matchers.type_matcher_defined() {
169+
if !matchers.is_empty() {
170+
node.add(ExecutionPlanNode::annotation(format!("{} {}", p.last_field().unwrap_or_default(),
171+
matchers.generate_description(false))));
172+
let mut current_value = ExecutionPlanNode::action("to-string");
173+
current_value.add(ExecutionPlanNode::resolve_current_value(&p));
174+
node.add(build_matching_rule_node(&ExecutionPlanNode::value_node(text_nodes.join("")),
175+
&current_value, &matchers, false));
181176
} else {
182-
let mut match_node = ExecutionPlanNode::action("match:equality");
183-
match_node
184-
.add(ExecutionPlanNode::value_node(NodeValue::STRING(text_nodes.join(""))))
185-
.add(ExecutionPlanNode::action("to-string")
186-
.add(ExecutionPlanNode::resolve_current_value(&p)))
187-
.add(ExecutionPlanNode::value_node(NodeValue::NULL));
188-
node.add(match_node);
177+
if text_nodes.is_empty() {
178+
node.add(ExecutionPlanNode::action("expect:empty")
179+
.add(ExecutionPlanNode::action("to-string")
180+
.add(ExecutionPlanNode::resolve_current_value(&p))));
181+
} else {
182+
let mut match_node = ExecutionPlanNode::action("match:equality");
183+
match_node
184+
.add(ExecutionPlanNode::value_node(NodeValue::STRING(text_nodes.join(""))))
185+
.add(ExecutionPlanNode::action("to-string")
186+
.add(ExecutionPlanNode::resolve_current_value(&p)))
187+
.add(ExecutionPlanNode::value_node(NodeValue::NULL));
188+
node.add(match_node);
189+
}
189190
}
190191
}
191192
}
@@ -837,13 +838,7 @@ mod tests {
837838
~>$.values
838839
),
839840
:$.values (
840-
:#text (
841-
%expect:empty (
842-
%to-string (
843-
~>$.values['#text']
844-
)
845-
)
846-
),
841+
:#text (),
847842
%expect:only-entries (
848843
['value'],
849844
~>$.values
@@ -862,15 +857,7 @@ mod tests {
862857
~>$.values['value*']
863858
),
864859
:$.values['value*'] (
865-
:#text (
866-
%match:equality (
867-
'100',
868-
%to-string (
869-
~>$.values['value*']['#text']
870-
),
871-
NULL
872-
)
873-
),
860+
:#text (),
874861
%expect:empty (
875862
~>$.values['value*']
876863
)

0 commit comments

Comments
 (0)