Skip to content

Commit

Permalink
feat: Add a fabricated scenario in main to test the tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 28, 2023
1 parent a65591e commit 0258bc4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
26 changes: 19 additions & 7 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
fn main() {
let base = r#"
public static interface HelloWorld {
void sayHello(String name);
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
int y = 4;
int j = 0;
}
}
"#;
let left = r#"
public static interface HelloWorld {
void sayHello(String name);
public class Main {
public static void main(String[] args) {
int x = 0;
System.out.println("Hello, João!");
int y = 3;
int j = 0;
}
}
"#;
let right = r#"
public static interface HelloWorld {
void sayHello(String name);
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Paulo!");
int y = 3;
}
}
"#;

Expand All @@ -34,5 +46,5 @@ fn main() {
&matchings_left_right,
);

println!("{:#?}", result)
println!("{}", result.to_string())
}
10 changes: 7 additions & 3 deletions merge/src/odered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ pub fn ordered_merge<'a>(
let matching_base_left = base_left_matchings.find_matching_for(cur_left.unwrap());
let matching_base_right =
base_right_matchings.find_matching_for(cur_right.unwrap());
let bidirectional_matching_left_right =
left_right_matchings.get_matching_entry(cur_left.unwrap(), cur_right.unwrap());
let left_matching_in_right =
left_right_matchings.find_matching_for(cur_left.unwrap());
let right_matching_in_left =
left_right_matchings.find_matching_for(cur_right.unwrap());
let bidirectional_matching_left_right = if (left_matching_in_right.is_some() && right_matching_in_left.is_some()) { Some(true) } else { None};

Check warning on line 70 in merge/src/odered_merge.rs

View workflow job for this annotation

GitHub Actions / build

unnecessary parentheses around `if` condition

Check warning on line 70 in merge/src/odered_merge.rs

View workflow job for this annotation

GitHub Actions / test

unnecessary parentheses around `if` condition

Check warning on line 70 in merge/src/odered_merge.rs

View workflow job for this annotation

GitHub Actions / test

unnecessary parentheses around `if` condition

match (
bidirectional_matching_left_right,
Expand Down Expand Up @@ -214,7 +213,12 @@ pub fn ordered_merge<'a>(
cur_left = children_left_it.next();
cur_right = children_right_it.next();
}
(_, _, _, _, _) => panic!("[INVARIANT BROKEN]: Ordered merge found a matching configuration that should not be achieved")
(a, b, c, d, e) => {
panic!(
"[INVARIANT BROKEN]: Ordered merge found a matching configuration that should not be achieved, {} {} {} {} {}",
a.is_some(), b.is_some(), c.is_some(), d.is_some(), e.is_some()
)
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion model/src/cst_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ impl ToString for CSTNode<'_> {
result
})
}
CSTNode::Conflict { .. } => "Conflict found".into(),
CSTNode::Conflict { left, right } => {
match (left, right) {
(Some(left), Some(right)) => format!("<<<<<<<<< {} ========= {} >>>>>>>>>", left.to_string(), right.to_string()).to_string(),
(Some(left), None) => format!("<<<<<<<<< ========= {} >>>>>>>>>", left.to_string()).to_string(),
(None, Some(right)) => format!("<<<<<<<<< ========= {} >>>>>>>>>", right.to_string()).to_string(),
(None, None) => panic!("Invalid conflict provided")
}
},
}
}
}

0 comments on commit 0258bc4

Please sign in to comment.