Skip to content

Commit

Permalink
test: Add a test to assert expected behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 27, 2023
1 parent 79b007a commit ce55988
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions merge/src/odered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ pub fn ordered_merge(
let right_has_matching_in_left =
left_right_matchings.find_matching_for(cur_right.unwrap());

println!(
"{} {} {} {}",
left_has_matching_in_right.is_none(),
has_matching_base_left,
right_has_matching_in_left.is_some(),
has_matching_base_right
);

// The nodes are unchanged
if has_matching_base_left
&& has_matching_base_right
Expand Down Expand Up @@ -882,4 +874,78 @@ mod tests {
},
)
}

#[test]
fn it_merges_when_a_parent_adds_a_node() {
let base = CSTNode::NonTerminal {
kind: "kind".into(),
children: vec![
CSTNode::Terminal {
kind: "kind_a".into(),
value: "value_a".into(),
},
CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
},
],
};

let unchanged_parent = CSTNode::NonTerminal {
kind: "kind".into(),
children: vec![
CSTNode::Terminal {
kind: "kind_a".into(),
value: "value_a".into(),
},
CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
},
],
};

let changed_parent = CSTNode::NonTerminal {
kind: "kind".into(),
children: vec![
CSTNode::Terminal {
kind: "kind_a".into(),
value: "value_a".into(),
},
CSTNode::Terminal {
kind: "kind_b".into(),
value: "value_b".into(),
},
CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
},
],
};

let expected_merge = CSTNode::NonTerminal {
kind: "kind".into(),
children: vec![
CSTNode::Terminal {
kind: "kind_a".into(),
value: "value_a".into(),
},
CSTNode::Terminal {
kind: "kind_b".into(),
value: "value_b".into(),
},
CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
},
],
};

assert_merge_is_correct_and_idempotent_with_respect_to_parent_side(
base,
unchanged_parent,
changed_parent,
expected_merge,
)
}
}

0 comments on commit ce55988

Please sign in to comment.