# HTML::FromText test suite (-*- cperl -*-) use strict; use HTML::FromText; $^W = 1; # Each test is represented by three data chunks, separated by a line # containing only a form-feed character (0x0c). The first chunk is # the options to pass to text2html(), the second is the input, and the # third the expected output. $/ = "\n\f\n"; my @tests = (); while () { chomp; push @tests, $_; } my $n = @tests / 3; print "1..$n\n"; foreach my $i (1..$n) { my $j = 3 * ($i - 1); my $input = $tests[$j + 1]; my $expected = $tests[$j + 2]; my @options = eval $tests[$j]; my $output = text2html($input, @options); unless ($output eq $expected) { print STDERR "\n",'--expected','-'x60, "\n",$expected, "\n",'--but-found','-'x59, "\n",$output, "\n",'-'x70, "\n"; print "not "; } print "ok $i\n"; } __DATA__ () <&> <B>&lt;&amp;&gt;</B> (metachars => 0) <&> <&> (email => 1) real@email.address, real2@email.addresss. fake@:email.address, another@[fake].address mailto:me@foo.bar.com #$%=strange!?@characters.=+=in=+=_.address real@email.address, real2@email.addresss. fake@:email.address, another@[fake].address mailto:me@foo.bar.com <tricky@subdomain.domain> #$%=strange!?@characters.=+=in=+=_.address (metachars => 1, email => 1) An email address with an & in it: fred&barney@stonehenge.com. An email address with an & in it: fred&barney@stonehenge.com. (metachars => 0, email => 1) An email address with an & in it: fred&barney@stonehenge.com. Generates non-legal HTML, but that was what was asked for! An email address with an & in it: fred&barney@stonehenge.com. Generates non-legal HTML, but that was what was asked for! (urls => 1) See http://foo.bar.com. What about http://foo.com/bar/baz? http://foo.com/bar/baz?quux. ftp://spong.gov/a/b/c/d.e/f.g/h/ should have trailing / ...gopher://x.y.z/foo... mailto:mail@address.com is translated but mail@address.com on its own is not See http://foo.bar.com. What about http://foo.com/bar/baz? http://foo.com/bar/baz?quux. ftp://spong.gov/a/b/c/d.e/f.g/h/ should have trailing / ...gopher://x.y.z/foo... mailto:mail@address.com is translated but mail@address.com on its own is not (bold => 1, underline => 1) *Words* in *bold* _underline_ and *bold* again, but 5*4, 3_1 unaffected; _underline_ *more* *bold* _more_ _underline_ Now *several words in bold* and _several in underline_ but equations like 5*x + 5*y or zeta_i + phi_i are not marked up. Here's a *phrase in bold crossing a newline* and an _underlined phrase crossing a newline_ Single letter words: *a* _b_ *c* _d_ Words in bold underline and bold again, but 5*4, 3_1 unaffected; underline more bold more underline Now several words in bold and several in underline but equations like 5*x + 5*y or zeta_i + phi_i are not marked up. Here's a phrase in bold crossing a newline and an underlined phrase crossing a newline Single letter words: a b c d (paras => 1, bold => 1, underline => 1) *Bold* works OK in a paragraph context and so does _underline_ _Underline works OK_ in a paragraph context and *so does bold*

Bold works OK in a paragraph context and so does underline

Underline works OK in a paragraph context and so does bold

(lines => 1) line 1 line 2 line 3 line 4 line 1
line 2
line 3
line 4 (lines => 1, spaces => 1) line 1 line 2 line 3 line 4 tab 1 tab 2 line 1
 line  2
  line   3
   line    4
        tab     1
                tab     2 (paras => 1) paragraph one paragraph two a long paragraph three

paragraph one

paragraph two

a long paragraph three

(paras => 1, title => 1) this is the title and this the text

this is the title

and this the text

(paras => 1, headings => 1) 1. Chapter one 2. Chapter two 2.1 Section two point one 2.1.1 Subsection two point one point one 2.1.1.3 Subsubsection two point one point one point three 2.1.1.3.7 Heading level 5 2.1.1.3.7.1 Heading level 6 (a long heading across two lines) paragraph text 2.1.1.3.7.1.2 There are no more than 6 heading levels. paragraph text 3. Chapter three

1. Chapter one

2. Chapter two

2.1 Section two point one

2.1.1 Subsection two point one point one

2.1.1.3 Subsubsection two point one point one point three

2.1.1.3.7 Heading level 5
2.1.1.3.7.1 Heading level 6 (a long heading across two lines)

paragraph text

2.1.1.3.7.1.2 There are no more than 6 heading levels.

paragraph text

3. Chapter three

(paras => 1, bullets => 1) Ordinary text * bulleted paragraph * another bulleted paragarph with two lines ordinary text * bullet flush left * bullet with tabs - bullet with hyphen

Ordinary text

ordinary text

(paras => 1, headings => 1, numbers => 1) 1. This is a heading, not a numbered paragraph 1. number one 2. number two 31. number thirty-one ordinary text 1. another number one * bulleted paragraph not recognised 3. number three

1. This is a heading, not a numbered paragraph

  1. number one

  2. number two

  3. number thirty-one

ordinary text

  1. another number one

* bulleted paragraph not recognised

  1. number three

(paras => 1, numbers => 1, bullets => 1) 1. a numbered item 2. and another * switching to bullets starts a new list 3. as does switching back
  1. a numbered item

  2. and another

  1. as does switching back

(paras => 1, numbers => 1, bullets => 1) * a bulleted list * with all the bullets next to each other * blah * blah (paras => 1, numbers => 1, bullets => 1) 1. a numbered list 2. with all the numbers next to each other 3. blah 4. blah
  1. a numbered list

  2. with all the numbers next to each other

  3. blah

  4. blah

(paras => 1, numbers => 1, bullets => 1) * switching between 111 numbers * and 222 bullets
  1. numbers

  1. bullets

(paras => 1, numbers => 1, bullets => 1) Ordinary paragraphs * mixed up with numbers 789 and bullets

Ordinary paragraphs

  1. and bullets

(paras => 1, numbers => 1, bullets => 1) 000 different 002. kinds 003) of 004] numbered 001 list
  1. different

  2. kinds

  3. of

  4. numbered

  5. list

(paras => 1, blockquotes => 1) Here's a block quote: line 1 line 2 line 3 line 4 end of block quote

Here's a block quote:

line 1
line 2
line 3
line 4

end of block quote

(paras => 1, blockquotes => 1) A block quote with variable spacing: line 1 line 2 line 3 end of block quote

A block quote with variable spacing:

line 1
line 2
line 3

end of block quote

(paras => 1, blockquotes => 1) Ditto, spacing goes the other way: line 1 line 2 line 3 end of block quote

Ditto, spacing goes the other way:

line 1
line 2
line 3

end of block quote

(paras => 1, blockquotes => 1) This shouldn't be recognized as blockquote: despite the spaces on this line, and this one, this is just an ordinary paragraph?

This shouldn't be recognized as blockquote:

despite the spaces on this line, and this one, this is just an ordinary paragraph?

(paras => 1, bullets => 1, numbers => 1, blockquotes => 1) This is not a blockquote, despite initial and final blank lines.

This is not a blockquote, despite initial and final blank lines.

(pre => 1) preformatted text
preformatted
text
(paras => 1, blockparas => 1) Turing wrote, I propose to consider the question, "Can machines think?" This should begin with definitions of the meaning of the terms "machine" and "think".

Turing wrote,

I propose to consider the question, "Can machines think?" This should begin with definitions of the meaning of the terms "machine" and "think".

(paras => 1, blockquotes => 1) From "The Waste Land": Phlebas the Phoenecian, a fortnight dead, Forgot the cry of gulls, and the deep sea swell

From "The Waste Land":

Phlebas the Phoenecian, a fortnight dead,
Forgot the cry of gulls, and the deep sea swell
(paras => 1, blockcode => 1) Here's how to output numbers with commas (from perlfaq4): sub commify { local $_ = shift; 1 while s/^(-?\d+)(\d{3})/$1,$2/; $_; }

Here's how to output numbers with commas (from perlfaq4):

sub commify {
  local $_ = shift;
  1 while s/^(-?\d+)(\d{3})/$1,$2/;
  $_;
}
() Line mixing tabs and metachars: &&& <> Line mixing tabs and metachars: &&& <> (paras => 1, tables => 1) 1, 1 1, 2 1, 3 2, 1 2, 2 2, 3 3, 1 3, 2 3, 3
1, 11, 21, 3
2, 12, 22, 3
3, 13, 23, 3
(paras => 1, tables => 1) Tables can be left-aligned: 1, 1 1, 2 1, 3 2, 1 2, 2 2, 3 3, 1 3, 2 3, 3

Tables can be left-aligned:

1, 11, 21, 3
2, 12, 22, 3
3, 13, 23, 3

(paras => 1, tables => 1) despite its appearance this table has only two columns
despite itsappearance
this tablehas
only twocolumns
(paras => 1, tables => 1) tables must have two columns

tables must have two columns

(paras => 1, tables => 1) tables can have only one space at the left
tablescan
haveonly
onespace
at theleft
(paras => 1, tables => 1) tables must have two rows

tables must have two rows

(paras => 1, tables => 1) this table has varying lengths of column at the right
thistablehas varying lengths of column
attheright
(paras => 1, tables => 1) This table contains right-aligned cells: p p^2 p^3 p^4 2 4 8 16 3 9 27 81 5 25 125 625 7 49 343 2401

This table contains right-aligned cells:

pp^2p^3p^4
24816
392781
525125625
7493432401
(paras => 1, tables => 1) This table contains metacharacters: & & < < > >

This table contains metacharacters:

&&amp;
<&lt;
>&gt;
(paras => 1, tables => 1) Here's a table with centre-aligned columns: 1 1 2 1 1 3 1 2 1 4 1 3 3 1 5 1 4 6 4 1

Here's a table with centre-aligned columns:

11
21 1
31 2 1
41 3 3 1
51 4 6 4 1

(paras => 1, blockparas => 1, tables => 1) This should get recognised as a blockquote despite the unorthodox spacing. But this is a table XXX XXXX XX X XXXXX

This should get recognised as a blockquote despite the unorthodox spacing.

Butthisisatable
XXXXXXXXXXXXXXX