1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Test suite for `namespace_support`.
12 module test_namespace_support
is test
14 import sax
::helpers
::namespace_support
16 class TestNamespaceSupport
19 private fun sample
: NamespaceSupport do
20 var subject
= new NamespaceSupport
23 subject
.declare_prefix
("", "http://www.w3.org/1999/xhtml")
24 subject
.declare_prefix
("dc", "http://www.purl.org/dc#")
28 fun test_reset
is test
do
32 assert subject
.xmlns
== subject
.uri
("xml")
33 assert subject
.nsdecl
== subject
.uri
("xmlns")
34 assert subject
.prefix
("http://www.w3.org/1999/xhtml") == null
35 assert 2 == subject
.declared_prefixes
.length
36 assert 2 == subject
.prefixes
.length
39 fun test_push_context_override_default
is test
do
43 subject
.declare_prefix
("", "this:is:a:test")
44 assert "this:is:a:test" == subject
.uri
("")
45 assert "http://www.purl.org/dc#" == subject
.uri
("dc")
46 assert subject
.xmlns
== subject
.uri
("xml")
47 assert subject
.nsdecl
== subject
.uri
("xmlns")
48 assert subject
.prefix
("http://www.w3.org/1999/xhtml") == null
49 assert 1 == subject
.declared_prefixes
.length
50 assert 3 == subject
.prefixes
.length
53 fun test_push_context_override_dc
is test
do
57 subject
.declare_prefix
("dc", "this:is:a:test")
58 assert "this:is:a:test" == subject
.uri
("dc")
59 assert "http://www.w3.org/1999/xhtml" == subject
.uri
("")
60 assert subject
.xmlns
== subject
.uri
("xml")
61 assert subject
.prefix
("http://www.purl.org/dc#") == null
62 assert 1 == subject
.declared_prefixes
.length
63 assert 3 == subject
.prefixes
.length
66 fun test_push_context_undeclare
is test
do
70 subject
.declare_prefix
("dc", "")
71 assert subject
.uri
("dc") == null
72 assert 1 == subject
.declared_prefixes
.length
73 assert 2 == subject
.prefixes
.length
76 fun test_pop_context
is test
do
80 assert subject
.xmlns
== subject
.uri
("xml")
81 assert subject
.prefix
("http://www.w3.org/1999/xhtml") == null
82 assert 2 == subject
.declared_prefixes
.length
83 assert 2 == subject
.prefixes
.length
86 #fun test_declare_prefix # SEE: test_push_context_*
88 fun test_process_name
is test
do
90 var parts
= new Array[String]
92 assert ["http://www.w3.org/1999/xhtml", "p", "p"] == subject
.process_name
("p", parts
, false)
93 assert ["", "p", "p"] == subject
.process_name
("p", parts
, true)
94 assert ["http://www.purl.org/dc#", "title", "dc:title"] == subject
.process_name
("dc:title", parts
, false)
95 assert ["http://www.purl.org/dc#", "title", "dc:title"] == subject
.process_name
("dc:title", parts
, true)
96 assert [subject
.xmlns
, "lang", "xml:lang"] == subject
.process_name
("xml:lang", parts
, false)
97 assert ["http://www.w3.org/1999/xhtml", "p", ":p"] == subject
.process_name
(":p", parts
, false)
98 assert ["", "p", ":p"] == subject
.process_name
(":p", parts
, true)
99 assert subject
.process_name
("foo:bar", parts
, false) == null
100 assert subject
.process_name
("foo:bar", parts
, true) == null
102 assert ["", "p", "p"] == subject
.process_name
("p", parts
, false)
103 assert ["", "p", "p"] == subject
.process_name
("p", parts
, true)
106 fun test_process_name_xmlns
is test
do
108 var parts
= new Array[String].with_capacity
(3)
110 assert [subject
.nsdecl
, "", "xmlns"] == subject
.process_name
("xmlns", parts
, true)
111 assert ["http://www.w3.org/1999/xhtml", "xmlns", "xmlns"] == subject
.process_name
("xmlns", parts
, false)
114 fun test_declare_prefix_illegal
is test
do
117 assert not subject
.declare_prefix
("xml", "http://example.org")
118 assert not subject
.declare_prefix
("xmlns", "http://www2.example.org")
119 assert not subject
.declare_prefix
("foo", subject
.xmlns
)
120 assert not subject
.declare_prefix
("bar", subject
.nsdecl
)
121 assert 2 == subject
.declared_prefixes
.length
124 fun test_uri
is test
do
127 assert "http://www.w3.org/1999/xhtml" == subject
.uri
("")
128 assert "http://www.purl.org/dc#" == subject
.uri
("dc")
129 assert subject
.xmlns
== subject
.uri
("xml")
130 assert subject
.uri
("foo") == null
133 fun test_prefixes
is test
do
134 var res
= sample
.prefixes
136 assert 3 == res
.length
else
137 sys
.stderr
.write
("Expected 3; got {res.length}.\n")
140 assert res
.has
("xml")
141 assert res
.has
("xmlns")
144 fun test_prefix
is test
do
147 assert subject
.prefix
("http://www.w3.org/1999/xhtml") == null
148 assert "dc" == subject
.prefix
("http://www.purl.org/dc#")
149 assert "xml" == subject
.prefix
(subject
.xmlns
)
150 assert subject
.prefix
("https://example.org/serious") == null
153 fun test_prefixes_of
is test
do
155 var res
: Collection[String]
157 assert new Array[String] == subject
.prefixes_of
("http://www.w3.org/1999/xhtml")
158 assert ["dc"] == subject
.prefixes_of
("http://www.purl.org/dc#")
159 assert ["xml"] == subject
.prefixes_of
(subject
.xmlns
)
160 assert new Array[String] == subject
.prefixes_of
("https://example.org/serious")
161 subject
.declare_prefix
("html", "http://www.w3.org/1999/xhtml")
162 assert ["html"] == subject
.prefixes_of
("http://www.w3.org/1999/xhtml")
163 subject
.declare_prefix
("dc2", "http://www.purl.org/dc#")
164 res
= subject
.prefixes_of
("http://www.purl.org/dc#")
165 assert 2 == res
.length
else
166 sys
.stderr
.write
("Expected 2; got {res.length}.\n")
168 assert res
.has_all
(["dc", "dc2"])
171 fun test_declared_prefixes
is test
do
172 var res
= sample
.declared_prefixes
174 assert 2 == res
.length
else
175 sys
.stderr
.write
("Expected 2; got {res.length}.\n")