Skip to content

Commit

Permalink
Merge pull request #1 from urbit-pilled/add_tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
urbit-pilled authored Mar 28, 2024
2 parents 8c77c49 + cbf8081 commit 16f4d8a
Show file tree
Hide file tree
Showing 11 changed files with 91,364 additions and 87,393 deletions.
9 changes: 9 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 crates/core/src/pattern/code_snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ fn process_snippet_content(
if lang.exact_variable_regex().is_match(source.trim()) {
match source.trim() {
"$_" => return Ok(Pattern::Underscore),
"^_" => return Ok(Pattern::Underscore),
name => {
let var = register_variable(
name,
Expand Down
128 changes: 127 additions & 1 deletion crates/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12823,7 +12823,7 @@ fn php_simple_match() {
pattern: r#"
|language php
|
|`echo ^match;` => `^match + ^match;`
|`echo ^x;` => `^x + ^x;`
|"#
.trim_margin()
.unwrap(),
Expand Down Expand Up @@ -12885,6 +12885,132 @@ fn php_quote_snippet_rewrite() {
.unwrap();
}

#[test]
fn php_if_statement() {
run_test_expected(
TestArgExpected {
pattern: r#"
|language php
|
|`$a = 12;` => `$b=24;`
|"#
.trim_margin()
.unwrap(),
source: r#"
|#
|if (!$foo = $bar) {
| $a = 12;
|}
|"#
.trim_margin().
unwrap(),
expected: r#"
|#
|if (!$foo = $bar) {
| $b=24;
|}
|"#
.trim_margin()
.unwrap(),
}
)
.unwrap();
}

#[test]
fn php_delete_include() {
run_test_expected(
TestArgExpected {
pattern: r#"
|language php
|
|`include ^package;` => .
|"#
.trim_margin()
.unwrap(),
source: r#"
|include 'test.php';
|$test = "";
|"#
.trim_margin().
unwrap(),
expected: r#"
|
|$test = "";
|"#
.trim_margin()
.unwrap(),
}
)
.unwrap();
}

#[test]
fn php_function_modifier() {
run_test_expected(
TestArgExpected {
pattern: r#"
|language php
|
|`class ^_ { ^mod function ^name(){ ^_ } }` where {
| ^mod => `private`,
| ^name => `modified`,
|}
|"#
.trim_margin()
.unwrap(),
source: r#"
|class Log {
| public function printHello()
| {
| echo $this->public;
| echo $this->protected;
| echo $this->private;
| }
|}
|"#
.trim_margin().
unwrap(),
expected: r#"
|class Log {
| private function modified()
| {
| echo $this->public;
| echo $this->protected;
| echo $this->private;
| }
|}
|"#
.trim_margin()
.unwrap(),
}
)
.unwrap();
}

#[test]
fn php_rewrite_arrow_function() {
run_test_expected(
TestArgExpected {
pattern: r#"
|language php
|
|`fn(^a) => ^_` => `fn(^a) => $x * $x`
|"#
.trim_margin()
.unwrap(),
source: "$fn1 = fn($x) => $x + $y;"
.trim_margin().
unwrap(),
expected: "$fn1 = fn($x) => $x * $x;"
.trim_margin()
.unwrap(),
}
)
.unwrap();
}


#[test]
fn css_property_value() {
run_test_match(TestArg {
Expand Down
3 changes: 3 additions & 0 deletions crates/language/src/php.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ impl Language for Php {
&[
("", ""),
("", ";"),
("$", ";"),
("class GRIT_CLASS {", "}"),
("class GRIT_CLASS { ", " function GRIT_FN(); }"),
]
}

Expand Down
Binary file modified crates/wasm-bindings/wasm_parsers/tree-sitter-php_only.wasm
Binary file not shown.
Loading

0 comments on commit 16f4d8a

Please sign in to comment.