-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from moonbitlang/fuzzy-matching
feat: support fuzzy matching for moon test --package
- Loading branch information
Showing
24 changed files
with
266 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
.mooncakes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# username/hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "username/hello", | ||
"version": "0.1.0", | ||
"readme": "README.md", | ||
"repository": "", | ||
"license": "", | ||
"keywords": [], | ||
"description": "", | ||
"source": "src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
$ moon test -p username/hello/x --sort-input --no-parallelize | ||
x blackbox test | ||
x inline test | ||
x whitebox test | ||
Total tests: 3, passed: 3, failed: 0. | ||
|
||
$ moon test -p x --sort-input --no-parallelize | ||
x blackbox test | ||
x inline test | ||
x whitebox test | ||
x_y blackbox test | ||
x_y inline test | ||
x_y whitebox test | ||
Total tests: 6, passed: 6, failed: 0. | ||
|
||
$ moon test -p x/y --sort-input --no-parallelize | ||
x_y blackbox test | ||
x_y inline test | ||
x_y whitebox test | ||
Total tests: 3, passed: 3, failed: 0. | ||
|
||
$ moon test -p u/h/x/y --sort-input --no-parallelize | ||
x_y blackbox test | ||
x_y inline test | ||
x_y whitebox test | ||
Total tests: 3, passed: 3, failed: 0. | ||
|
||
$ moon test -p y --sort-input --no-parallelize | ||
x_y blackbox test | ||
x_y inline test | ||
x_y whitebox test | ||
y blackbox test | ||
y inline test | ||
y whitebox test | ||
Total tests: 6, passed: 6, failed: 0. | ||
|
||
$ moon test -p asdf --sort-input --no-parallelize | ||
|
||
Warning: no test entry found | ||
|
||
$ moon test -p y -f asdf --sort-input --no-parallelize | ||
Total tests: 0, passed: 0, failed: 0. | ||
|
||
Warning: cannot find file `asdf` in package `username/hello/x/y`, `username/hello/y`, --file only support exact matching | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x inline test") | ||
} |
1 change: 1 addition & 0 deletions
1
crates/moon/tests/test_cases/fuzzy_matching/src/x/moon.pkg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x blackbox test") | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/fuzzy_matching/src/x/x_wbtest.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x whitebox test") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x_y inline test") | ||
} |
1 change: 1 addition & 0 deletions
1
crates/moon/tests/test_cases/fuzzy_matching/src/x/y/moon.pkg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/fuzzy_matching/src/x/y/x_y_test.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x_y blackbox test") | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/fuzzy_matching/src/x/y/x_y_wbtest.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("x_y whitebox test") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("y inline test") | ||
} |
1 change: 1 addition & 0 deletions
1
crates/moon/tests/test_cases/fuzzy_matching/src/y/moon.pkg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("y blackbox test") | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/fuzzy_matching/src/y/y_wbtest.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
println("y whitebox test") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// moon: The build system and package manager for MoonBit. | ||
// Copyright (C) 2024 International Digital Economy Academy | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
pub fn fuzzy_match<T: AsRef<str>>( | ||
needle: T, | ||
haystack: impl IntoIterator<Item = T>, | ||
) -> Option<Vec<String>> { | ||
let mut matcher = nucleo_matcher::Matcher::new(nucleo_matcher::Config::DEFAULT.match_paths()); | ||
let matches = nucleo_matcher::pattern::Pattern::parse( | ||
needle.as_ref(), | ||
nucleo_matcher::pattern::CaseMatching::Ignore, | ||
nucleo_matcher::pattern::Normalization::Smart, | ||
) | ||
.match_list(haystack, &mut matcher); | ||
if matches.is_empty() { | ||
None | ||
} else { | ||
Some( | ||
matches | ||
.into_iter() | ||
.map(|m| m.0.as_ref().to_string()) | ||
.collect(), | ||
) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_fuzzy() { | ||
let haystack = [ | ||
"moonbitlang/core/builtin", | ||
"moonbitlang/core/int", | ||
"moonbitlang/core/list", | ||
"moonbitlang/core/list/internal", | ||
"moonbitlang/core/hashmap", | ||
]; | ||
let result = fuzzy_match("mci", haystack); | ||
expect_test::expect![[r#" | ||
Some( | ||
[ | ||
"moonbitlang/core/int", | ||
"moonbitlang/core/list/internal", | ||
"moonbitlang/core/list", | ||
"moonbitlang/core/builtin", | ||
], | ||
) | ||
"#]] | ||
.assert_debug_eq(&result); | ||
|
||
let result = fuzzy_match("moonbitlang/core/list", haystack); | ||
expect_test::expect![[r#" | ||
Some( | ||
[ | ||
"moonbitlang/core/list", | ||
"moonbitlang/core/list/internal", | ||
], | ||
) | ||
"#]] | ||
.assert_debug_eq(&result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters