1my $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc';
2
3use TestpQuery tests => 38;
4
5use pQuery;
6
7pQuery("$t/spreadily.html");
8
9is pQuery('*')->size, 76, '* finds all';
10is pQuery('h3')->text, 'The Intarweb is a Spreadsheet!',
11    'select an element by tag name';
12is pQuery('#tagline')->text, 'The Intarweb is a Spreadsheet!',
13    'select an element by id';
14is pQuery('h3#tagline')->text, 'The Intarweb is a Spreadsheet!',
15    'select an element by tag name and id';
16is pQuery('h3:eq(0)')->text, 'The Intarweb is a Spreadsheet!',
17    'select an element by tag name and index';
18is pQuery('body h3')->text, 'The Intarweb is a Spreadsheet!',
19    'select an element by tag under tag';
20
21is pQuery->find('.bookmarklet')->text, 'Spreadily Available!',
22    'select by class';
23
24is pQuery('td:nth(4)')->text, 'Favorite Number',
25    'select nth';
26
27is pQuery('td:gt(2):lt(2)')->text, 'Age Favorite Number',
28    'select a range with gt/lt';
29
30is pQuery('td:lt(4):even')->text, 'First Name Favorite Color',
31    'select a with even';
32
33is pQuery('td:lt(4):odd')->text, 'Last Name Age',
34    'select a with odd';
35
36is pQuery('td:first')->text, 'First Name',
37    'select first';
38
39is pQuery('td:last')->text, '62.83',
40    'select last';
41
42is pQuery('td:first-child')->text,
43    'First Name Alyssa Bennie Chester Delilah Eldridge Fennel',
44    'select :first-child';
45
46is pQuery('td:last-child')->text,
47    'Favorite Number 13 7 144 54 21 138 377 62.83',
48    'select :last-child';
49
50is pQuery('ul li:only-child')->text,
51    'Subversion: http://svn.spreadily.com/repo/trunk/',
52    'select :only-child';
53
54is pQuery('tr:last:parent')->text, 'Average 43.83 62.83', 'select :parent';
55is pQuery('br:empty')->size, 3, 'select :empty';
56
57is pQuery('td:contains(Blue)')->size, 3,
58    '3 tds contain Blue';
59
60like pQuery('p:has(u)')->text, qr/^Then you can/,
61    ':has()';
62
63is pQuery('*:header')->size, 2,
64    'Two Headers';
65
66is pQuery(':header')->size, 2,
67    'Two Headers';
68
69is pQuery("table#table1")->size, 1,
70    'combined tag#id selector';
71
72is pQuery('[href]')->size, 4,
73    'match attribute is defined';
74
75is pQuery('[nowrap]')->size, 4,
76    'match attribute is defined';
77
78is pQuery('[href="http://en.wikipedia.org/wiki/Bookmarklet"]')->size, 1,
79    'match attribute href equals exactly';
80
81is pQuery('A[href!=http://svn.spreadily.com/repo/trunk/]')->size, 2,
82    'match tag attribute href is not equal or not defined';
83
84is pQuery("[href][href!='http://svn.spreadily.com/repo/trunk/']")->size, 3,
85    'match attribute href is defined and not equal';
86
87is pQuery('[href^="http"]')->size, 2,
88    'match attribute href starts with http';
89
90is pQuery('[href$="Bookmarklet"]')->size, 1,
91    'match attribute href ends with Bookmarklet';
92
93is pQuery('[class|="table"]')->[0]->tagName, 'TR',
94    'match attribute equals or is fallowed by a dash';
95
96is pQuery('[class~="foo"]')->size, 5,
97    'match attribute contains given word';
98
99is pQuery('[class~="bar"]')->size, 3,
100    'match attribute contains given word';
101
102is pQuery('[class~="baz"]')->size, 4,
103    'match attribute contains given word';
104
105is pQuery('[class*=" foo baz"]')->size, 1,
106    'match attribute contains given substring';
107
108is pQuery('TaBle#table1 > TR:eq(2) TD:first-child')->html, 'Bennie',
109    'complex case insensitive selector';
110
111is pQuery('body > P:eq(0) ~ table')->attr('id'), 'table1',
112    'complex sibling selector';
113
114is pQuery('body > P:eq(0) ~ table > TR > TD:first-child + TD')->html, 'Last Name',
115    'complex adjacent selector';
116
117