-
-
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 node magic method
part of #389
- Loading branch information
1 parent
79c663a
commit d6eb7b0
Showing
2 changed files
with
62 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from ast_grep_pyo3 import SgNode, SgRoot | ||
|
||
source = """ | ||
function test() { | ||
let a = 123 | ||
let b = 456 | ||
let c = 789 | ||
} | ||
""".strip() | ||
sg = SgRoot(source, "javascript") | ||
root = sg.root() | ||
|
||
def test_get_root(): | ||
node = root.find(pattern="let a = $A") | ||
assert node is not None | ||
root2 = node.get_root() | ||
assert root2.filename() == "anonymous" | ||
# assert root2 == root | ||
|
||
|
||
def test_find_all(): | ||
nodes = root.find_all(pattern="let $N = $V") | ||
assert len(nodes) == 3 | ||
|
||
def assert_name(node: SgNode, text: str): | ||
n = node.get_match("N") | ||
assert n is not None | ||
assert n.text() == text | ||
|
||
assert_name(nodes[0], "a") | ||
assert_name(nodes[1], "b") | ||
assert_name(nodes[2], "c") | ||
|
||
def test_field(): pass | ||
def test_parent(): pass | ||
def test_child(): pass | ||
def test_ancestors(): pass | ||
def test_next(): pass | ||
def test_next_all(): pass | ||
def test_prev(): pass | ||
def test_prev_all(): pass |