Skip to content

Commit

Permalink
feat(merge): Cover case in which we're adding in a parent
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 28, 2023
1 parent 3850869 commit cf8520a
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions merge/src/odered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ pub fn ordered_merge<'a>(
}
cur_right = children_right_it.next();
}
(None, Some(_), None, None, None) => {}
(None, Some(_), None, None, None) => {
result_children.push(cur_right.unwrap().to_owned());
cur_right = children_right_it.next();
}
(None, None, Some(matching_base_left), Some(_), Some(_)) => {
if !matching_base_left.is_perfect_match {
result_children.push(CSTNode::Conflict {
Expand Down Expand Up @@ -162,7 +165,10 @@ pub fn ordered_merge<'a>(

cur_left = children_left_it.next();
}
(None, None, None, Some(_), None) => {}
(None, None, None, Some(_), None) => {
result_children.push(cur_left.unwrap().to_owned());
cur_left = children_left_it.next();
}
(None, None, None, None, Some(matching_base_right)) => {
result_children.push(cur_left.unwrap().to_owned());

Expand Down Expand Up @@ -1074,4 +1080,55 @@ mod tests {
},
);
}

#[test]
fn it_merges_when_a_parent_adds_one_node() {
let base = CSTNode::NonTerminal {
kind: "kind",
children: vec![],
};

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

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

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

assert_merge_is_correct_and_idempotent_with_respect_to_parent_side(
base,
parent_a,
parent_b,
expected_merge,
)
}
}

0 comments on commit cf8520a

Please sign in to comment.