diff --git a/merge/src/odered_merge.rs b/merge/src/odered_merge.rs index e6181ce..e8338af 100644 --- a/merge/src/odered_merge.rs +++ b/merge/src/odered_merge.rs @@ -115,6 +115,11 @@ pub fn ordered_merge<'a>( cur_right = children_right_it.next(); } + (None, Some(_), Some(_), 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 { @@ -138,6 +143,11 @@ pub fn ordered_merge<'a>( cur_left = children_left_it.next(); cur_right = children_right_it.next(); } + (None, None, None, Some(_), Some(_)) => { + 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()); @@ -838,77 +848,77 @@ 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, - // ) - // } + #[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, + ) + } }