-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for get_match and wrong usages
part of #389
- Loading branch information
1 parent
2ad3463
commit 89aec8d
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
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,40 @@ | ||
from ast_grep_pyo3 import SgRoot | ||
import pytest | ||
|
||
source = """ | ||
function test() { | ||
let a = 123 | ||
let b = 456 | ||
let c = 789 | ||
} | ||
""".strip() | ||
sg = SgRoot(source, "javascript") | ||
root = sg.root() | ||
|
||
def test_wrong_use_pattern_as_dict(): | ||
with pytest.raises(TypeError): | ||
root.find("let $A = 123") | ||
|
||
def test_get_unfound_match(): | ||
node = root.find(pattern="let $A = 123") | ||
with pytest.raises(KeyError): | ||
node["B"] | ||
|
||
# TODO: remove BaseException | ||
def test_wrong_rule_key(): | ||
with pytest.raises(BaseException): | ||
root.find(pat="not") # type: ignore | ||
|
||
def test_no_rule_key(): | ||
with pytest.raises(BaseException): | ||
root.find() | ||
|
||
def test_error_for_invalid_kind(): | ||
with pytest.raises(BaseException): | ||
root.find(kind="nonsense") | ||
|
||
def test_no_error_for_invalid_pattern(): | ||
with pytest.raises(BaseException): | ||
root.find(pattern="$@!!--l3**+no//nsense") | ||
# but not this | ||
assert not root.find(pattern="@test") |