File: 02-tags.t

package info (click to toggle)
libtest-html-content-perl 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,393; makefile: 2
file content (87 lines) | stat: -rwxr-xr-x 5,452 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -w
use strict;
use lib 't';
use testlib;

sub run {
  # Tests for tags
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Single attribute");
  tag_ok('<html><a href="http://www.perl.com">Title</a></html>',
      "A",{href => "http://www.perl.com" }, "Uppercase query finds lowercase tag");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Lowercase query finds uppercase tag");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "A",{href => "http://www.perl.com" }, "Uppercase query finds uppercase tag");
  tag_ok('<html><a href="http://www.perl.com">Title</a></html>',
      "a",{href => "http://www.perl.com" }, "Lowercase query finds lowercase tag");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a",{}, "No attributes");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a",undef, "Undef attributes");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a", "Forgotten attributes");
  tag_count('<html><A href="http://www.perl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" },1, "Single attribute gets counted once");
  tag_ok('<html><A href="http://www.perl.com" alt=\'click here!\'>Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Superfluous attributes are ignored");
  tag_count('<html><A href="http://www.perl.com" alt=\'click here!\'>Title</A></html>',
      "a",{href => "http://www.perl.com" }, 1, "Superfluous attributes are ignored and still the matchcount stays");
  tag_ok('<html><A href="http://www.perl.com">Title</A><A href="http://www.perl.com">Icon</A></html>',
      "a",{href => "http://www.perl.com" }, "Tags that appear twice get reported");
  tag_count('<html><A href="http://www.perl.com">Title</A><A href="http://www.perl.com">Icon</A></html>',
      "a",{href => "http://www.perl.com" },2, "Tags that appear twice get reported twice");

  no_tag('<html><A href="http://www.perl.com.example.com">Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Plain strings get matched exactly");
  tag_ok('<html><A href="http://www.perl.com">Title</A></html>',
      "a",{href => qr"^http://.*$" }, "Regular expressions for attributes");
  tag_ok('<html><A href="http://www.perl.com" name="Perl">Title</A></html>',
      "a",{href => qr"^http://.*$", name => "Perl" }, "Mixing regular expressions with strings");
  tag_ok('<html><A href="http://www.perl.com" name="Perl">Title</A></html>',
      "a",{href => qr"^http://.*$", name => qr"^P.*l$" }, "Specifying more than one RE");
  tag_ok('<html><A href="http://www.perl.com" name="Perl">Title</A></html>',
      "a",{href => qr"http://www.pea?rl.com", name => qr"^Pea?rl$" }, "Optional RE");

  tag_count('<html><A href="http://www.perl.com" name="Perl">Title</A><A href="http://www.perl.com">Another link</A></html>',
      "a",{href => "http://www.perl.com" },2, "Ignored tags");
  tag_count('<html><a href="http://www.perl.com" name="Perl">Title</a><a href="http://www.perl.com">Another link</a></html>',
      "a",{href => "http://www.perl.com", name => undef },1, "Absent tags");

  no_tag('<html><A hrf="http://www.perl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Misspelled attribute is not found");
  tag_count('<html><A hrf="http://www.perl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" },0, "Misspelled attribute is reported zero times");

  no_tag('<html><B href="http://www.perl.com">Title</B></html>',
      "a",{href => "http://www.perl.com" }, "Tag with same attribute but different tag is not found");
  tag_count('<html><B href="http://www.perl.com">Title</B></html>',
      "a",{href => "http://www.perl.com" }, 0,"Tag with same attribute but different tag is reported zero times");

  no_tag('<html><A href="http://www.purl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" },"Tag with different attribute value is not found");
  tag_count('<html><A href="http://www.purl.com">Title</A></html>',
      "a",{href => "http://www.perl.com" },0,"Tag with different attribute value is reported zero times");

  no_tag('<html><!-- <A href="http://www.purl.com">Title</A></html> -->',
      "a",{href => "http://www.perl.com" }, "Tag within a comment is not found");
  tag_count('<html><!-- <A href="http://www.purl.com">Title</A></html> -->',
      "a",{href => "http://www.perl.com" }, 0, "Tag within a comment is reported zero times");

  no_tag('<html><!-- <A href="http://www.perl.com"> -->Title</A></html>',
      "a",{href => "http://www.perl.com" }, "Tag within a (different) comment is not found");
  tag_count('<html><!-- <A href="http://www.perl.com"> -->Title</A></html>',
      "a",{href => "http://www.perl.com" }, 0, "Tag within a (different) comment is reported zero times");

  # RE parameters
  no_tag('<html><A href="http://www.perl.com" name="Perl">Title</A></html>',
      "a",{href => "http://www.perl.com", name => qr"^Pearl$" }, "Nonmatching via RE");
  tag_count('<html>
               <p style="nice">Nice style</p>
               <p style="ugly">Ugly style</p>
               <p style="super-ugly">Super-ugly style</p>
             </html>',
      "p",{style => qr"ugly$" }, 2, "Tag attribute counting");
};

runtests(32,\&run);