Debian Codegraph @

test/internals-test.js

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