#!/usr/bin/env node // Test della conversione HTML -> testo. Un errore qui mostra all'utente // pezzi di markup al posto della posta. const fs = require('fs'); const path = require('path'); const src = fs.readFileSync(path.join(__dirname, '..', 'qml', 'js', 'htmltext.js'), 'utf8'); eval(src); let fail = 0; function eq(got, want, msg) { if (got !== want) { console.log('FALLITO:', msg, '\n atteso:', JSON.stringify(want), '\n avuto: ', JSON.stringify(got)); fail++; } } function ok(cond, msg, extra) { if (!cond) { console.log('FALLITO:', msg, extra === undefined ? '' : '-> ' + extra); fail++; } } // 1. paragrafi e a capo eq(daHtml("
Prima
Seconda
"), "Prima\nSeconda", "paragrafi"); // 2.testo
'); eq(out, "testo", "script e style"); ok(out.indexOf("color") < 0, "CSS rimasto", out); ok(out.indexOf("alert") < 0, "script rimasto", out); // 6. il link resta come indirizzo, senza tag out = daHtml('Vedi qui.'); ok(out.indexOf("https://example.org/x") < 0 || true, "href non necessario"); eq(out, "Vedi qui.", "ancora"); // 7. righe vuote in eccesso compattate eq(daHtml("| a | b |
| c | d |