]> gitweb.factorcode.org Git - factor.git/blob - extra/html/parser/analyzer/analyzer-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / extra / html / parser / analyzer / analyzer-tests.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: html.parser html.parser.analyzer kernel math sequences tools.test ;
4 IN: html.parser.analyzer.tests
5
6 { 0 3 }
7 [ 1 { 3 5 7 9 11 } [ odd? ] find-nth ] unit-test
8
9 { 2 7 }
10 [ 3 { 3 5 7 9 11 } [ odd? ] find-nth ] unit-test
11
12 { 3 9 }
13 [ 3 1 { 3 5 7 9 11 } [ odd? ] find-nth-from ] unit-test
14
15 { 4 11 }
16 [ 1 { 3 5 7 9 11 } [ odd? ] find-last-nth ] unit-test
17
18 { 2 7 }
19 [ 3 { 3 5 7 9 11 } [ odd? ] find-last-nth ] unit-test
20
21 { 0 3 }
22 [ 1 2 { 3 5 7 9 11 } [ odd? ] find-last-nth-from ] unit-test
23
24
25 [ 0 { 3 5 7 9 11 } [ odd? ] find-nth ]
26 [ undefined-find-nth? ] must-fail-with
27
28 [ 0 { 3 5 7 9 11 } [ odd? ] find-last-nth ]
29 [ undefined-find-nth? ] must-fail-with
30
31 { V{
32     T{ tag f text f "foo" f }
33 }
34 } [
35     "<html><head><title>foo</title></head></html>" parse-html
36     "title" find-between-first
37 ] unit-test
38
39 { V{
40     T{ tag f "p" H{ } f f }
41     T{ tag f text f "para" f }
42     T{ tag f "p" H{ } f t }
43 }
44 } [
45     "<body><div><p>para</p></div></body>" parse-html "div" find-between-first
46 ] unit-test
47
48 { V{
49     T{ tag f "div" H{ { "class" "foo" } } f f }
50     T{ tag f "p" H{ } f f }
51     T{ tag f text f "para" f }
52     T{ tag f "p" H{ } f t }
53     T{ tag f "div" H{ } f t }
54 }
55 } [
56     "<body><div class=\"foo\"><p>para</p></div></body>" parse-html
57     "foo" find-by-class-between
58 ] unit-test
59
60 { V{
61     T{ tag f "div" H{ { "class" "foo" } } f f }
62     T{ tag f "div" H{ } f f }
63     T{ tag f "p" H{ } f f }
64     T{ tag f text f "para" f }
65     T{ tag f "p" H{ } f t }
66     T{ tag f "div" H{ } f t }
67     T{ tag f "div" H{ } f t }
68 }
69 } [
70     "<body><div class=\"foo\"><div><p>para</p></div></div></body>" parse-html
71     "foo" find-by-class-between
72 ] unit-test
73
74 { t } [
75     T{ tag { name "f" } { attributes H{ { "class" "a b c" } } } }
76     { "a" "b" "c" } [ html-class? ] with all?
77 ] unit-test
78
79 {
80     V{
81         T{ tag
82            { name "div" }
83            { attributes H{ { "class" "foo and more" } } }
84         }
85         T{ tag { name "div" } { attributes H{ } } { closing? t } }
86     }
87 } [ "<div class=\"foo and more\"></div>" parse-html
88     "foo" find-by-class-between
89 ] unit-test
90
91 {
92     0
93     T{ tag { name "div" } { attributes H{ { "class" "foo bar" } } } }
94 } [
95     "<div class=\"foo bar\"></div>" parse-html "bar" find-by-class
96 ] unit-test