Skip to content

Commit a7fc3e1

Browse files
committed
rename API
1 parent d41c950 commit a7fc3e1

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

query/cstyle_simple_forloop_test.mbt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ test "query can emulate cstyle forward simple forloop patterns-not by iterating
1818
#|for $(counter:id) = $(start:exp); $(counter:id) < $(limit:exp); $(counter:id) = $(counter:id) + 1 {
1919
#| $(body:exp)
2020
#|}
21-
let matches = ExprQuery::ExprQuery(pattern).matches_all(
21+
let captures = ExprQuery::ExprQuery(pattern).captures(
2222
source_name="sample.mbt",
2323
source,
2424
)
25-
assert_eq(matches.length(), 3)
26-
let filtered : Array[Map[String, @untyped_ast.Node]] = []
27-
for captures in matches {
28-
if captures.get("counter") is Some(counter_node) &&
25+
assert_eq(captures.length(), 3)
26+
let filtered_capture_maps : Array[Map[String, @untyped_ast.Node]] = []
27+
for capture in captures {
28+
if capture.get("counter") is Some(counter_node) &&
2929
counter_node.kind is Leaf(PString(counter_name)) &&
30-
captures.get("body") is Some(body) {
30+
capture.get("body") is Some(body) {
3131
// unused variable in for loop body
3232
if !body.contains_unshadowed(id=counter_name) {
33-
filtered.push(captures)
33+
filtered_capture_maps.push(capture)
3434
}
3535
}
3636
}
37-
assert_eq(filtered.length(), 2)
37+
assert_eq(filtered_capture_maps.length(), 2)
3838
debug_inspect(
39-
filtered[0].get("counter").unwrap(),
39+
filtered_capture_maps[0].get("counter").unwrap(),
4040
content=(
4141
#|{
4242
#| kind: Leaf(PString("i")),
@@ -49,7 +49,7 @@ test "query can emulate cstyle forward simple forloop patterns-not by iterating
4949
),
5050
)
5151
debug_inspect(
52-
filtered[1].get("counter").unwrap(),
52+
filtered_capture_maps[1].get("counter").unwrap(),
5353
content=(
5454
#|{
5555
#| kind: Leaf(PString("k")),

query/pkg.generated.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
// Types and methods
1313
type ExprQuery
1414
pub fn ExprQuery::ExprQuery(String) -> Self raise
15-
pub fn ExprQuery::matches_all(Self, source_name~ : String, String) -> ArrayView[Map[String, @untyped_ast.Node]] raise
15+
pub fn ExprQuery::captures(Self, source_name~ : String, String) -> ArrayView[Map[String, @untyped_ast.Node]] raise
1616

1717
// Type aliases
1818

query/query.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn ExprQuery::ExprQuery(pattern : String) -> ExprQuery raise {
3535
}
3636

3737
///|
38-
pub fn ExprQuery::matches_all(
38+
pub fn ExprQuery::captures(
3939
self : ExprQuery,
4040
source_name~ : String,
4141
source : String,

query/query_test.mbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test "query matches simple expression and returns empty capture map" {
4242
#| target()
4343
#|}
4444
#|
45-
let matches = query.matches_all(source_name="sample.mbt", source)
45+
let matches = query.captures(source_name="sample.mbt", source)
4646
assert_eq(matches.length(), 1)
4747
assert_eq(matches[0].length(), 0)
4848
}
@@ -56,7 +56,7 @@ test "query captures one repeated expression and rejects non-repeated candidates
5656
#| make() + other()
5757
#|}
5858
#|
59-
let matches = query.matches_all(source_name="sample.mbt", source)
59+
let matches = query.captures(source_name="sample.mbt", source)
6060
assert_eq(matches.length(), 1)
6161
guard matches[0].get("value") is Some(value) else {
6262
fail("expected value capture")
@@ -72,7 +72,7 @@ test "query captures identifiers and constants by metavar name" {
7272
#| sink(@math.abs)
7373
#|}
7474
#|
75-
let id_matches = id_query.matches_all(source_name="sample.mbt", id_source)
75+
let id_matches = id_query.captures(source_name="sample.mbt", id_source)
7676
assert_eq(id_matches.length(), 1)
7777
guard id_matches[0].get("callee") is Some(callee) else {
7878
fail("expected callee capture")
@@ -89,7 +89,7 @@ test "query captures identifiers and constants by metavar name" {
8989
#| sink(42)
9090
#|}
9191
#|
92-
let const_matches = const_query.matches_all(
92+
let const_matches = const_query.captures(
9393
source_name="sample.mbt",
9494
const_source,
9595
)
@@ -118,7 +118,7 @@ test "query prefilter skips irrelevant invalid source" {
118118
#| this is not valid MoonBit
119119
#|}
120120
#|
121-
let matches = query.matches_all(source_name="bad.mbt", source)
121+
let matches = query.captures(source_name="bad.mbt", source)
122122
assert_eq(matches.length(), 0)
123123
}
124124

@@ -130,7 +130,7 @@ test "query raises parse error when relevant source is invalid" {
130130
#| target(
131131
#|}
132132
#|
133-
try query.matches_all(source_name="bad.mbt", source) catch {
133+
try query.captures(source_name="bad.mbt", source) catch {
134134
err => inspect("\{to_repr(err)}".contains("parse"), content="true")
135135
} noraise {
136136
_ => fail("expected parse error")

0 commit comments

Comments
 (0)