Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add id attribute in node #42

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ members = [

[workspace.dependencies]
log = "0.4.20"
uuid = { version = "1.7.0", features = ["v4"] }
11 changes: 11 additions & 0 deletions bin/tests/scenarios/imports_are_merged_correctly/base.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
package de.fosd.jdime.merge;

import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import de.fosd.jdime.operations.ConflictOperation;
import de.fosd.jdime.operations.DeleteOperation;
import de.fosd.jdime.operations.MergeOperation;

import static de.fosd.jdime.artifact.Artifacts.root;
import static de.fosd.jdime.strdump.DumpMode.PLAINTEXT_TREE;
13 changes: 11 additions & 2 deletions bin/tests/scenarios/imports_are_merged_correctly/left.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import java.security.Permission;
import java.util.Arrays;
package de.fosd.jdime.merge;

import java.util.List;
import java.util.Objects;

import de.fosd.jdime.operations.AddOperation;
import de.fosd.jdime.operations.ConflictOperation;
import de.fosd.jdime.operations.MergeOperation;

import static de.fosd.jdime.artifact.Artifacts.root;
import static de.fosd.jdime.strdump.DumpMode.PLAINTEXT_TREE;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import java . security . Permission ; import java . util . Arrays ; import java . util . logging . Array ;
package de . fosd . jdime . merge ; import java . util . List ; import de . fosd . jdime . operations . AddOperation ; import de . fosd . jdime . operations . ConflictOperation ; import de . fosd . jdime . operations . MergeOperation ; import static de . fosd . jdime . artifact . Artifacts . root ; import static de . fosd . jdime . strdump . DumpMode . PLAINTEXT_TREE ;
12 changes: 10 additions & 2 deletions bin/tests/scenarios/imports_are_merged_correctly/right.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import java.security.Permission;
package de.fosd.jdime.merge;

import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Array;

import de.fosd.jdime.operations.AddOperation;
import de.fosd.jdime.operations.ConflictOperation;
import de.fosd.jdime.operations.MergeOperation;

import static de.fosd.jdime.artifact.Artifacts.root;
import static de.fosd.jdime.strdump.DumpMode.PLAINTEXT_TREE;
3 changes: 3 additions & 0 deletions matching/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ model = { path = "../model" }
matching_handlers = { path = "../matching_handlers" }
unordered-pair = "0.2.4"
log = { workspace = true }

[dev-dependencies]
uuid = { workspace = true }
12 changes: 10 additions & 2 deletions matching/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub fn calculate_matchings<'a>(
..
}),
) => {
let is_perfetch_match = kind_left == kind_right && value_left == value_right;
let is_perfect_match = kind_left == kind_right && value_left == value_right;
Matchings::from_single(
UnorderedPair(left, right),
MatchingEntry::new(is_perfetch_match.into(), is_perfetch_match),
MatchingEntry::new(is_perfect_match.into(), is_perfect_match),
)
}
(_, _) => Matchings::from_single(UnorderedPair(left, right), MatchingEntry::new(0, false)),
Expand All @@ -61,13 +61,15 @@ mod tests {
#[test]
fn two_terminal_nodes_matches_with_a_score_of_one_if_they_have_the_same_kind_and_value() {
let left = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value",
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 5 },
is_block_end_delimiter: false,
});
let right = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value",
start_position: Point { row: 0, column: 0 },
Expand All @@ -87,13 +89,15 @@ mod tests {
#[test]
fn two_terminal_nodes_have_a_match_with_score_zero_if_they_have_different_value() {
let left = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value_a",
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 7 },
is_block_end_delimiter: false,
});
let right = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value_b",
start_position: Point { row: 0, column: 0 },
Expand All @@ -113,13 +117,15 @@ mod tests {
#[test]
fn two_terminal_nodes_have_a_match_with_score_zero_if_they_have_different_kind() {
let left = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind_a",
value: "value",
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 5 },
is_block_end_delimiter: false,
});
let right = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind_b",
value: "value",
start_position: Point { row: 0, column: 0 },
Expand All @@ -139,13 +145,15 @@ mod tests {
#[test]
fn two_terminal_nodes_have_a_match_with_score_zero_if_they_have_different_kind_and_value() {
let left = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind_a",
value: "value_a",
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 7 },
is_block_end_delimiter: false,
});
let right = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind_b",
value: "value_a",
start_position: Point { row: 0, column: 0 },
Expand Down
12 changes: 10 additions & 2 deletions matching/src/matchings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ impl<'a> Matchings<'a> {
pub fn find_matching_for(&self, a_node: &'a CSTNode) -> Option<Matching> {
self.matching_entries
.iter()
.find(|(UnorderedPair(left, right), ..)| left == &a_node || right == &a_node)
.find(|(UnorderedPair(left, right), ..)| {
left.id() == a_node.id() || right.id() == a_node.id()
})
.map(|(UnorderedPair(left, right), matching)| {
let matching_node = if left == &a_node { right } else { left };
let matching_node = if left.id() == a_node.id() {
right
} else {
left
};
Matching {
matching_node,
score: matching.score,
Expand Down Expand Up @@ -89,6 +95,7 @@ mod tests {
#[test]
fn returns_none_if_a_matching_for_the_node_is_not_found() {
let a_node = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value",
start_position: Point { row: 0, column: 0 },
Expand All @@ -102,6 +109,7 @@ mod tests {
#[test]
fn returns_some_match_if_a_matching_for_the_node_is_found() {
let a_node = CSTNode::Terminal(Terminal {
id: uuid::Uuid::new_v4(),
kind: "kind",
value: "value",
start_position: Point { row: 0, column: 0 },
Expand Down
Loading
Loading