Skip to content

Commit

Permalink
feat: Handle case in which each parent adds a non-conflicting node
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 27, 2023
1 parent e05dc21 commit 57e454c
Showing 1 changed file with 83 additions and 73 deletions.
156 changes: 83 additions & 73 deletions merge/src/odered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());

Expand Down Expand Up @@ -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,
)
}
}

0 comments on commit 57e454c

Please sign in to comment.