import { expect } from 'chai'; import { fuzzyTest, hasInlineText, kernelText, normalizeLines, tokenize } from './utils'; describe(' 工具函数', () => { it('把“1. ”列表处理成空行分隔的格式,以便处理', function () { const lines = normalizeLines(`1. abc 11. def `); expect(lines).eql(`1. abc 11. def`); }); it('把“- ”列表处理成空行分隔的格式,以便处理', function () { const lines = normalizeLines(`- abc - def `); expect(lines).eql(`- abc - def`); }); it('把“* ”列表处理成空行分隔的格式,以便处理', function () { const lines = normalizeLines(`* abc * def `); expect(lines).eql(`* abc * def`); }); it('把“# ”标题处理成空行分隔的格式,以便处理', function () { const lines = normalizeLines(`\n# abc def`); expect(lines).eql(`# abc def`); }); it('拆解单行的成对 tag', function () { const lines = normalizeLines(` a
DEF
b `); expect(lines).eql(`a
DEF
b`); }); it('拆解单行的自封闭 tag', function () { const lines = normalizeLines(` a
b `); expect(lines).eql(`a
b`); }); it('拆解单行的 h\\d 标签', function () { const lines = normalizeLines(` a

line

b `); expect(lines).eql(`a

line

b`); }); it('把多行 hn 处理成单行', function () { const lines = normalizeLines(` `); expect(lines).eql(``); }); it('拆解单行的 th 标签', function () { const lines = normalizeLines(` a line b `); expect(lines).eql(`a line b`); }); it('拆解单行注释', function () { const lines = normalizeLines(` a b `); expect(lines).eql(`a b`); }); it('拆解多行注释', function () { const lines = normalizeLines(` a b `); expect(lines).eql(`a b`); }); it('拆解单行br', function () { const lines = normalizeLines(` a
b `); expect(lines).eql(`a
b`); }); it('拆解 code-example', function () { const lines = normalizeLines(` abc ng generate directive highlight def `); expect(lines).eql(`abc ng generate directive highlight def`); }); it('不拆解引用的 code-example', function () { const lines = normalizeLines(` abc > abc def `); expect(lines).eql(`abc > abc def`); }); it('为单行的 li 和 ul 前后添加空行', function () { const lines = normalizeLines(` a
  • b
  • c `); expect(normalizeLines(lines)).eql(`a
  • b
  • c `); }); it('拆解 @a 标记', function () { const lines = normalizeLines(` a {@a test} b `); expect(lines).eql(`a {@a test} b`); }); it('拆解多行代码', function () { const lines = normalizeLines(` a \`\`\` var a = 1 \`\`\` b `); expect(lines).eql(`a \`\`\` var a = 1 \`\`\` b`); }); it('把多行的 p 元素合并成单行', function () { const lines = normalizeLines(`

    a

    `); expect(lines).eq(`

    a

    `); }); it('不要拆解 header', function () { const lines = normalizeLines(`
    Angular forms don't require a style library
    `); expect(lines).eq(`
    Angular forms don't require a style library
    `); }); it('拆解独行的 th/td', function () { expect(normalizeLines(` abc `)).eql(` abc `); }); it('拆解 pre', function () { expect(normalizeLines(` ABC
    def
    ghi `)).eql(`ABC
    def
    ghi`); }); it('拆解任意位置的 ', function () { expect(normalizeLines(` abc `)).eql(` abc `); }); it('拆解独行的 li', function () { expect(normalizeLines(` `)).eql(``); }); it('不要拆解行内的 html tag', function () { expect(normalizeLines(` a c `)).eql(`a c`); }); it('把连续的三行及以上空行简化为两个空行', function () { const lines = normalizeLines(` a b`); expect(lines).eql(`a b`); }); it('拆分', function () { expect(tokenize('abc def,abc.')).eql(['abc', 'def', 'abc']); }); it('抽取核心字符', function () { expect(kernelText(' # Forms ABC. ')).eql('#FORMSABC'); }); it('删除非核心字符', function () { expect(kernelText('Abc-132-@#!abc')).eql('ABC132#ABC'); }); it('模糊匹配', function () { expect(fuzzyTest(`a b c d e`, `a b c d e`)).is.false; expect(fuzzyTest(`a b c d e f g`, `a b c d e`)).is.false; expect(fuzzyTest(`Make that easy by encapsulating the _click-triggering_ process in a helper such as the \`click\` function below:`, `Make that consistent and easy by encapsulating the _click-triggering_ process in a helper such as the \`click()\` function below: `)).is.true; }); it('检测是否表格', function () { expect(hasInlineText(` abc | def ----|--- gh | ij `)).eql(true); }); });