Fix small issues with new wasm bindings
This commit is contained in:
parent
f65b499a7c
commit
f462f0d09d
2 changed files with 31 additions and 84 deletions
|
|
@ -652,7 +652,7 @@ class Language {
|
|||
stringToUTF8(type, typeAddress, typeLength + 1);
|
||||
const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named);
|
||||
C._free(typeAddress);
|
||||
return result;
|
||||
return result || null;
|
||||
}
|
||||
|
||||
get nodeTypeCount() {
|
||||
|
|
|
|||
|
|
@ -4,94 +4,41 @@ let JavaScript;
|
|||
describe("Language", () => {
|
||||
before(async () => ({ JavaScript } = await require("./helper")));
|
||||
|
||||
describe(".fieldCount", () => {
|
||||
it("returns a number", () => {
|
||||
assert.equal(34, JavaScript.fieldCount);
|
||||
describe(".fieldIdForName, .fieldNameForId", () => {
|
||||
it("converts between the string and integer representations of fields", () => {
|
||||
const nameId = JavaScript.fieldIdForName("name");
|
||||
const bodyId = JavaScript.fieldIdForName("body");
|
||||
|
||||
assert.isBelow(nameId, JavaScript.fieldCount);
|
||||
assert.isBelow(bodyId, JavaScript.fieldCount);
|
||||
assert.equal("name", JavaScript.fieldNameForId(nameId));
|
||||
assert.equal("body", JavaScript.fieldNameForId(bodyId));
|
||||
});
|
||||
|
||||
it("handles invalid inputs", () => {
|
||||
assert.equal(null, JavaScript.fieldIdForName("namezzz"));
|
||||
assert.equal(null, JavaScript.fieldNameForId(-1));
|
||||
assert.equal(null, JavaScript.fieldNameForId(10000));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".fieldIdForName", () => {
|
||||
it("returns null, if not defined", () => {
|
||||
const fieldName = "nonExistentFieldName";
|
||||
assert.equal(null, JavaScript.fieldIdForName(fieldName));
|
||||
describe(".idForNodeType, .nodeTypeForId, .nodeTypeIsNamed", () => {
|
||||
it("converts between the string and integer representations of a node type", () => {
|
||||
const exportStatementId = JavaScript.idForNodeType("export_statement", true);
|
||||
const starId = JavaScript.idForNodeType("*", false);
|
||||
|
||||
assert.isBelow(exportStatementId, JavaScript.nodeTypeCount);
|
||||
assert.isBelow(starId, JavaScript.nodeTypeCount);
|
||||
assert.equal(true, JavaScript.nodeTypeIsNamed(exportStatementId))
|
||||
assert.equal("export_statement", JavaScript.nodeTypeForId(exportStatementId))
|
||||
assert.equal(false, JavaScript.nodeTypeIsNamed(starId))
|
||||
assert.equal("*", JavaScript.nodeTypeForId(starId))
|
||||
});
|
||||
|
||||
it("returns a number, if defined", () => {
|
||||
const fieldName = "decorator";
|
||||
assert.equal(12, JavaScript.fieldIdForName(fieldName));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".fieldNameForId", () => {
|
||||
it("returns null, if not defined", () => {
|
||||
const fieldId = -1;
|
||||
assert.equal(null, JavaScript.fieldNameForId(fieldId));
|
||||
});
|
||||
|
||||
it("returns a string, if defined", () => {
|
||||
const fieldId = 12;
|
||||
assert.equal("decorator", JavaScript.fieldNameForId(fieldId));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".idForNodeType", () => {
|
||||
it("returns a number", () => {
|
||||
const type = "export_statement";
|
||||
const named = true;
|
||||
assert.equal(125, JavaScript.idForNodeType(type, named));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".nodeTypeCount", () => {
|
||||
it("returns a number", () => {
|
||||
assert.equal(239, JavaScript.nodeTypeCount);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".nodeTypeForId", () => {
|
||||
it("returns null, if not defined", () => {
|
||||
const typeId = -1;
|
||||
assert.equal(null, JavaScript.nodeTypeForId(typeId));
|
||||
});
|
||||
|
||||
it("returns a string, if not defined", () => {
|
||||
const typeId = 125;
|
||||
assert.equal("export_statement", JavaScript.nodeTypeForId(typeId));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".nodeTypeIsNamed", () => {
|
||||
it("returns false, if node type is not named", () => {
|
||||
const typeId = 4;
|
||||
assert.equal("*", JavaScript.nodeTypeForId(typeId));
|
||||
assert.equal(false, JavaScript.nodeTypeIsNamed(typeId));
|
||||
});
|
||||
|
||||
it("returns true, if node type is named", () => {
|
||||
const typeId = 125;
|
||||
assert.equal("export_statement", JavaScript.nodeTypeForId(typeId));
|
||||
assert.equal(true, JavaScript.nodeTypeIsNamed(typeId));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".nodeTypeIsVisible", () => {
|
||||
it("returns false, if node type is not visible", () => {
|
||||
let typeId;
|
||||
typeId = 100;
|
||||
assert.equal(false, JavaScript.nodeTypeIsVisible(typeId));
|
||||
typeId = 102;
|
||||
assert.equal(false, JavaScript.nodeTypeIsVisible(typeId));
|
||||
});
|
||||
|
||||
it("returns true, if node type is visible", () => {
|
||||
const typeId = 101;
|
||||
assert.equal(true, JavaScript.nodeTypeIsVisible(typeId));
|
||||
});
|
||||
});
|
||||
|
||||
describe(".version", () => {
|
||||
it("returns a number", () => {
|
||||
assert.equal(12, JavaScript.version);
|
||||
it("handles invalid inputs", () => {
|
||||
assert.equal(null, JavaScript.nodeTypeForId(-1));
|
||||
assert.equal(null, JavaScript.nodeTypeForId(10000));
|
||||
assert.equal(null, JavaScript.idForNodeType("export_statement", false));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue