2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-20 20:00:33 +03:00

feat: add start and end positions of tag nodes (#246)

Closes #134

* feat: Add start and end positions of tag nodes

Improves accuracy of row/col error reporting. Now targets the start of the relevant token instead of the end.

* Simplify language for TagNode and Token

* Update static TagNode.create to ingest setStart() logic

improve readability of end pos offset for no attr tags
This commit is contained in:
Steven Chang
2024-08-01 00:42:29 -07:00
committed by GitHub
parent 0beab56d7f
commit 40848747d4
13 changed files with 929 additions and 386 deletions
@@ -2,7 +2,7 @@ import { TagNode } from '../src'
describe('@bbob/plugin-helper/TagNode', () => {
test('create', () => {
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
const tagNode = TagNode.create('test', {test: 1}, ['Hello'], {from: 0, to: 10});
expect(tagNode).toBeInstanceOf(TagNode)
});
@@ -36,12 +36,15 @@ describe('@bbob/plugin-helper/TagNode', () => {
});
test('toTagNode', () => {
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
const tagNode = TagNode.create('test', {test: 1}, ['Hello'], {from: 0, to: 10});
tagNode.setEnd({from: 20, to: 27});
const newTagNode = tagNode.toTagNode()
expect(newTagNode !== tagNode).toBe(true);
expect(newTagNode.tag).toEqual(tagNode.tag);
expect(newTagNode.content).toEqual(tagNode.content);
expect(newTagNode.start).toEqual(tagNode.start);
expect(newTagNode.end).toEqual(tagNode.end);
});
test('null content', () => {
@@ -56,6 +59,20 @@ describe('@bbob/plugin-helper/TagNode', () => {
expect(String(tagNode)).toBe('[img]');
});
test('setStart', () => {
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
tagNode.setStart({from: 0, to: 10});
expect(tagNode.start).toEqual({from: 0, to: 10});
});
test('setEnd', () => {
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
tagNode.setEnd({from: 20, to: 27});
expect(tagNode.end).toEqual({from: 20, to: 27});
});
describe('toString', () => {
test('tag with content and params', () => {
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);