rdf-rdfxml 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +13 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/etc/doap.nt +47 -0
- data/etc/doap.xml +73 -0
- data/lib/rdf/rdfxml.rb +0 -1
- data/lib/rdf/rdfxml/patches/literal_hacks.rb +19 -8
- data/lib/rdf/rdfxml/patches/seq.rb +1 -1
- data/lib/rdf/rdfxml/patches/uri_hacks.rb +6 -0
- data/lib/rdf/rdfxml/reader.rb +14 -8
- data/lib/rdf/rdfxml/version.rb +1 -1
- data/lib/rdf/rdfxml/writer.rb +13 -18
- data/rdf-rdfxml.gemspec +14 -13
- data/script/console +2 -2
- data/script/parse +49 -0
- data/spec/literal_spec.rb +176 -3
- data/spec/rdf-iso-falure.rb +35 -0
- data/spec/reader_spec.rb +16 -9
- data/spec/uri_spec.rb +47 -34
- data/spec/writer_spec.rb +5 -2
- metadata +30 -11
- data/lib/rdf/rdfxml/patches/rdf_escape.rb +0 -131
- data/spec/rdf_escape_spec.rb +0 -36
data/script/console
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
4
|
|
5
5
|
libs = " -r irb/completion"
|
6
|
-
|
7
|
-
|
6
|
+
RDF = File.dirname(__FILE__) + "/../../rdf/lib"
|
7
|
+
libs << " -I #{RDF}" if File.directory?(RDF)
|
8
8
|
libs << " -r #{File.dirname(__FILE__) + '/../lib/rdf/rdfxml.rb'}"
|
9
9
|
puts "Loading rdf-rdfxml gem"
|
10
10
|
exec "#{irb} #{libs} --simple-prompt"
|
data/script/parse
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby -s
|
2
|
+
require 'rubygems'
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", 'lib'))
|
4
|
+
require 'rdf/rdfxml'
|
5
|
+
require 'getoptlong'
|
6
|
+
|
7
|
+
def parse(input, base)
|
8
|
+
puts RDF::Writer.for($format.to_sym).buffer { |writer|
|
9
|
+
RDF::RDFXML::Reader.new(input, :base_uri => base, :strict => true).each do |statement|
|
10
|
+
writer << statement
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
mode = ARGV.shift
|
16
|
+
raise "Mode must be one of 'parse'" unless mode == "parse"
|
17
|
+
|
18
|
+
$verbose = false
|
19
|
+
$format = :ntriples
|
20
|
+
base_uri = "http://example.com"
|
21
|
+
input = nil
|
22
|
+
|
23
|
+
opts = GetoptLong.new(
|
24
|
+
["--debug", GetoptLong::NO_ARGUMENT],
|
25
|
+
["--verbose", GetoptLong::NO_ARGUMENT],
|
26
|
+
["--quiet", GetoptLong::NO_ARGUMENT],
|
27
|
+
["--format", GetoptLong::REQUIRED_ARGUMENT],
|
28
|
+
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
|
29
|
+
["--uri", GetoptLong::REQUIRED_ARGUMENT]
|
30
|
+
)
|
31
|
+
opts.each do |opt, arg|
|
32
|
+
case opt
|
33
|
+
when '--verbose' then $verbose = true
|
34
|
+
when '--quiet' then $quiet = true
|
35
|
+
when '--debug' then $DEBUG = true
|
36
|
+
when '--execute' then input = arg
|
37
|
+
when '--format' then $format = arg
|
38
|
+
when '--uri' then base_uri = arg
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if ARGV.empty?
|
43
|
+
s = input ? input : $stdin.read
|
44
|
+
parse(StringIO.new(s), base_uri)
|
45
|
+
else
|
46
|
+
ARGV.each do |test_file|
|
47
|
+
parse(File.open(test_file), base_uri)
|
48
|
+
end
|
49
|
+
end
|
data/spec/literal_spec.rb
CHANGED
@@ -22,26 +22,64 @@ describe RDF::Literal do
|
|
22
22
|
describe "with a namespace" do
|
23
23
|
subject {
|
24
24
|
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
25
|
-
:namespaces => {
|
25
|
+
:namespaces => {:dc => RDF::DC.to_s})
|
26
26
|
}
|
27
27
|
|
28
28
|
it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
|
29
29
|
|
30
|
+
describe "as string prefix" do
|
31
|
+
subject {
|
32
|
+
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
33
|
+
:namespaces => {"dc" => RDF::DC.to_s})
|
34
|
+
}
|
35
|
+
|
36
|
+
it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
|
37
|
+
end
|
38
|
+
|
30
39
|
describe "and language" do
|
31
40
|
subject {
|
32
41
|
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
33
|
-
:namespaces => {
|
42
|
+
:namespaces => {:dc => RDF::DC.to_s},
|
34
43
|
:language => :fr)
|
35
44
|
}
|
36
45
|
|
37
46
|
it "should add namespaces and language" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"fr\">bar</dc:sup> baz!" end
|
38
47
|
end
|
39
48
|
|
49
|
+
describe "and node set" do
|
50
|
+
subject {
|
51
|
+
root = Nokogiri::XML.parse(%(<?xml version="1.0" encoding="UTF-8"?>
|
52
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
53
|
+
<html xmlns="http://www.w3.org/1999/xhtml"
|
54
|
+
xmlns:dc="http://purl.org/dc/terms/"
|
55
|
+
xmlns:ex="http://example.org/rdf/"
|
56
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
57
|
+
xmlns:svg="http://www.w3.org/2000/svg">
|
58
|
+
<head profile="http://www.w3.org/1999/xhtml/vocab http://www.w3.org/2005/10/profile">
|
59
|
+
<title>Test 0100</title>
|
60
|
+
</head>
|
61
|
+
<body>
|
62
|
+
<div about="http://www.example.org">
|
63
|
+
<h2 property="ex:example" datatype="rdf:XMLLiteral"><svg:svg/></h2>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
67
|
+
), nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML).root
|
68
|
+
content = root.css("h2").children
|
69
|
+
@new.call(content, :datatype => RDF.XMLLiteral,
|
70
|
+
:namespaces => {
|
71
|
+
:svg => "http://www.w3.org/2000/svg",
|
72
|
+
:dc => "http://purl.org/dc/terms/",
|
73
|
+
})
|
74
|
+
}
|
75
|
+
it "should add namespace" do subject.to_s.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
|
76
|
+
end
|
77
|
+
|
40
78
|
describe "and language with an existing language embedded" do
|
41
79
|
subject {
|
42
80
|
@new.call("foo <dc:sup>bar</dc:sup><dc:sub xml:lang=\"en\">baz</dc:sub>",
|
43
81
|
:datatype => RDF.XMLLiteral,
|
44
|
-
:namespaces => {
|
82
|
+
:namespaces => {:dc => RDF::DC.to_s},
|
45
83
|
:language => :fr)
|
46
84
|
}
|
47
85
|
|
@@ -50,6 +88,15 @@ describe RDF::Literal do
|
|
50
88
|
end
|
51
89
|
|
52
90
|
describe "with a default namespace" do
|
91
|
+
subject {
|
92
|
+
@new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
|
93
|
+
:namespaces => {:__default__ => RDF::DC.to_s})
|
94
|
+
}
|
95
|
+
|
96
|
+
it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "with a default namespace (as empty string)" do
|
53
100
|
subject {
|
54
101
|
@new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
|
55
102
|
:namespaces => {"" => RDF::DC.to_s})
|
@@ -57,5 +104,131 @@ describe RDF::Literal do
|
|
57
104
|
|
58
105
|
it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
|
59
106
|
end
|
107
|
+
|
108
|
+
context "rdfcore tests" do
|
109
|
+
context "rdfms-xml-literal-namespaces" do
|
110
|
+
it "should reproduce test001" do
|
111
|
+
l = @new.call("
|
112
|
+
<html:h1>
|
113
|
+
<b>John</b>
|
114
|
+
</html:h1>
|
115
|
+
",
|
116
|
+
:datatype => RDF.XMLLiteral,
|
117
|
+
:namespaces => {
|
118
|
+
"" => "http://www.w3.org/1999/xhtml",
|
119
|
+
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
120
|
+
"html" => "http://NoHTML.example.org",
|
121
|
+
"my" => "http://my.example.org/",
|
122
|
+
})
|
123
|
+
|
124
|
+
l.to_s.should == "\n <html:h1 xmlns:html=\"http://NoHTML.example.org\">\n <b xmlns=\"http://www.w3.org/1999/xhtml\">John</b>\n </html:h1>\n "
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should reproduce test002" do
|
128
|
+
l = @new.call("
|
129
|
+
Ramifications of
|
130
|
+
<apply>
|
131
|
+
<power/>
|
132
|
+
<apply>
|
133
|
+
<plus/>
|
134
|
+
<ci>a</ci>
|
135
|
+
<ci>b</ci>
|
136
|
+
</apply>
|
137
|
+
<cn>2</cn>
|
138
|
+
</apply>
|
139
|
+
to World Peace
|
140
|
+
",
|
141
|
+
:datatype => RDF.XMLLiteral,
|
142
|
+
:namespaces => {
|
143
|
+
"" => "http://www.w3.org/TR/REC-mathml",
|
144
|
+
})
|
145
|
+
|
146
|
+
l.to_s.should == "\n Ramifications of\n <apply xmlns=\"http://www.w3.org/TR/REC-mathml\">\n <power></power>\n <apply>\n\t<plus></plus>\n\t<ci>a</ci>\n\t<ci>b</ci>\n </apply>\n <cn>2</cn>\n </apply>\n to World Peace\n "
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "rdfms-xmllang" do
|
151
|
+
it "should reproduce test001" do
|
152
|
+
l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => nil)
|
153
|
+
|
154
|
+
l.to_s.should == "chat"
|
155
|
+
end
|
156
|
+
it "should reproduce test002" do
|
157
|
+
l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => :fr)
|
158
|
+
|
159
|
+
l.to_s.should == "chat"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "xml-canon" do
|
164
|
+
it "should reproduce test001" do
|
165
|
+
l = @new.call("<br />", :datatype => RDF.XMLLiteral)
|
166
|
+
|
167
|
+
l.to_s.should == "<br></br>"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "rdfa tests" do
|
173
|
+
it "should reproduce test 0011: XMLLiteral" do
|
174
|
+
l = @new.call("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
|
175
|
+
:datatype => RDF.XMLLiteral,
|
176
|
+
:namespaces => {"" => "http://www.w3.org/1999/xhtml"})
|
177
|
+
|
178
|
+
l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should reproduce test 0092: Tests XMLLiteral content with explicit @datatype" do
|
182
|
+
l = @new.call(%(E = mc<sup>2</sup>: The Most Urgent Problem of Our Time<),
|
183
|
+
:datatype => RDF.XMLLiteral,
|
184
|
+
:namespaces => {"" => "http://www.w3.org/1999/xhtml"})
|
185
|
+
|
186
|
+
l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should reproduce test 0100: XMLLiteral with explicit namespace" do
|
190
|
+
l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
191
|
+
:datatype => RDF.XMLLiteral,
|
192
|
+
:namespaces => {
|
193
|
+
"" => "http://www.w3.org/1999/xhtml",
|
194
|
+
"svg" => "http://www.w3.org/2000/svg",
|
195
|
+
})
|
196
|
+
|
197
|
+
l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should reproduce 0101: XMLLiteral with explicit namespace and xml:lang" do
|
201
|
+
l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
202
|
+
:datatype => RDF.XMLLiteral, :language => :fr,
|
203
|
+
:namespaces => {
|
204
|
+
"" => "http://www.w3.org/1999/xhtml",
|
205
|
+
"svg" => "http://www.w3.org/2000/svg",
|
206
|
+
})
|
207
|
+
|
208
|
+
l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should reproduce test 0102: XMLLiteral with explicit namespace and xml:lang; not overwriting existing langs" do
|
212
|
+
l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg xml:lang="hu"><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
213
|
+
:datatype => RDF.XMLLiteral, :language => :fr,
|
214
|
+
:namespaces => {
|
215
|
+
"" => "http://www.w3.org/1999/xhtml",
|
216
|
+
"svg" => "http://www.w3.org/2000/svg",
|
217
|
+
})
|
218
|
+
|
219
|
+
l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"hu\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should reproduce test 0103: XMLLiteral with explicit namespace; not overwriting local namespaces" do
|
223
|
+
l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg xmlns="http://www.w3.org/2000/svg"><rect width="200" height="100"/></svg>),
|
224
|
+
:datatype => RDF.XMLLiteral,
|
225
|
+
:namespaces => {
|
226
|
+
"" => "http://www.w3.org/1999/xhtml",
|
227
|
+
"svg" => "http://www.w3.org/2000/svg",
|
228
|
+
})
|
229
|
+
|
230
|
+
l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg xmlns=\"http://www.w3.org/2000/svg\"><rect height=\"100\" width=\"200\"></rect></svg>"
|
231
|
+
end
|
232
|
+
end
|
60
233
|
end if defined?(::Nokogiri)
|
61
234
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rdf'
|
4
|
+
require 'rdf/rdfxml'
|
5
|
+
require 'rdf/ntriples'
|
6
|
+
require 'rdf/isomorphic'
|
7
|
+
|
8
|
+
s1 = %(<?xml version="1.0"?>
|
9
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
10
|
+
xmlns:eg="http://example.org/">
|
11
|
+
<rdf:Description rdf:about="http://example.org/foo">
|
12
|
+
<eg:bar rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</eg:bar>
|
13
|
+
<eg:baz rdf:datatype="http://www.w3.org/2001/XMLSchema#integer" xml:lang="fr">10</eg:baz>
|
14
|
+
</rdf:Description>
|
15
|
+
</rdf:RDF>)
|
16
|
+
|
17
|
+
s2 = %(<http://example.org/foo> <http://example.org/bar> "10"^^<http://www.w3.org/2001/XMLSchema#integer> .
|
18
|
+
<http://example.org/foo> <http://example.org/baz> "10"^^<http://www.w3.org/2001/XMLSchema#integer> .
|
19
|
+
)
|
20
|
+
|
21
|
+
g1 = RDF::Graph.new
|
22
|
+
RDF::RDFXML::Reader.new(s1).each {|s| g1 << s}
|
23
|
+
|
24
|
+
g1.each do |s|
|
25
|
+
puts s.object.datatype.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
res1 = g1.map(&:to_ntriples).join("")
|
29
|
+
|
30
|
+
g2 = RDF::Graph.new
|
31
|
+
RDF::NTriples::Reader.new(s2).each {|s| g2 << s}
|
32
|
+
|
33
|
+
puts g1.isomorphic_with?(g2) ? "graphs isomorphic" : "graphs non-isomorphic"
|
34
|
+
|
35
|
+
puts res1 == s2 ? "strings equivalent" : "strings differ"
|
data/spec/reader_spec.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
+
require 'rdf/spec/reader'
|
3
4
|
|
4
5
|
# w3c test suite: http://www.w3.org/TR/rdf-testcases/
|
5
6
|
|
6
7
|
describe "RDF::RDFXML::Reader" do
|
8
|
+
before :each do
|
9
|
+
@reader = RDF::RDFXML::Reader
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_behave_like RDF_Reader
|
13
|
+
|
7
14
|
context "discovery" do
|
8
15
|
{
|
9
16
|
"rdf" => RDF::Reader.for(:rdf),
|
@@ -18,7 +25,7 @@ describe "RDF::RDFXML::Reader" do
|
|
18
25
|
"application/rdf+xml" => RDF::Reader.for(:content_type => "application/rdf+xml"),
|
19
26
|
}.each_pair do |label, format|
|
20
27
|
it "should discover '#{label}'" do
|
21
|
-
format.should ==
|
28
|
+
format.should == @reader
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -45,20 +52,20 @@ EOF
|
|
45
52
|
|
46
53
|
it "should yield reader" do
|
47
54
|
inner = mock("inner")
|
48
|
-
inner.should_receive(:called).with(
|
49
|
-
|
55
|
+
inner.should_receive(:called).with(@reader)
|
56
|
+
@reader.new(@sampledoc) do |reader|
|
50
57
|
inner.called(reader.class)
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
61
|
it "should return reader" do
|
55
|
-
|
62
|
+
@reader.new(@sampledoc).should be_a(@reader)
|
56
63
|
end
|
57
64
|
|
58
65
|
it "should yield statements" do
|
59
66
|
inner = mock("inner")
|
60
67
|
inner.should_receive(:called).with(RDF::Statement).twice
|
61
|
-
|
68
|
+
@reader.new(@sampledoc).each_statement do |statement|
|
62
69
|
inner.called(statement.class)
|
63
70
|
end
|
64
71
|
end
|
@@ -66,7 +73,7 @@ EOF
|
|
66
73
|
it "should yield triples" do
|
67
74
|
inner = mock("inner")
|
68
75
|
inner.should_receive(:called).with(RDF::URI, RDF::URI, RDF::Literal).twice
|
69
|
-
|
76
|
+
@reader.new(@sampledoc).each_triple do |subject, predicate, object|
|
70
77
|
inner.called(subject.class, predicate.class, object.class)
|
71
78
|
end
|
72
79
|
end
|
@@ -387,7 +394,7 @@ EOF
|
|
387
394
|
t.run_test do |rdf_string|
|
388
395
|
t.debug = []
|
389
396
|
g = RDF::Graph.new
|
390
|
-
|
397
|
+
@reader.new(rdf_string,
|
391
398
|
:base_uri => t.about,
|
392
399
|
:strict => true,
|
393
400
|
:debug => t.debug).each do |statement|
|
@@ -408,7 +415,7 @@ EOF
|
|
408
415
|
t.run_test do |rdf_string, parser|
|
409
416
|
lambda do
|
410
417
|
g = RDF::Graph.new
|
411
|
-
|
418
|
+
@reader.new(rdf_string,
|
412
419
|
:base_uri => t.about,
|
413
420
|
:strict => true).each do |statement|
|
414
421
|
g << statement
|
@@ -424,7 +431,7 @@ EOF
|
|
424
431
|
def parse(input, options)
|
425
432
|
@debug = []
|
426
433
|
graph = RDF::Graph.new
|
427
|
-
|
434
|
+
@reader.new(input, options.merge(:debug => @debug)).each do |statement|
|
428
435
|
graph << statement
|
429
436
|
end
|
430
437
|
graph
|
data/spec/uri_spec.rb
CHANGED
@@ -17,43 +17,56 @@ describe RDF::URI do
|
|
17
17
|
subject.join(RDF::URI.new("foo#bar")).to_s.should == "http://example.org/foo#bar"
|
18
18
|
end
|
19
19
|
|
20
|
-
describe "
|
20
|
+
describe "utf-8 escaped" do
|
21
21
|
{
|
22
|
-
%
|
23
|
-
%
|
24
|
-
%
|
25
|
-
%
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
%w(http://foo
|
36
|
-
|
37
|
-
%w(http://foo/
|
38
|
-
%w(http://foo
|
39
|
-
|
40
|
-
%w(http://foo/
|
41
|
-
|
42
|
-
%w(http://foo/
|
43
|
-
%w(http://foo/
|
44
|
-
|
45
|
-
%w(http://foo
|
46
|
-
|
47
|
-
%w(http://foo
|
48
|
-
%w(http://foo
|
49
|
-
|
50
|
-
%w(http://foo/bar
|
51
|
-
|
52
|
-
%w(http://foo/bar
|
53
|
-
%w(http://foo/bar
|
22
|
+
%(http://a/D%C3%BCrst) => %(<http://a/D%C3%BCrst>),
|
23
|
+
%(http://a/D\u00FCrst) => %(<http://a/D\\u00FCrst>),
|
24
|
+
%(http://b/Dürst) => %(<http://b/D\\u00FCrst>),
|
25
|
+
%(http://a/\u{15678}another) => %(<http://a/\\U00015678another>),
|
26
|
+
}.each_pair do |uri, dump|
|
27
|
+
it "should dump #{uri} as #{dump}" do
|
28
|
+
RDF::URI.new(uri).to_ntriples.should == dump
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end if defined?(::Encoding) # Only works properly in Ruby 1.9
|
32
|
+
|
33
|
+
describe "join" do
|
34
|
+
{
|
35
|
+
%w(http://foo ) => "<http://foo>",
|
36
|
+
%w(http://foo a) => "<http://foo/a>",
|
37
|
+
%w(http://foo /a) => "<http://foo/a>",
|
38
|
+
%w(http://foo #a) => "<http://foo#a>",
|
39
|
+
|
40
|
+
%w(http://foo/ ) => "<http://foo/>",
|
41
|
+
%w(http://foo/ a) => "<http://foo/a>",
|
42
|
+
%w(http://foo/ /a) => "<http://foo/a>",
|
43
|
+
%w(http://foo/ #a) => "<http://foo/#a>",
|
44
|
+
|
45
|
+
%w(http://foo# ) => "<http://foo#>",
|
46
|
+
%w(http://foo# a) => "<http://foo/a>",
|
47
|
+
%w(http://foo# /a) => "<http://foo/a>",
|
48
|
+
%w(http://foo# #a) => "<http://foo#a>",
|
49
|
+
|
50
|
+
%w(http://foo/bar ) => "<http://foo/bar>",
|
51
|
+
%w(http://foo/bar a) => "<http://foo/a>",
|
52
|
+
%w(http://foo/bar /a) => "<http://foo/a>",
|
53
|
+
%w(http://foo/bar #a) => "<http://foo/bar#a>",
|
54
|
+
|
55
|
+
%w(http://foo/bar/ ) => "<http://foo/bar/>",
|
56
|
+
%w(http://foo/bar/ a) => "<http://foo/bar/a>",
|
57
|
+
%w(http://foo/bar/ /a) => "<http://foo/a>",
|
58
|
+
%w(http://foo/bar/ #a) => "<http://foo/bar/#a>",
|
59
|
+
|
60
|
+
%w(http://foo/bar# ) => "<http://foo/bar#>",
|
61
|
+
%w(http://foo/bar# a) => "<http://foo/a>",
|
62
|
+
%w(http://foo/bar# /a) => "<http://foo/a>",
|
63
|
+
%w(http://foo/bar# #a) => "<http://foo/bar#a>",
|
64
|
+
|
65
|
+
%w(http://foo/bar# #D%C3%BCrst) => "<http://foo/bar#D%C3%BCrst>",
|
66
|
+
%w(http://foo/bar# #Dürst) => "<http://foo/bar#D\\u00FCrst>",
|
54
67
|
}.each_pair do |input, result|
|
55
68
|
it "should create <#{result}> from <#{input[0]}> and '#{input[1]}'" do
|
56
|
-
RDF::URI.new(input[0]).join(input[1].to_s).
|
69
|
+
RDF::URI.new(input[0]).join(input[1].to_s).to_ntriples.should == result
|
57
70
|
end
|
58
71
|
end
|
59
72
|
end
|