rdf-rdfa 0.3.4.2 → 0.3.5.1

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/script/tc DELETED
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
4
- require 'rdf/rdfa'
5
- require 'sparql/grammar'
6
- require File.expand_path(File.join(File.dirname(__FILE__), "..", 'spec', 'spec_helper'))
7
- require File.expand_path(File.join(File.dirname(__FILE__), "..", 'spec', 'test_helper'))
8
- require 'getoptlong'
9
-
10
- def run_tc(tc, options)
11
- input_uri = tc.input(options[:host_language], options[:version])
12
- results_uri = tc.results(options[:host_language], options[:version])
13
-
14
- STDOUT.write "run #{tc.name}"
15
-
16
- if options[:verbose]
17
- puts("\nTestCase: #{tc.inspect}")
18
- puts("\nInput:\n" + Kernel.open(input_uri) {|f| f.read})
19
- puts("\nQuery:\n" + Kernel.open(results_uri) {|f| f.read})
20
- end
21
-
22
- pg = RDF::Graph.new if options[:processor_graph]
23
-
24
- begin
25
- reader = RDF::RDFa::Reader.new(Kernel.open(input_uri),
26
- :base_uri => input_uri,
27
- :validate => options[:validate],
28
- :processor_graph => pg,
29
- :version => options[:version])
30
-
31
- graph = RDF::Graph.new << reader
32
- rescue Exception => e
33
- puts "#{"exception:" unless options[:quiet]}: #{e}"
34
- if options[:quiet]
35
- return
36
- else
37
- raise
38
- end
39
- end
40
-
41
- puts("\nResult:\n" + graph.dump(options[:format])) unless options[:quiet]
42
-
43
- begin
44
- result = SPARQL::Grammar.parse(Kernel.open(results_uri)).execute(graph)
45
- rescue Exception => e
46
- puts "#{"exception:" unless options[:quiet]}: #{e}"
47
- return
48
- end
49
- puts "#{"test result:" unless options[:quiet]} #{(result == (tc.expectedResults || true)) ? 'ok' : 'fail'}"
50
-
51
- if pg && !options[:quiet]
52
- puts "\nProcessor Graph:\n"
53
- puts pg.inspect
54
- RDF::Writer.for(options[:format]).new do |writer|
55
- writer << pg
56
- end
57
- end
58
- end
59
-
60
- options = {
61
- :verbose => false,
62
- :quite => false,
63
- :validate => false,
64
- :format => :ntriples,
65
- :processor_graph => nil,
66
- :host_language => "xhtml1",
67
- :version => "rdfa1.1"
68
- }
69
-
70
- opts = GetoptLong.new(
71
- ["--help", "-?", GetoptLong::NO_ARGUMENT],
72
- ["--dbg", GetoptLong::NO_ARGUMENT],
73
- ["--format", GetoptLong::REQUIRED_ARGUMENT],
74
- ["--host-language", "-h", GetoptLong::OPTIONAL_ARGUMENT],
75
- ["--processor-graph", GetoptLong::NO_ARGUMENT],
76
- ["--quiet", GetoptLong::NO_ARGUMENT],
77
- ["--validate", GetoptLong::NO_ARGUMENT],
78
- ["--verbose", GetoptLong::NO_ARGUMENT],
79
- ["--version", "-v", GetoptLong::OPTIONAL_ARGUMENT]
80
- )
81
-
82
- def help(options)
83
- puts "Usage: #{$0} [options] [test-number ...]"
84
- puts "Options:"
85
- puts " --dump: Dump raw output, otherwise serialize to Ruby"
86
- puts " --debug: Display detailed debug output"
87
- puts " --format: Format for output, defaults to #{options[:format].inspect}"
88
- puts " --host-language: Run for specified host language, defaults to #{options[:host_language]}"
89
- puts " --processor-graph: Output processor graph"
90
- puts " --quiet: Minimal output"
91
- puts " --validate: Validate input"
92
- puts " --verbose: Verbose processing"
93
- puts " --version: Version of processor to use (rdf1.0, rdf1.1). Defaults to #{options[:version]}"
94
- puts " --help,-?: This message"
95
- exit(0)
96
- end
97
-
98
- opts.each do |opt, arg|
99
- case opt
100
- when '--help' then help(options)
101
- when '--verbose' then options[:verbose] = true
102
- when '--quiet' then options[:quiet] = true
103
- when '--dbg' then ::RDF::RDFa::debug = true
104
- when '--format' then options[:format] = arg.to_sym
105
- when '--processor-graph' then options[:processor_graph] = true
106
- when '--host-language' then options[:host_language] = arg
107
- when '--version' then options[:version] = arg
108
- when '--validate' then options[:validate] = true
109
- end
110
- end
111
-
112
- Fixtures::TestCase.for_specific(options[:host_language], options[:version]) do |tc|
113
- next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
114
- run_tc(tc, options)
115
- end
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env sh
2
- rsync -azv doc/yard/ gkellogg@rubyforge.org:/var/www/gforge-projects/rdf/rdfa/
@@ -1 +0,0 @@
1
- /uri-cache/
@@ -1,244 +0,0 @@
1
- # coding: utf-8
2
- $:.unshift "."
3
- require File.join(File.dirname(__FILE__), 'spec_helper')
4
-
5
- describe RDF::Literal do
6
- require 'nokogiri' rescue nil
7
-
8
- before :each do
9
- @new = Proc.new { |*args| RDF::Literal.new(*args) }
10
- end
11
-
12
- describe "XML Literal" do
13
- describe "with no namespace" do
14
- subject { @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral) }
15
- it "should return input" do subject.to_s.should == "foo <sup>bar</sup> baz!" end
16
-
17
- it "should be equal if they have the same contents" do
18
- should == @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral)
19
- end
20
- end
21
-
22
- describe "with a namespace" do
23
- subject {
24
- @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
25
- :namespaces => {:dc => RDF::DC.to_s})
26
- }
27
-
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
-
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
-
39
- describe "and language" do
40
- subject {
41
- @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
42
- :namespaces => {:dc => RDF::DC.to_s},
43
- :language => :fr)
44
- }
45
-
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
47
- end
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\" xmlns:dc=\"http://purl.org/dc/terms/\"></svg:svg>" end
76
- end
77
-
78
- describe "and language with an existing language embedded" do
79
- subject {
80
- @new.call("foo <dc:sup>bar</dc:sup><dc:sub xml:lang=\"en\">baz</dc:sub>",
81
- :datatype => RDF.XMLLiteral,
82
- :namespaces => {:dc => RDF::DC.to_s},
83
- :language => :fr)
84
- }
85
-
86
- 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><dc:sub xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"en\">baz</dc:sub>" end
87
- end
88
- end
89
-
90
- describe "with a default namespace" do
91
- subject {
92
- @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
93
- :namespaces => {"" => 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
100
- subject {
101
- @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
102
- :namespaces => {"" => RDF::DC.to_s})
103
- }
104
-
105
- it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
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
- pending do
125
- 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 "
126
- end
127
- end
128
-
129
- it "should reproduce test002" do
130
- l = @new.call("
131
- Ramifications of
132
- <apply>
133
- <power/>
134
- <apply>
135
- <plus/>
136
- <ci>a</ci>
137
- <ci>b</ci>
138
- </apply>
139
- <cn>2</cn>
140
- </apply>
141
- to World Peace
142
- ",
143
- :datatype => RDF.XMLLiteral,
144
- :namespaces => {
145
- "" => "http://www.w3.org/TR/REC-mathml",
146
- })
147
-
148
- 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 "
149
- end
150
- end
151
-
152
- context "rdfms-xmllang" do
153
- it "should reproduce test001" do
154
- l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => nil)
155
-
156
- l.to_s.should == "chat"
157
- end
158
- it "should reproduce test002" do
159
- l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => :fr)
160
-
161
- l.to_s.should == "chat"
162
- end
163
- end
164
-
165
- context "xml-canon" do
166
- it "should reproduce test001" do
167
- l = @new.call("<br />", :datatype => RDF.XMLLiteral)
168
-
169
- l.to_s.should == "<br></br>"
170
- end
171
- end
172
- end
173
-
174
- context "rdfa tests" do
175
- it "should reproduce test 0011: XMLLiteral" do
176
- l = @new.call("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
177
- :datatype => RDF.XMLLiteral,
178
- :namespaces => {"" => "http://www.w3.org/1999/xhtml"})
179
-
180
- l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
181
- end
182
-
183
- it "should reproduce test 0092: Tests XMLLiteral content with explicit @datatype" do
184
- l = @new.call(%(E = mc<sup>2</sup>: The Most Urgent Problem of Our Time<),
185
- :datatype => RDF.XMLLiteral,
186
- :namespaces => {"" => "http://www.w3.org/1999/xhtml"})
187
-
188
- l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
189
- end
190
-
191
- it "should reproduce test 0100: XMLLiteral with explicit namespace" do
192
- 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>),
193
- :datatype => RDF.XMLLiteral,
194
- :namespaces => {
195
- "" => "http://www.w3.org/1999/xhtml",
196
- "svg" => "http://www.w3.org/2000/svg",
197
- })
198
-
199
- pending do
200
- 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>"
201
- end
202
- end
203
-
204
- it "should reproduce 0101: XMLLiteral with explicit namespace and xml:lang" do
205
- 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>),
206
- :datatype => RDF.XMLLiteral, :language => :fr,
207
- :namespaces => {
208
- "" => "http://www.w3.org/1999/xhtml",
209
- "svg" => "http://www.w3.org/2000/svg",
210
- })
211
-
212
- pending do
213
- 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>"
214
- end
215
- end
216
-
217
- it "should reproduce test 0102: XMLLiteral with explicit namespace and xml:lang; not overwriting existing langs" do
218
- 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>),
219
- :datatype => RDF.XMLLiteral, :language => :fr,
220
- :namespaces => {
221
- "" => "http://www.w3.org/1999/xhtml",
222
- "svg" => "http://www.w3.org/2000/svg",
223
- })
224
-
225
- pending do
226
- 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>"
227
- end
228
- end
229
-
230
- it "should reproduce test 0103: XMLLiteral with explicit namespace; not overwriting local namespaces" do
231
- 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>),
232
- :datatype => RDF.XMLLiteral,
233
- :namespaces => {
234
- "" => "http://www.w3.org/1999/xhtml",
235
- "svg" => "http://www.w3.org/2000/svg",
236
- })
237
-
238
- pending do
239
- 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>"
240
- end
241
- end
242
- end
243
- end if defined?(::Nokogiri)
244
- end
@@ -1,108 +0,0 @@
1
- require 'rspec/matchers'
2
- require 'sparql/grammar'
3
-
4
- RSpec::Matchers.define :have_xpath do |xpath, value|
5
- match do |actual|
6
- @doc = Nokogiri::XML.parse(actual)
7
- @doc.should be_a(Nokogiri::XML::Document)
8
- @doc.root.should be_a(Nokogiri::XML::Element)
9
- @namespaces = @doc.namespaces.merge("xhtml" => "http://www.w3.org/1999/xhtml", "xml" => "http://www.w3.org/XML/1998/namespace")
10
- case value
11
- when false
12
- @doc.root.at_xpath(xpath, @namespaces).should be_nil
13
- when true
14
- @doc.root.at_xpath(xpath, @namespaces).should_not be_nil
15
- when Array
16
- @doc.root.at_xpath(xpath, @namespaces).to_s.split(" ").should include(*value)
17
- when Regexp
18
- @doc.root.at_xpath(xpath, @namespaces).to_s.should =~ value
19
- else
20
- @doc.root.at_xpath(xpath, @namespaces).to_s.should == value
21
- end
22
- end
23
-
24
- failure_message_for_should do |actual|
25
- msg = "expected that #{xpath.inspect} would be #{value.inspect} in:\n" + actual.to_s
26
- msg += "was: #{@doc.root.at_xpath(xpath, @namespaces)}"
27
- end
28
- end
29
-
30
- def normalize(graph)
31
- case graph
32
- when RDF::Graph then graph
33
- when IO, StringIO
34
- RDF::Graph.new.load(graph, :base_uri => @info.about)
35
- else
36
- # Figure out which parser to use
37
- g = RDF::Graph.new
38
- reader_class = detect_format(graph)
39
- reader_class.new(graph, :base_uri => @info.about).each {|s| g << s}
40
- g
41
- end
42
- end
43
-
44
- Info = Struct.new(:about, :information, :trace, :compare, :inputDocument, :outputDocument)
45
-
46
- RSpec::Matchers.define :be_equivalent_graph do |expected, info|
47
- match do |actual|
48
- @info = if info.respond_to?(:about)
49
- info
50
- elsif info.is_a?(Hash)
51
- identifier = info[:identifier] || expected.is_a?(RDF::Graph) ? expected.context : info[:about]
52
- trace = info[:trace]
53
- trace = trace.join("\n") if trace.is_a?(Array)
54
- Info.new(identifier, info[:information] || "", trace, info[:compare])
55
- else
56
- Info.new(expected.is_a?(RDF::Graph) ? expected.context : info, info.to_s)
57
- end
58
- @expected = normalize(expected)
59
- @actual = normalize(actual)
60
- @actual.isomorphic_with?(@expected)
61
- end
62
-
63
- failure_message_for_should do |actual|
64
- info = @info.respond_to?(:information) ? @info.information : @info.inspect
65
- if @expected.is_a?(RDF::Graph) && @actual.size != @expected.size
66
- "Graph entry count differs:\nexpected: #{@expected.size}\nactual: #{@actual.size}"
67
- elsif @expected.is_a?(Array) && @actual.size != @expected.length
68
- "Graph entry count differs:\nexpected: #{@expected.length}\nactual: #{@actual.size}"
69
- else
70
- "Graph differs"
71
- end +
72
- "\n#{info + "\n" unless info.empty?}" +
73
- (@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") +
74
- (@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") +
75
- "Unsorted Expected:\n#{@expected.dump(:ntriples)}" +
76
- "Unsorted Results:\n#{@actual.dump(:ntriples)}" +
77
- (@info.trace ? "\nDebug:\n#{@info.trace}" : "")
78
- end
79
- end
80
-
81
- RSpec::Matchers.define :pass_query do |expected, info|
82
- match do |actual|
83
- @expected = expected.read
84
- @expected = @expected.force_encoding("utf-8") if @expected.respond_to?(:force_encoding)
85
- query = SPARQL::Grammar.parse(@expected)
86
- actual = actual.force_encoding("utf-8") if actual.respond_to?(:force_encoding)
87
- @results = query.execute(actual)
88
-
89
- @results.should == info.expectedResults
90
- end
91
-
92
- failure_message_for_should do |actual|
93
- information = info.respond_to?(:information) ? info.information : ""
94
- "#{information + "\n" unless information.empty?}" +
95
- if @results.nil?
96
- "Query failed to return results"
97
- elsif !@results.is_a?(RDF::Literal::Boolean)
98
- "Query returned non-boolean results"
99
- elsif info.expectedResults
100
- "Query returned false"
101
- else
102
- "Query returned true (expected false)"
103
- end +
104
- "\n#{@expected}" +
105
- "\nResults:\n#{@actual.dump(:ntriples)}" +
106
- "\nDebug:\n#{info.trace}"
107
- end
108
- end