forked from ruby/rexml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_xpath.rb
More file actions
115 lines (93 loc) · 3.05 KB
/
Copy pathtest_xpath.rb
File metadata and controls
115 lines (93 loc) · 3.05 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# frozen_string_literal: false
require "test/unit"
require "rexml/parsers/xpathparser"
module REXMLTests
class TestParserXPathParser < Test::Unit::TestCase
sub_test_case("#abbreviate") do
def abbreviate(xpath)
parser = REXML::Parsers::XPathParser.new
parser.abbreviate(xpath)
end
def test_document
assert_equal("/",
abbreviate("/"))
end
def test_descendant_or_self_only
assert_equal("//",
abbreviate("/descendant-or-self::node()/"))
end
def test_descendant_or_self_absolute
assert_equal("//a/b",
abbreviate("/descendant-or-self::node()/a/b"))
end
def test_descendant_or_self_relative
assert_equal("a//b",
abbreviate("a/descendant-or-self::node()/b"))
end
def test_descendant_or_self_not_node
assert_equal("/descendant-or-self::text()",
abbreviate("/descendant-or-self::text()"))
end
def test_self_absolute
assert_equal("/a/./b",
abbreviate("/a/self::node()/b"))
end
def test_self_relative
assert_equal("a/./b",
abbreviate("a/self::node()/b"))
end
def test_self_not_node
assert_equal("/self::text()",
abbreviate("/self::text()"))
end
def test_parent_absolute
assert_equal("/a/../b",
abbreviate("/a/parent::node()/b"))
end
def test_parent_relative
assert_equal("a/../b",
abbreviate("a/parent::node()/b"))
end
def test_parent_not_node
assert_equal("/a/parent::text()",
abbreviate("/a/parent::text()"))
end
def test_any_absolute
assert_equal("/*/a",
abbreviate("/*/a"))
end
def test_any_relative
assert_equal("a/*/b",
abbreviate("a/*/b"))
end
def test_following_sibling_absolute
assert_equal("/following-sibling::a/b",
abbreviate("/following-sibling::a/b"))
end
def test_following_sibling_relative
assert_equal("a/following-sibling::b/c",
abbreviate("a/following-sibling::b/c"))
end
def test_predicate_index
assert_equal("a[5]/b",
abbreviate("a[5]/b"))
end
def test_attribute_relative
assert_equal("a/@b",
abbreviate("a/attribute::b"))
end
def test_filter_attribute
assert_equal("a/b[@i = 1]/c",
abbreviate("a/b[attribute::i=1]/c"))
end
def test_filter_string_single_quote
assert_equal("a/b[@name = \"single ' quote\"]/c",
abbreviate("a/b[attribute::name=\"single ' quote\"]/c"))
end
def test_filter_string_double_quote
assert_equal("a/b[@name = 'double \" quote']/c",
abbreviate("a/b[attribute::name='double \" quote']/c"))
end
end
end
end