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