File: 10para.t

package info (click to toggle)
txt2html 1%3A2.53-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 816 kB
  • sloc: perl: 3,608; sh: 5; makefile: 2
file content (175 lines) | stat: -rw-r--r-- 4,132 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#########################

use Test::More tests => 18;
use HTML::TextToHTML;
ok(1); # If we made it this far, we are ok.

# Insert your test code below, the Test module is use()ed here so read
# its man page ( perldoc Test ) for help writing this test script.

my $conv = new HTML::TextToHTML();
ok( defined $conv, 'new() returned something' );
ok( $conv->isa('HTML::TextToHTML'), "  and it's the right class" );

$conv->args(
	system_link_dict=>'txt2html.dict',
	default_link_dict=>'',
	);

#
# test the process_para method alone
#
$test_str = "Matty had a little truck
he drove it round and round
and everywhere that Matty went
the truck was *always* found.
";

$ok_str = "<p>Matty had a little truck<br/>
he drove it round and round<br/>
and everywhere that Matty went<br/>
the truck was <em>always</em> found.
</p>";

$out_str = $conv->process_para($test_str);
ok($out_str, 'converted sample string');

# compare the result
is($out_str, $ok_str, 'compare converted string with OK string');

#
# test the process_chunk method with an ordered list
#
$test_str = "Here is my list:

1. Spam
2. Jam
3. Ham
4. Pickles
";

$ok_str = "<p>Here is my list:
</p><ol>
  <li>Spam
  </li><li>Jam
  </li><li>Ham
  </li><li>Pickles</li></ol>
";

$out_str = $conv->process_chunk($test_str);
ok($out_str, 'converted sample string with list');

# compare the result
is($out_str, $ok_str, 'compare converted list string with OK list string');

#
# test the process_chunk method with an empty string
#
$test_str = "";

$ok_str = "";

$out_str = $conv->process_chunk($test_str);
# note we do not do an ok on this because it should be empty

# compare the result
is($out_str, $ok_str, 'compare converted empty string with OK empty string');

#
# test with is_fragment
#
$test_str = "Matty had a little truck
he drove it round and round
and everywhere that Matty went
the truck was *always* found.
";

$ok_str = "Matty had a little truck<br/>
he drove it round and round<br/>
and everywhere that Matty went<br/>
the truck was <em>always</em> found.
";

$out_str = $conv->process_chunk($test_str, is_fragment=>1);
ok($out_str, 'converted sample string');

# compare the result
is($out_str, $ok_str, 'compare converted string with OK string');

#
# test the process_para method with a URL
#
$test_str = "I like to look at http://www.example.com a lot";

$ok_str = 'I like to look at <a href="http://www.example.com">http://www.example.com</a> a lot';

$out_str = $conv->process_para($test_str, is_fragment=>1);
ok($out_str, 'converted sample string with URL');

# compare the result
is($out_str, $ok_str, 'compare converted URL string with OK URL string');

#
# test process_chunk with caps_tag turned off
#
$test_str = "We have a line alone
FULL OF CAPS AND FURY
";

$ok_str = "We have a line alone<br/>
FULL OF CAPS AND FURY
";

$conv->args(caps_tag=>'');
$out_str = $conv->process_chunk($test_str, is_fragment=>1);
ok($out_str, 'converted sample string with CAPS');

# compare the result
is($out_str, $ok_str, 'compare converted CAPS string with OK CAPS string');

$conv->args(caps_tag=>'STRONG'); # restore caps to default

#
# Test with different italic/bold delimiters
#
$test_str = "I am ^bold^,
You are --really krazy--.
-----------------
";

$ok_str = "I am <strong>bold</strong>,<br/>
You are <em>really krazy</em>.
<hr/>
";

$conv->args(bold_delimiter=>'^',
	italic_delimiter=>'--');
$out_str = $conv->process_chunk($test_str, is_fragment=>1);
ok($out_str, 'converted sample string with delimiters');

# compare the result
is($out_str, $ok_str, 'compare converted delimiter string with OK delimiter string');

# 
# test with no bolding or italic at all
$test_str = "I am ^bold^,
You are --really krazy--.
-----------------
";

$ok_str = "I am ^bold^,<br/>
You are --really krazy--.
<hr/>
";

$conv->args(bold_delimiter=>'',
	italic_delimiter=>'');
$out_str = $conv->process_chunk($test_str, is_fragment=>1);
ok($out_str, 'converted sample string with no bold');

# compare the result
is($out_str, $ok_str, 'compare converted no-bold string with OK no-bold string');

# restore default
$conv->args(bold_delimiter=>'#',
	italic_delimiter=>'*');