test.xq 4.55 KB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
1
xquery version "3.1";
mrodzis's avatar
mrodzis committed
2
3
4

(: This is the main test script for the module content/main.xqm.
 : It is supposed to run during post installation stage.
Mathias Goebel's avatar
Mathias Goebel committed
5
6
7
 :
 : @version 1.0.0
 : @since 2.5.6
mrodzis's avatar
mrodzis committed
8
 : @author Michelle Weidling
Mathias Goebel's avatar
Mathias Goebel committed
9
 : @author Mathias Göbel
mrodzis's avatar
mrodzis committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 : :)

module namespace cv-test = "https://sade.textgrid.de/ns/cv-test";

import module namespace code-view="http://bdn-edition.de/ns/code-view";

declare namespace test="http://exist-db.org/xquery/xqsuite";


(: Test to test the test :)
declare
    %test:name("FAIL")
    %test:args("<milestone/>")
    %test:assertFalse
    function cv-test:test-basic-000($node as element(*)) {
        false()
};

declare
    %test:name("Basic: no child nodes, no attributes")
    %test:args("<test/>")
    %test:assertXPath("$result[self::xhtml:pre]/xhtml:code/xhtml:span[@class=""hljs-tag""]/child::text()[1] = ""&lt;""")
mrodzis's avatar
mrodzis committed
32

mrodzis's avatar
mrodzis committed
33
34
    %test:args("<test/>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-tag""]/xhtml:span[@class=""hljs-name""]")
mrodzis's avatar
mrodzis committed
35

mrodzis's avatar
mrodzis committed
36
37
    %test:args("<test/>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-name""]/child::text() = ""test""")
mrodzis's avatar
mrodzis committed
38

mrodzis's avatar
mrodzis committed
39
    %test:args("<test/>")
mrodzis's avatar
mrodzis committed
40
    %test:assertXPath("$result//xhtml:span[@class=""hljs-tag""]/child::text()[last()] = ""/&gt;""")
mrodzis's avatar
mrodzis committed
41
42
43
44
45
46
47
48
    function cv-test:test-basic-001($node as element(*)) {
        code-view:main($node)
};


declare
    %test:name("Basic: no child nodes, with attribute(s)")
    %test:args("<test type=""class""/>")
mrodzis's avatar
mrodzis committed
49
50
    %test:assertXPath("$result//xhtml:span[@class=""hljs-attr""]/child::text()[1] = ""type""")

mrodzis's avatar
mrodzis committed
51
52
    %test:args("<test type=""class""/>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-string""]/child::text()[1][contains(., ""class"")]")
mrodzis's avatar
mrodzis committed
53

mrodzis's avatar
mrodzis committed
54
55
    %test:args("<test type=""class""/>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-name""]/following-sibling::text()[1] = "" """)
mrodzis's avatar
mrodzis committed
56

mrodzis's avatar
mrodzis committed
57
58
59
60
61
62
63
64
    function cv-test:test-basic-002($node as element(*)) {
        code-view:main($node)
};


declare
    %test:name("Basic: with child node(s)")
    %test:args("<test><childnode/></test>")
mrodzis's avatar
mrodzis committed
65
    %test:assertXPath("$result//xhtml:span[@class=""hljs-tag""]/xhtml:span[@class=""hljs-name""]/string() = ""childnode""")
mrodzis's avatar
mrodzis committed
66
67

    %test:args("<test><childnode/></test>")
mrodzis's avatar
mrodzis committed
68
    %test:assertXPath("$result//xhtml:span[@class=""hljs-name""][./string() = ""test""]/following::xhtml:span[@class=""hljs-name""][1]/descendant::text() = ""childnode""")
mrodzis's avatar
mrodzis committed
69
70
71
72
73
74
75
76
77
    function cv-test:test-basic-003($node as element(*)) {
        code-view:main($node)
};


declare
    %test:name("Comments: display")
    %test:args("<test><!-- test --></test>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-comment""]")
mrodzis's avatar
mrodzis committed
78

mrodzis's avatar
mrodzis committed
79
80
    %test:args("<test><!-- test --></test>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-comment""]/child::text() = ""&lt;!-- test --&gt;""")
mrodzis's avatar
mrodzis committed
81

mrodzis's avatar
mrodzis committed
82
83
84
85
86
87
88
89
90
    function cv-test:test-basic-004($node as element(*)) {
        code-view:main($node, true(), "hljs-", false())
};


declare
    %test:name("Comments: don't display")
    %test:args("<test><!-- test --></test>")
    %test:assertXPath("not($result//xhtml:span[@class=""hljs-comment""])")
mrodzis's avatar
mrodzis committed
91

mrodzis's avatar
mrodzis committed
92
93
94
95
96
97
98
99
100
    function cv-test:test-basic-005($node as element(*)) {
        code-view:main($node, false(), "hljs-", false())
};


declare
    %test:name("Prefix: change")
    %test:args("<test><!-- test --></test>")
    %test:assertXPath("$result//xhtml:span[@class=""another-prefix-tag""]")
mrodzis's avatar
mrodzis committed
101

mrodzis's avatar
mrodzis committed
102
103
104
105
106
107
108
109
110
111
    function cv-test:test-basic-006($node as element(*)) {
        code-view:main($node, false(), "another-prefix-", false())
};


declare
    %test:name("Indent: true")
    %test:args("<test>
        <childnode/>
    </test>")
mrodzis's avatar
mrodzis committed
112
113
    %test:assertXPath("$result//xhtml:span[@class=""hljs-tag""][1]/following::*[1][self::xhtml:span[@class=""hljs-tag""]]")

mrodzis's avatar
mrodzis committed
114
115
116
117
    %test:args("<test>
        <childnode/>
        </test>")
    %test:assertXPath("not($result//xhtml:span[@class=""hljs-tag""][2]/following::node()[1][matches(., ""[\s]{4}"")])")
mrodzis's avatar
mrodzis committed
118

mrodzis's avatar
mrodzis committed
119
120
121
122
    function cv-test:test-basic-007($node as element(*)) {
        code-view:main($node, false(), "hljs-", true())
};

Mathias Goebel's avatar
Mathias Goebel committed
123

mrodzis's avatar
mrodzis committed
124
125
126
127
declare
    %test:name("Indent: false")
    %test:args("<test>    <childnode/></test>")
    %test:assertXPath("$result//xhtml:span[@class=""hljs-tag""][1]/following::node()[1][matches(., ""[\s]{4}"")]")
mrodzis's avatar
mrodzis committed
128

mrodzis's avatar
mrodzis committed
129
130
131
    function cv-test:test-basic-008($node as element(*)) {
        code-view:main($node, false(), "hljs-", false())
};
Mathias Goebel's avatar
Mathias Goebel committed
132

Mathias Goebel's avatar
Mathias Goebel committed
133
(:~ hljs xml example 1
134
 : @see https://highlightjs.org/?snippet=1&style=14 :)
Mathias Goebel's avatar
Mathias Goebel committed
135
declare
136
    %test:name("hljs example")
Mathias Goebel's avatar
Mathias Goebel committed
137
138
    %test:args('<title>Title</title>')
    %test:assertTrue
mrodzis's avatar
mrodzis committed
139
    %test:assertXPath("$result//xhtml:span[matches(@class, 'hljs')]")
mrodzis's avatar
mrodzis committed
140
141
    function cv-test:test-basic-009($node as element(title)) {
        code-view:main($node)
mrodzis's avatar
mrodzis committed
142
};