-
Notifications
You must be signed in to change notification settings - Fork 43
/
escape-for-regex.xspec
88 lines (78 loc) · 3.19 KB
/
escape-for-regex.xspec
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
88
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:functx="http://www.functx.com"
stylesheet="escape-for-regex.xslt">
<!--
This is a sample test suite written in the XSpec language. It
tests the stylesheet escape-for-regex.xslt. It contains three
main scenarios (the second of which in turn contains two sub-
scenarios).
See http://code.google.com/p/xspec/wiki/GettingStarted for the
full tutorial it is part of.
-->
<!--
This is a very simple scenario, checking the return value of a
function call (the param does not contain any character to be
escaped).
-->
<x:scenario label="No escaping">
<!-- call the function with the string 'Hello' -->
<x:call function="functx:escape-for-regex">
<x:param select="'Hello'"/>
</x:call>
<!-- check the result -->
<x:expect label="Must not be escaped at all" select="'Hello'"/>
</x:scenario>
<!--
This scenario demonstrates:
(1) how to test a function (named templates can be simliarly tested)
(2) that scenarios can be nested
(3) a test can have multiple expectations.
-->
<x:scenario label="Test simple patterns">
<!-- first sub-scenario -->
<x:scenario label="When encountering parentheses">
<!-- call the function -->
<x:call function="functx:escape-for-regex">
<x:param name="arg" select="'(Hello)'"/>
</x:call>
<!-- check the result -->
<x:expect label="escape them." select="'\(Hello\)'"/>
</x:scenario>
<!-- second sub-scenario -->
<x:scenario label="When encountering a whitespace character class">
<!-- call the function with another parameter -->
<x:call function="functx:escape-for-regex">
<x:param name="arg" select="'\sHello'"/>
</x:call>
<!-- check the result -->
<x:expect label="escape the backslash" select="'\\sHello'"/>
<!-- we can have several checks on the same result -->
<x:expect label="result should have one more character than source"
test="string-length(.) = 8"/>
</x:scenario>
</x:scenario>
<!--
This scenario demonstrates how to test a matching template.
-->
<x:scenario label="When processing a list of phrases">
<!-- apply template rules to this element -->
<x:context>
<phrases>
<phrase>Hello!</phrase>
<phrase>Goodbye!</phrase>
<phrase>(So long!)</phrase>
</phrases>
</x:context>
<!-- check the result -->
<x:expect label="All phrase elements should remain"
test="count(phrases/phrase) = 3"/>
<x:expect label="Strings should be escaped and status attributes should be added">
<phrases>
<phrase status="same">Hello!</phrase>
<phrase status="same">Goodbye!</phrase>
<phrase status="changed">\(So long!\)</phrase>
</phrases>
</x:expect>
</x:scenario>
</x:description>