-- The visible text of an HTML part must be what a browser renders: the tree -- is built as the HTML Standard says (implied end tags, text in the head and -- after the last tag, no character references in tag names) context("HTML tree building", function() local rspamd_parsers = require "rspamd_parsers" local rspamd_task = require "rspamd_task" local rspamd_config = rspamd_config local function visible(html) return tostring(rspamd_parsers.parse_html(html)) end -- The cases that give another text, one per line; empty if all are right local function mismatches(cases) local bad = {} for _, c in ipairs(cases) do local got = visible(c[1]) if got ~= c[2] then bad[#bad + 1] = string.format('%q: expected %q, got %q', c[1], c[2], got) end end return table.concat(bad, '\n') end test('text after the last tag is shown', function() assert_equal('', mismatches({ { '
one
TAIL', 'one\nTAIL' }, { 'one
TAIL', 'one\nTAIL' }, { 'one
\nTAIL\n', 'one\nTAIL' }, { 'one
TAIL', 'one\nTAIL' }, { 'two
', 'one\nTAIL\ntwo\n' }, })) end) test('text after the end of the body goes into the body, as in a browser', function() assert_equal('', mismatches({ { 'HIDTAIL', '' }, { '