polyglot-piranha 0.3.31__tar.gz → 0.3.33__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/Cargo.lock +12 -13
  2. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/Cargo.toml +4 -2
  3. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/PKG-INFO +1 -1
  4. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/default_configs.rs +2 -2
  5. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/matches.rs +20 -10
  6. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/rule.rs +12 -10
  7. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/concrete_syntax_test.rs +17 -1
  8. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/rule_test.rs +8 -9
  9. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/LICENSE +0 -0
  10. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/NOTICE +0 -0
  11. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/README.md +0 -0
  12. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/plugins/pyproject.toml +0 -0
  13. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/pyproject.toml +0 -0
  14. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/go/edges.toml +0 -0
  15. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/go/rules.toml +0 -0
  16. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/go/scope_config.toml +0 -0
  17. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java/edges.toml +0 -0
  18. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java/rules.toml +0 -0
  19. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java/scope_config.toml +0 -0
  20. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java_cs/edges.toml +0 -0
  21. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java_cs/rules.toml +0 -0
  22. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/java_cs/scope_config.toml +0 -0
  23. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/kt/edges.toml +0 -0
  24. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/kt/rules.toml +0 -0
  25. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/kt/scope_config.toml +0 -0
  26. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/ruby/edges.toml +0 -0
  27. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/ruby/rules.toml +0 -0
  28. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/ruby/scope_config.toml +0 -0
  29. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/scala/scope_config.toml +0 -0
  30. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/swift/edges.toml +0 -0
  31. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/swift/rules.toml +0 -0
  32. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/cleanup_rules/swift/scope_config.toml +0 -0
  33. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/README.md +0 -0
  34. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/analysis.rs +0 -0
  35. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/mod.rs +0 -0
  36. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/tag_analysis.rs +0 -0
  37. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/unit_tests/tag_analysis_test.rs +0 -0
  38. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/df/utils.rs +0 -0
  39. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/lib.rs +0 -0
  40. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/main.rs +0 -0
  41. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/capture_group_patterns.rs +0 -0
  42. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/concrete_syntax.rs +0 -0
  43. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/edit.rs +0 -0
  44. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/filter.rs +0 -0
  45. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/language.rs +0 -0
  46. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/mod.rs +0 -0
  47. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/outgoing_edges.rs +0 -0
  48. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/piranha_arguments.rs +0 -0
  49. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/piranha_output.rs +0 -0
  50. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/rule_graph.rs +0 -0
  51. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/rule_store.rs +0 -0
  52. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/scopes.rs +0 -0
  53. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/source_code_unit.rs +0 -0
  54. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/piranha_arguments_test.rs +0 -0
  55. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/rule_graph_validation_test.rs +0 -0
  56. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/scopes_test.rs +0 -0
  57. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/source_code_unit_test.rs +0 -0
  58. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/testdata/custom_builtin/edges.toml +0 -0
  59. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/models/unit_tests/testdata/custom_builtin/rules.toml +0 -0
  60. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/mod.rs +0 -0
  61. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_go.rs +0 -0
  62. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_java.rs +0 -0
  63. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_kt.rs +0 -0
  64. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_python.rs +0 -0
  65. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_scala.rs +0 -0
  66. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_scm.rs +0 -0
  67. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_strings.rs +0 -0
  68. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_swift.rs +0 -0
  69. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_thrift.rs +0 -0
  70. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_ts.rs +0 -0
  71. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_tsx.rs +0 -0
  72. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/tests/test_piranha_yaml.rs +0 -0
  73. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/utilities/mod.rs +0 -0
  74. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/utilities/regex_utilities.rs +0 -0
  75. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/utilities/tree_sitter_utilities.rs +0 -0
  76. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/utilities/unit_tests/tree_sitter_utilities_test.rs +0 -0
  77. {polyglot_piranha-0.3.31 → polyglot_piranha-0.3.33}/src/utilities/unit_tests/utilities_test.rs +0 -0
@@ -126,9 +126,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
126
126
 
127
127
  [[package]]
128
128
  name = "clap"
129
- version = "4.5.38"
129
+ version = "4.5.39"
130
130
  source = "registry+https://github.com/rust-lang/crates.io-index"
131
- checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000"
131
+ checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f"
132
132
  dependencies = [
133
133
  "clap_builder",
134
134
  "clap_derive",
@@ -136,9 +136,9 @@ dependencies = [
136
136
 
137
137
  [[package]]
138
138
  name = "clap_builder"
139
- version = "4.5.38"
139
+ version = "4.5.39"
140
140
  source = "registry+https://github.com/rust-lang/crates.io-index"
141
- checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120"
141
+ checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51"
142
142
  dependencies = [
143
143
  "anstream",
144
144
  "anstyle",
@@ -502,9 +502,9 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
502
502
 
503
503
  [[package]]
504
504
  name = "lock_api"
505
- version = "0.4.12"
505
+ version = "0.4.13"
506
506
  source = "registry+https://github.com/rust-lang/crates.io-index"
507
- checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
507
+ checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
508
508
  dependencies = [
509
509
  "autocfg",
510
510
  "scopeguard",
@@ -572,9 +572,9 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
572
572
 
573
573
  [[package]]
574
574
  name = "parking_lot"
575
- version = "0.12.3"
575
+ version = "0.12.4"
576
576
  source = "registry+https://github.com/rust-lang/crates.io-index"
577
- checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
577
+ checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
578
578
  dependencies = [
579
579
  "lock_api",
580
580
  "parking_lot_core",
@@ -582,9 +582,9 @@ dependencies = [
582
582
 
583
583
  [[package]]
584
584
  name = "parking_lot_core"
585
- version = "0.9.10"
585
+ version = "0.9.11"
586
586
  source = "registry+https://github.com/rust-lang/crates.io-index"
587
- checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
587
+ checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
588
588
  dependencies = [
589
589
  "cfg-if",
590
590
  "libc",
@@ -595,7 +595,7 @@ dependencies = [
595
595
 
596
596
  [[package]]
597
597
  name = "piranha"
598
- version = "0.3.31"
598
+ version = "0.3.33"
599
599
  dependencies = [
600
600
  "assert_cmd",
601
601
  "cc",
@@ -1087,8 +1087,7 @@ dependencies = [
1087
1087
  [[package]]
1088
1088
  name = "tree-sitter-kotlin"
1089
1089
  version = "0.3.5"
1090
- source = "registry+https://github.com/rust-lang/crates.io-index"
1091
- checksum = "8df217a0e1fec649f3e13157de932439f3d37ea4e265038dd0873971ef56e726"
1090
+ source = "git+https://github.com/danieltrt/tree-sitter-kotlin?rev=5e0b07cb2ba628842028313b60b97699cc5e0fee#5e0b07cb2ba628842028313b60b97699cc5e0fee"
1092
1091
  dependencies = [
1093
1092
  "cc",
1094
1093
  "tree-sitter",
@@ -2,7 +2,7 @@
2
2
  authors = ["Uber Technologies Inc."]
3
3
  name = "piranha"
4
4
  description = "Polyglot Piranha is a library for performing structural find and replace with deep cleanup."
5
- version = "0.3.31"
5
+ version = "0.3.33"
6
6
  edition = "2021"
7
7
  include = ["pyproject.toml", "src/"]
8
8
  exclude = ["legacy"]
@@ -47,7 +47,9 @@ serde_json = "1.0.82"
47
47
  ctrlc = "3.4"
48
48
 
49
49
  # TODO: Update if we upgrade tree-sitter to >=0.21
50
- tree-sitter-kotlin = "=0.3.5"
50
+ # Kotlin's grammar needs to fix the way it parses unary expressions (currently -a + b gets parsed as - (a +b)).
51
+ # Once we upstream the fix, we can point to the official version.
52
+ tree-sitter-kotlin = { git = "https://github.com/danieltrt/tree-sitter-kotlin", rev = "5e0b07cb2ba628842028313b60b97699cc5e0fee" }
51
53
  tree-sitter-java = "0.20.2"
52
54
  # TODO: Update after: https://github.com/alex-pinkus/tree-sitter-swift/issues/278 resolves
53
55
  tree-sitter-swift = { git = "https://github.com/satyam1749/tree-sitter-swift.git", rev = "08a28993599f1968bc81631a89690503e1db7704" }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyglot_piranha
3
- Version: 0.3.31
3
+ Version: 0.3.33
4
4
  License-File: LICENSE
5
5
  License-File: NOTICE
6
6
  Summary: Polyglot Piranha is a library for performing structural find and replace with deep cleanup.
@@ -192,8 +192,8 @@ pub(crate) fn default_is_seed_rule() -> bool {
192
192
  true
193
193
  }
194
194
 
195
- pub(crate) fn default_delete_comments() -> bool {
196
- true
195
+ pub(crate) fn default_keep_comment_regexes() -> HashSet<String> {
196
+ HashSet::new()
197
197
  }
198
198
 
199
199
  pub(crate) fn default_allow_dirty_ast() -> bool {
@@ -18,6 +18,7 @@ use getset::{Getters, MutGetters};
18
18
  use itertools::Itertools;
19
19
  use log::trace;
20
20
  use pyo3::prelude::{pyclass, pymethods};
21
+ use regex::Regex;
21
22
  use serde_derive::{Deserialize, Serialize};
22
23
  use tree_sitter::Node;
23
24
 
@@ -120,10 +121,10 @@ impl Match {
120
121
  // Populates the leading and trailing comma and comment ranges for the match.
121
122
  fn populate_associated_elements(
122
123
  &mut self, node: &Node, code: &String, piranha_arguments: &PiranhaArguments,
123
- delete_comments: bool,
124
+ compiled_regexes: Vec<Regex>,
124
125
  ) {
125
- self.get_associated_elements(node, code, piranha_arguments, true, delete_comments);
126
- self.get_associated_elements(node, code, piranha_arguments, false, delete_comments);
126
+ self.get_associated_elements(node, code, piranha_arguments, true, &compiled_regexes);
127
+ self.get_associated_elements(node, code, piranha_arguments, false, &compiled_regexes);
127
128
  self.get_associated_leading_empty_lines(node, code);
128
129
  }
129
130
 
@@ -183,7 +184,7 @@ impl Match {
183
184
  /// We currently capture leading and trailing comments and commas.
184
185
  fn get_associated_elements(
185
186
  &mut self, node: &Node, code: &String, piranha_arguments: &PiranhaArguments, trailing: bool,
186
- delete_comments: bool,
187
+ keep_comment_regexes: &[Regex],
187
188
  ) {
188
189
  let mut current_node = *node;
189
190
  let mut buf = *piranha_arguments.cleanup_comments_buffer();
@@ -201,11 +202,14 @@ impl Match {
201
202
  self.associated_comma = Some(sibling.range().into());
202
203
  current_node = sibling;
203
204
  continue; // Continue the inner loop (i.e. evaluate next sibling)
204
- } else if delete_comments
205
- && self._is_comment_safe_to_delete(&sibling, node, piranha_arguments, trailing)
206
- {
207
- // Add the comment to the associated matches
208
- self.associated_comments.push(sibling.range().into());
205
+ } else if self._is_comment_safe_to_delete(&sibling, node, piranha_arguments, trailing) {
206
+ let comment_text = sibling.utf8_text(code.as_bytes()).unwrap();
207
+ if !keep_comment_regexes
208
+ .iter()
209
+ .any(|re| re.is_match(comment_text))
210
+ {
211
+ self.associated_comments.push(sibling.range().into());
212
+ }
209
213
  current_node = sibling;
210
214
  continue; // Continue the inner loop (i.e. evaluate next sibling)
211
215
  }
@@ -494,11 +498,17 @@ impl SourceCodeUnit {
494
498
  p_match.range().end_byte,
495
499
  );
496
500
  if self.is_satisfied(matched_node, rule, p_match.matches(), rule_store) {
501
+ let compiled_regexes: Vec<Regex> = rule
502
+ .rule()
503
+ .keep_comment_regexes()
504
+ .iter()
505
+ .filter_map(|pattern| Regex::new(pattern).ok())
506
+ .collect();
497
507
  p_match.populate_associated_elements(
498
508
  &matched_node,
499
509
  self.code(),
500
510
  self.piranha_arguments(),
501
- *rule.rule().delete_comments(),
511
+ compiled_regexes,
502
512
  );
503
513
  trace!("Found match {:#?}", p_match);
504
514
  output.push(p_match.clone());
@@ -25,8 +25,9 @@ use crate::utilities::Instantiate;
25
25
  use super::{
26
26
  capture_group_patterns::CGPattern,
27
27
  default_configs::{
28
- default_delete_comments, default_filters, default_groups, default_holes, default_is_seed_rule,
29
- default_query, default_replace, default_replace_idx, default_replace_node, default_rule_name,
28
+ default_filters, default_groups, default_holes, default_is_seed_rule,
29
+ default_keep_comment_regexes, default_query, default_replace, default_replace_idx,
30
+ default_replace_node, default_rule_name,
30
31
  },
31
32
  filter::Filter,
32
33
  Validator,
@@ -97,11 +98,11 @@ pub struct Rule {
97
98
  is_seed_rule: bool,
98
99
 
99
100
  /// Marks comments as deletable
100
- #[builder(default = "default_delete_comments()")]
101
- #[serde(default = "default_delete_comments")]
101
+ #[builder(default = "default_keep_comment_regexes()")]
102
+ #[serde(default = "default_keep_comment_regexes")]
102
103
  #[get = "pub"]
103
104
  #[pyo3(get)]
104
- delete_comments: bool,
105
+ keep_comment_regexes: HashSet<String>,
105
106
  }
106
107
 
107
108
  impl Rule {
@@ -148,7 +149,7 @@ macro_rules! piranha_rule {
148
149
  $(, is_seed_rule = $is_seed_rule:expr)?
149
150
  $(, groups = [$($group_name: expr)*])?
150
151
  $(, filters = [$($filter:tt)*])?
151
- $(, delete_comments = $delete_comments:expr)?
152
+ $(, keep_comment_regexes = [$($rgex: expr)*])?
152
153
  ) => {
153
154
  $crate::models::rule::RuleBuilder::default()
154
155
  .name($name.to_string())
@@ -160,7 +161,7 @@ macro_rules! piranha_rule {
160
161
  $(.holes(std::collections::HashSet::from([$($hole.to_string(),)*])))?
161
162
  $(.groups(std::collections::HashSet::from([$($group_name.to_string(),)*])))?
162
163
  $(.filters(std::collections::HashSet::from([$($filter)*])))?
163
- $(.delete_comments($delete_comments))?
164
+ $(.keep_comment_regexes(std::collections::HashSet::from([$($rgex.to_string(),)*])))?
164
165
  .build().unwrap()
165
166
  };
166
167
  }
@@ -171,7 +172,8 @@ impl Rule {
171
172
  fn py_new(
172
173
  name: String, query: Option<String>, replace: Option<String>, replace_idx: Option<u8>,
173
174
  replace_node: Option<String>, holes: Option<HashSet<String>>, groups: Option<HashSet<String>>,
174
- filters: Option<HashSet<Filter>>, is_seed_rule: Option<bool>, delete_comments: Option<bool>,
175
+ filters: Option<HashSet<Filter>>, is_seed_rule: Option<bool>,
176
+ keep_comment_regexes: Option<HashSet<String>>,
175
177
  ) -> Self {
176
178
  let mut rule_builder = RuleBuilder::default();
177
179
 
@@ -208,8 +210,8 @@ impl Rule {
208
210
  rule_builder.is_seed_rule(is_seed_rule);
209
211
  }
210
212
 
211
- if let Some(delete_comments) = delete_comments {
212
- rule_builder.delete_comments(delete_comments);
213
+ if let Some(keep_comment_regexes) = keep_comment_regexes {
214
+ rule_builder.keep_comment_regexes(keep_comment_regexes);
213
215
  }
214
216
 
215
217
  rule_builder.build().unwrap()
@@ -14,7 +14,10 @@
14
14
  use crate::models::capture_group_patterns::ConcreteSyntax;
15
15
  use crate::models::concrete_syntax::get_all_matches_for_concrete_syntax;
16
16
  use crate::models::default_configs::GO;
17
- use crate::models::{default_configs::JAVA, language::PiranhaLanguage};
17
+ use crate::models::{
18
+ default_configs::{JAVA, KOTLIN},
19
+ language::PiranhaLanguage,
20
+ };
18
21
 
19
22
  fn run_test(
20
23
  code: &str, pattern: &str, expected_matches: usize, expected_vars: Vec<Vec<(&str, &str)>>,
@@ -39,6 +42,19 @@ fn run_test(
39
42
  }
40
43
  }
41
44
 
45
+ #[test]
46
+ fn test_single_match_kotlin() {
47
+ run_test(
48
+ "class Something : BaseParameters(namespace = \"data\") {
49
+ val something_else: Boolean by parameter(\"something_else\")
50
+ }",
51
+ "val :[stale_property_name] : Boolean by parameter(\"something_else\")",
52
+ 1,
53
+ vec![vec![("stale_property_name", "something_else")]],
54
+ KOTLIN,
55
+ );
56
+ }
57
+
42
58
  #[test]
43
59
  fn test_single_match() {
44
60
  run_test(
@@ -393,14 +393,17 @@ fn test_rule_delete_comments() {
393
393
  query= "((method_invocation) @m (#eq? @m \"variable.set_value(true)\"))",
394
394
  replace_node = "m",
395
395
  replace = "",
396
- delete_comments = false
396
+ keep_comment_regexes = ["// Given .*"]
397
397
  };
398
398
 
399
399
  let rule = InstantiatedRule::new(&_rule, &HashMap::new());
400
400
  let source_code = "class Test {
401
401
  public void foobar(){
402
- // Given
402
+ // Given something
403
+ // This is an explanatory comment
404
+ // This is another explanatory comment
403
405
  variable.set_value(true);
406
+ other_variable.set_value(false);
404
407
 
405
408
  // When
406
409
  var result = data.Something();
@@ -433,16 +436,12 @@ fn test_rule_delete_comments() {
433
436
  let edit = source_code_unit.get_edit(&rule, &mut rule_store, node, true);
434
437
  assert!(edit.is_some());
435
438
  let edit = edit.unwrap();
436
-
437
439
  // Apply the edit to the source code unit
438
440
  source_code_unit.apply_edit(&edit, &mut parser);
439
441
 
440
- // Inspect the resulting code
441
442
  let edited_code = source_code_unit.code();
442
-
443
- // Now assert on the full edited code
444
- assert!(edited_code.contains("// Given"));
445
- assert!(edited_code.contains("// When"));
446
- assert!(edited_code.contains("// Then"));
443
+ assert!(edited_code.contains("// Given something"));
444
+ assert!(!edited_code.contains("// This is another explanatory comment"));
445
+ assert!(!edited_code.contains("// This is an explanatory comment"));
447
446
  assert!(!edited_code.contains("variable.set_value(true);"));
448
447
  }