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

chore(core): string node walk plugin test

This commit is contained in:
Nikolay Kostyurin
2018-09-24 00:39:13 +02:00
parent b49b7435da
commit ee29d499e5
3 changed files with 42 additions and 5 deletions
+34 -1
View File
@@ -1,4 +1,5 @@
import render from '@bbob/html'
import { TagNode } from '@bbob/parser'
import core from '../src'
const stringify = val => JSON.stringify(val);
@@ -21,7 +22,7 @@ describe('@bbob/core', () => {
]))
});
test('plugin walk api', () => {
test('plugin walk api node', () => {
const testPlugin = () => (tree) => tree.walk(node => {
if (node.tag === 'mytag') {
node.attrs = {
@@ -55,6 +56,38 @@ describe('@bbob/core', () => {
]));
});
test('plugin walk api string', () => {
const testPlugin = () => (tree) => tree.walk(node => {
if (node === ':)') {
return TagNode.create('test-tag')
}
return node
});
const res = process([testPlugin()], '[mytag]Large Text :)[/mytag]');
const ast = res.tree;
expect(ast).toBeInstanceOf(Array);
expect(ast.walk).toBeInstanceOf(Function);
expect(stringify(ast)).toEqual(stringify([
{
tag: 'mytag',
attrs: {},
content: [
'Large',
' ',
'Text',
{
tag: 'test-tag',
attrs: {},
content: [],
}
]
}
]));
});
test('plugin match api', () => {
const testPlugin = () => (tree) => tree.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
if (node.attrs) {