root/Web-Scraper/trunk/t/12_html.t

Revision 2371 (checked in by miyagawa, 13 years ago)

look to see if textarea preserves newlines

Line 
1 use strict;
2 use Test::Base;
3
4 use utf8;
5 use Web::Scraper;
6 plan tests => 1 * blocks;
7
8 filters {
9     selector => 'chomp',
10     expected => [ 'chomp', 'newline' ],
11     html     => 'newline',
12 };
13
14 sub newline {
15     s/\\n\n/\n/g;
16 }
17
18 run {
19     my $block = shift;
20     my $s = scraper {
21         process $block->selector, want => 'HTML';
22         result 'want';
23     };
24     my $want = $s->scrape($block->html);
25     is $want, $block->expected, $block->name;
26 };
27
28 __DATA__
29
30 === script
31 --- html
32 <script>function foo() {
33   return bar;
34 }
35 </script>
36 --- selector
37 script
38 --- expected
39 function foo() {
40   return bar;
41 }
42
43 === a
44 --- html
45 <a id="foo"><span>foo</span> bar</a>
46 --- selector
47 a
48 --- expected
49 <span>foo</span> bar
50
51 === div
52 --- html
53 <div id="foo">
54 <p>foo
55 bar</p>
56 <p>bar</p>
57 </div>
58 --- selector
59 #foo
60 --- expected
61 <p>foo bar</p><p>bar</p>
62
63 === non-ascii
64 --- html
65 <p id="foo">テスト</p>
66 --- selector
67 #foo
68 --- expected
69 テスト
70
71 === textarea
72 --- html
73 <textarea>
74 foo
75 bar
76 \n
77 baz
78 </textarea>
79 --- selector
80 textarea
81 --- expected
82 \n
83 foo
84 bar
85 \n
86 baz
Note: See TracBrowser for help on using the browser.