web: Add bindings for remaining field APIs
This commit is contained in:
parent
30e73505e1
commit
82fab90c0b
5 changed files with 81 additions and 5 deletions
|
|
@ -116,6 +116,35 @@ describe("Node", () => {
|
|||
})
|
||||
});
|
||||
|
||||
describe('.childForFieldName()', () => {
|
||||
it('returns null when the node has no children', () => {
|
||||
tree = parser.parse("class A { b() {} }");
|
||||
|
||||
const classNode = tree.rootNode.firstChild;
|
||||
assert.equal(classNode.type, 'class_declaration');
|
||||
|
||||
const classNameNode = classNode.childForFieldName('name');
|
||||
assert.equal(classNameNode.type, 'identifier');
|
||||
assert.equal(classNameNode.text, 'A');
|
||||
|
||||
const bodyNode = classNode.childForFieldName('body');
|
||||
assert.equal(bodyNode.type, 'class_body');
|
||||
assert.equal(bodyNode.text, '{ b() {} }');
|
||||
|
||||
const methodNode = bodyNode.firstNamedChild;
|
||||
assert.equal(methodNode.type, 'method_definition');
|
||||
assert.equal(methodNode.text, 'b() {}');
|
||||
|
||||
const methodNameNode = methodNode.childForFieldName('name');
|
||||
assert.equal(methodNameNode.type, 'property_identifier');
|
||||
assert.equal(methodNameNode.text, 'b');
|
||||
|
||||
const paramsNode = methodNode.childForFieldName('parameters');
|
||||
assert.equal(paramsNode.type, 'formal_parameters');
|
||||
assert.equal(paramsNode.text, '()');
|
||||
});
|
||||
});
|
||||
|
||||
describe(".nextSibling and .previousSibling", () => {
|
||||
it("returns the node's next and previous sibling", () => {
|
||||
tree = parser.parse("x10 + 1000");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue