UNPKG

@textlint/ast-tester

Version:

Compliance tests for textlint's AST(Abstract Syntax Tree).

100 lines 4.02 kB
// LICENSE : MIT "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.test = exports.isUnist = void 0; const assert = __importStar(require("assert")); // https://github.com/wooorm/unist function isUnist(node) { try { test(node); } catch (error) { return false; } return true; } exports.isUnist = isUnist; function test(node) { assert.strictEqual(typeof node, "object"); assert.strictEqual(typeof node.type, "string"); assert.ok(node.type.length >= 1); assert.doesNotThrow(function () { JSON.parse(JSON.stringify(node)); }); if (node.children !== null && node.children !== undefined) { assert.ok(Array.isArray(node.children)); node.children.forEach(test); } if (node.value !== null && node.value !== undefined) { assert.strictEqual(typeof node.value, "string"); } const position = node.position; if (position !== null && position !== undefined) { assert.strictEqual(typeof position, "object"); const start = position.start; const indent = position.indent; const end = position.end; if (start !== null && start !== undefined) { assert.strictEqual(typeof start, "object"); if (start.line !== null && start.line !== undefined) { assert.strictEqual(typeof start.line, "number"); assert.ok(start.line >= 0); // allow `0` for `null`. } if (start.column !== null && start.column !== undefined) { assert.strictEqual(typeof start.column, "number"); assert.ok(start.column >= 0); // allow `0` for `null`. } if (start.offset !== null && start.offset !== undefined) { assert.strictEqual(typeof start.offset, "number"); assert.ok(start.offset >= 0); } } if (end !== null && end !== undefined) { assert.strictEqual(typeof end, "object"); if (end.line !== null && end.line !== undefined) { assert.strictEqual(typeof end.line, "number"); assert.ok(end.line >= 0); // allow `0` for `null`. } if (end.column !== null && end.column !== undefined) { assert.strictEqual(typeof end.column, "number"); assert.ok(end.column >= 0); // allow `0` for `null`. } if (end.offset !== null && end.offset !== undefined) { assert.strictEqual(typeof end.offset, "number"); assert.ok(end.offset >= 0); } } if (indent !== null && indent !== undefined) { assert.ok(Array.isArray(indent)); indent.forEach(function (indentation) { assert.strictEqual(typeof indentation, "number"); assert.ok(indentation >= 0); }); } } } exports.test = test; //# sourceMappingURL=unist-test.js.map