Debian Codegraph @

test/internals-test.js

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 var test = require('tape').test
•2 var turndownModule = require('../lib/turndown.cjs')
3
4 test('edge whitespace detection',function (t) {
5 function ews (leadingAscii, leadingNonAscii, trailingNonAscii, trailingAscii) {
6 return {
7 leading: leadingAscii + leadingNonAscii,
8 leadingAscii: leadingAscii,
9 leadingNonAscii: leadingNonAscii,
10 trailing: trailingNonAscii + trailingAscii,
11 trailingNonAscii: trailingNonAscii,
12 trailingAscii: trailingAscii
13 }
14 }
15 var WS = '\r\n \t'
16 var TEST_CASES = [
17 [`${WS}HELLO WORLD${WS}`, ews(WS, '', '', WS)],
18 [`${WS}H${WS}`, ews(WS, '', '', WS)],
19 [`${WS}\xa0${WS}HELLO${WS}WORLD${WS}\xa0${WS}`, ews(WS, `\xa0${WS}`, `${WS}\xa0`, WS)],
20 [`\xa0${WS}HELLO${WS}WORLD${WS}\xa0`, ews('', `\xa0${WS}`, `${WS}\xa0`, '')],
21 [`\xa0${WS}\xa0`, ews('', `\xa0${WS}\xa0`, '', '')],
22 [`${WS}\xa0${WS}`, ews(WS, `\xa0${WS}`, '', '')],
23 [`${WS}\xa0`, ews(WS, `\xa0`, '', '')],
24 [`HELLO WORLD`, ews('', '', '', '')],
25 [``, ews('', '', '', '')],
26 [`TEST${Array(32768).join(' ')}END`, ews('', '', '', '')], // performance check
27 ]
28 t.plan(TEST_CASES.length)
29 t.timeoutAfter(300)
30 var edgeWhitespace = turndownModule.__get__('edgeWhitespace')
31 TEST_CASES.forEach(function (c) {
32 t.deepEqual(edgeWhitespace(c[0]), c[1])
33 })
34 })