mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
feat: typescript support (#185)
* feat: initial typescript support * feat: typescript support * feat(plugin-helper): move files to typescript * chore: update lock files * feat: preset types * fix: build * fix: benchmark * fix: remove pnpm cache * fix: bench action * fix: pnpm recursive install * fix: nx cache * fix: lock file * fix: workflows * fix: lerna support in pnpm * fix: pnpm workspace * fix: remove unused files * fix: pnpm lock file * fix: update lerna for support pnpm * fix: lerna bootstrap * fix: rollup build * fix: update nx * fix: build * fix: add nx dep target * fix: remove nx cache * fix: workflow run on push only for master * fix: test workflow run on push only for master * fix: remove parallel for gen types * fix: benchmark * fix: benchmark imports * fix: pnpm * fix: types errors and pnpm * fix: types * fix: types * refactor: parser * fix(parser): tests * fix: preset tests * fix: react types * fix: react type declarations * fix: pnpm lock file * fix: react preset types * fix: lock file * fix: vue2 types * feat: dev container support * fix: types * fix: types * refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts * refactor: types * fix: types * fix: rename gen-types to types * fix: nx build order * fix: nx reset * fix: define nx deps explicit * fix: build * fix: nx * fix: nx order build * fix: nx deps * fix: bbob cli tests * fix: tests * fix: cli tests and import * fix: test cover * fix: cli cover
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { TagNode } from '@bbob/parser'
|
||||
import core from '../src'
|
||||
import core, { BBobPluginFunction, BBobPlugins } from '../src'
|
||||
import { isTagNode } from "@bbob/plugin-helper";
|
||||
|
||||
const stringify = val => JSON.stringify(val);
|
||||
const stringify = (val: unknown) => JSON.stringify(val);
|
||||
|
||||
const process = (plugins, input) => core(plugins).process(input, { render: stringify });
|
||||
const process = (plugins: BBobPlugins, input: string) => core(plugins).process(input, { render: stringify });
|
||||
|
||||
describe('@bbob/core', () => {
|
||||
test('parse bbcode string to ast and html', () => {
|
||||
@@ -22,17 +23,27 @@ describe('@bbob/core', () => {
|
||||
});
|
||||
|
||||
test('plugin walk api node', () => {
|
||||
const testPlugin = () => (tree) => tree.walk(node => {
|
||||
if (node.tag === 'mytag') {
|
||||
node.attrs = {
|
||||
pass: 1
|
||||
};
|
||||
const testPlugin = () => {
|
||||
|
||||
node.content.push('Test');
|
||||
}
|
||||
const plugin: BBobPluginFunction = (tree) => tree.walk(node => {
|
||||
if (isTagNode(node)) {
|
||||
if (node?.tag === 'mytag') {
|
||||
node.attrs = {
|
||||
pass: 1
|
||||
};
|
||||
|
||||
return node
|
||||
});
|
||||
if (Array.isArray(node.content)) {
|
||||
node.content.push('Test');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return node
|
||||
});
|
||||
|
||||
return plugin
|
||||
}
|
||||
|
||||
const res = process([testPlugin()], '[mytag size="15px"]Large Text[/mytag]');
|
||||
const ast = res.tree;
|
||||
@@ -56,13 +67,18 @@ describe('@bbob/core', () => {
|
||||
});
|
||||
|
||||
test('plugin walk api string', () => {
|
||||
const testPlugin = () => (tree) => tree.walk(node => {
|
||||
if (node === ':)') {
|
||||
return TagNode.create('test-tag')
|
||||
}
|
||||
const testPlugin = () => {
|
||||
|
||||
return node
|
||||
});
|
||||
const plugin: BBobPluginFunction = (tree) => tree.walk(node => {
|
||||
if (node === ':)') {
|
||||
return TagNode.create('test-tag')
|
||||
}
|
||||
|
||||
return node
|
||||
})
|
||||
|
||||
return plugin
|
||||
};
|
||||
|
||||
const res = process([testPlugin()], '[mytag]Large Text :)[/mytag]');
|
||||
const ast = res.tree;
|
||||
@@ -89,13 +105,18 @@ describe('@bbob/core', () => {
|
||||
});
|
||||
|
||||
test('plugin match api', () => {
|
||||
const testPlugin = () => (tree) => tree.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
||||
if (node.attrs) {
|
||||
node.attrs['pass'] = 1
|
||||
}
|
||||
const testPlugin = () => {
|
||||
|
||||
return node
|
||||
});
|
||||
const plugin: BBobPluginFunction = (tree) => tree.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
||||
if (isTagNode(node) && node.attrs) {
|
||||
node.attrs['pass'] = 1
|
||||
}
|
||||
|
||||
return node
|
||||
})
|
||||
|
||||
return plugin
|
||||
};
|
||||
|
||||
const res = process([testPlugin()], `[mytag1 size="15"]Tag1[/mytag1][mytag2 size="16"]Tag2[/mytag2][mytag3]Tag3[/mytag3]`);
|
||||
const ast = res.tree;
|
||||
@@ -1,7 +1,5 @@
|
||||
import { iterate, match, same } from '../src/utils';
|
||||
|
||||
const stringify = val => JSON.stringify(val);
|
||||
|
||||
import { isTagNode } from "@bbob/plugin-helper";
|
||||
|
||||
describe('@bbob/core utils', () => {
|
||||
test('iterate', () => {
|
||||
@@ -14,7 +12,12 @@ describe('@bbob/core utils', () => {
|
||||
}];
|
||||
|
||||
const resultArr = iterate(testArr, node => {
|
||||
node.pass = 1;
|
||||
if (typeof node === 'object' && node !== null) {
|
||||
return {
|
||||
...node,
|
||||
pass: 1
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
@@ -31,7 +34,7 @@ describe('@bbob/core utils', () => {
|
||||
}
|
||||
];
|
||||
|
||||
expect(stringify(resultArr)).toEqual(stringify(expected));
|
||||
expect(resultArr).toEqual(expected);
|
||||
});
|
||||
test('match', () => {
|
||||
const testArr = [
|
||||
@@ -43,24 +46,25 @@ describe('@bbob/core utils', () => {
|
||||
{ tag: 'mytag6', six: 1 },
|
||||
];
|
||||
|
||||
testArr.match = match;
|
||||
|
||||
const resultArr = testArr.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
||||
node.pass = 1;
|
||||
const resultArr = match(testArr, [{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
||||
if (isTagNode(node)) {
|
||||
node.attrs = node.attrs || {}
|
||||
node.attrs.pass = 1
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
const expected = [
|
||||
{ tag: 'mytag1', one: 1, pass: 1 },
|
||||
{ tag: 'mytag2', two: 1, pass: 1 },
|
||||
{ tag: 'mytag1', one: 1, attrs: { pass: 1 } },
|
||||
{ tag: 'mytag2', two: 1, attrs: { pass: 1 } },
|
||||
{ tag: 'mytag3', three: 1 },
|
||||
{ tag: 'mytag4', four: 1 },
|
||||
{ tag: 'mytag5', five: 1 },
|
||||
{ tag: 'mytag6', six: 1 },
|
||||
];
|
||||
|
||||
expect(stringify(resultArr)).toEqual(stringify(expected))
|
||||
expect(resultArr).toEqual(expected)
|
||||
})
|
||||
|
||||
describe('same', () => {
|
||||
@@ -79,5 +83,8 @@ describe('@bbob/core utils', () => {
|
||||
test('same object', () => {
|
||||
expect(same({ foo: true, bar: 'test' }, { foo: true, bar: 'test', ext: true })).toBe(true)
|
||||
})
|
||||
test('same string', () => {
|
||||
expect(same('bar', 'bar')).toBe(true)
|
||||
})
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user