Skip to content

fix: improve python type matching #425

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
63 changes: 63 additions & 0 deletions crates/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn match_pattern_libs(

let pattern =
src_to_problem_libs(pattern, libs, default_language, None, None, None, None)?.problem;
println!("PATTERN: {:?}", pattern);
let results = pattern.execute_file(&RichFile::new(file.to_owned(), src.to_owned()), context);
let mut execution_result = ExecutionResult {
input_file_debug_text: "".to_string(),
Expand Down Expand Up @@ -2351,6 +2352,68 @@ fn python_easy_sub() {
.unwrap();
}

#[test]
fn tsx_type_context() {
run_test_expected({
TestArgExpected {
pattern: r#"
|engine marzano(0.1)
|language js
|
|`function matchingMethod($_): $type {
| $body
|}` where {
| $type <: `Array` => `Array<string>`
|}"#
.trim_margin()
.unwrap(),
source: r#"
|function matchingMethod(bob): Array {
| console.log("ok")
|}"#
.trim_margin()
.unwrap(),
expected: r#"
|function matchingMethod(bob): Array<string> {
| console.log("ok")
|}"#
.trim_margin()
.unwrap(),
}
})
.unwrap();
}
#[test]
fn python_type_context() {
run_test_expected({
TestArgExpected {
pattern: r#"
|engine marzano(0.1)
|language python
|
|`def matching_method($_) -> $type:
| $body` where {
| $type <: `List` => `List[str]`
|}"#
.trim_margin()
.unwrap(),
source: r#"
|def matching_method(bob) -> List:
| print("ok")
|"#
.trim_margin()
.unwrap(),
expected: r#"
|def matching_method(bob) -> List[str]:
| print("ok")
|"#
.trim_margin()
.unwrap(),
}
})
.unwrap();
}

#[test]
fn predicate_maybe() {
run_test_expected({
Expand Down
1 change: 1 addition & 0 deletions crates/language/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Language for Python {

fn snippet_context_strings(&self) -> &[(&'static str, &'static str)] {
&[
("\ndef GRIT_FUNCTION() ->", "\n pass"),
("", ""),
("{ ", " }"),
("", "\ndef GRIT_FUNCTION():\n return;"),
Expand Down