rdf-spec 1.0.9 → 1.1.0.p1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/AUTHORS +1 -1
- data/README +16 -23
- data/VERSION +1 -1
- data/etc/bendiken.nq +8 -8
- data/etc/bendiken.nt +8 -0
- data/etc/bendiken.ttl +17 -0
- data/etc/bhuga.nq +6 -6
- data/etc/bhuga.nt +6 -0
- data/etc/bhuga.ttl +15 -0
- data/etc/{triples.nt → doap.nq} +73 -76
- data/etc/doap.nt +39 -39
- data/etc/doap.ttl +79 -0
- data/etc/gkellogg.nq +5 -6
- data/etc/gkellogg.nt +5 -0
- data/etc/gkellogg.ttl +14 -0
- data/etc/test-data.nt +1 -0
- data/lib/rdf/spec.rb +0 -20
- data/lib/rdf/spec/countable.rb +26 -21
- data/lib/rdf/spec/durable.rb +13 -9
- data/lib/rdf/spec/enumerable.rb +314 -264
- data/lib/rdf/spec/format.rb +8 -9
- data/lib/rdf/spec/indexable.rb +13 -6
- data/lib/rdf/spec/matchers.rb +38 -38
- data/lib/rdf/spec/mutable.rb +81 -84
- data/lib/rdf/spec/queryable.rb +168 -195
- data/lib/rdf/spec/readable.rb +7 -3
- data/lib/rdf/spec/reader.rb +43 -43
- data/lib/rdf/spec/repository.rb +26 -15
- data/lib/rdf/spec/transaction.rb +90 -42
- data/lib/rdf/spec/writable.rb +55 -68
- data/lib/rdf/spec/writer.rb +36 -35
- data/spec/version_spec.rb +1 -1
- metadata +41 -34
- data/etc/quads.nq +0 -95
data/lib/rdf/spec/queryable.rb
CHANGED
@@ -7,184 +7,154 @@ module RDF_Queryable
|
|
7
7
|
before :each do
|
8
8
|
raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
|
9
9
|
|
10
|
-
@doap =
|
11
|
-
@
|
10
|
+
@doap = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nq'))
|
11
|
+
@doaps = RDF::NQuads::Reader.new(File.open(@doap)).to_a
|
12
|
+
@statements = @doaps
|
12
13
|
|
13
14
|
if @queryable.empty?
|
14
|
-
if @queryable.respond_to?(:<<)
|
15
|
-
@
|
15
|
+
if @queryable.respond_to?(:<<)
|
16
|
+
@doaps.each { |statement| @queryable << statement }
|
16
17
|
else
|
17
18
|
raise "@queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
22
|
+
@subject = RDF::URI('http://rubygems.org/gems/rdf')
|
20
23
|
end
|
21
|
-
let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
|
22
|
-
let(:literal) {RDF::Literal.new('J. Random Hacker')}
|
23
24
|
|
24
25
|
describe RDF::Queryable do
|
25
|
-
subject {@queryable}
|
26
|
-
let(:query) {RDF::Query.new {pattern [:s, :p, :o]}}
|
27
|
-
|
28
26
|
##
|
29
27
|
# @see RDF::Queryable#query
|
30
28
|
describe "#query" do
|
31
|
-
it
|
29
|
+
it "should respond to #query" do
|
30
|
+
@queryable.should respond_to(:query)
|
31
|
+
end
|
32
32
|
|
33
33
|
context "when called" do
|
34
34
|
it "requires an argument" do
|
35
|
-
|
35
|
+
lambda { @queryable.query }.should raise_error(ArgumentError)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "accepts a pattern argument" do
|
39
|
-
|
40
|
-
|
39
|
+
lambda { @queryable.query(RDF::Query::Pattern.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
|
40
|
+
lambda { @queryable.query(RDF::Query::Pattern.new(:s, :p, :o)) }.should_not raise_error(ArgumentError)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "accepts a statement argument" do
|
44
|
-
|
44
|
+
lambda { @queryable.query(RDF::Statement.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "accepts a triple argument" do
|
48
|
-
|
48
|
+
lambda { @queryable.query([nil, nil, nil]) }.should_not raise_error(ArgumentError)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "accepts a quad argument" do
|
52
|
-
|
52
|
+
lambda { @queryable.query([nil, nil, nil, nil]) }.should_not raise_error(ArgumentError)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "accepts a hash argument" do
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
it "accepts an RDF::Query argument" do
|
60
|
-
expect { subject.query(RDF::Query.new) }.not_to raise_error
|
56
|
+
lambda { @queryable.query({}) }.should_not raise_error(ArgumentError)
|
61
57
|
end
|
62
58
|
|
63
59
|
it "does not alter a given hash argument" do
|
64
|
-
query = {:subject =>
|
60
|
+
query = {:subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
|
65
61
|
original_query = query.dup
|
66
|
-
|
67
|
-
|
62
|
+
@queryable.query(query)
|
63
|
+
query.should == original_query
|
68
64
|
end
|
69
65
|
|
70
66
|
it "rejects other kinds of arguments" do
|
71
|
-
|
67
|
+
lambda { @queryable.query(nil) }.should raise_error(ArgumentError)
|
72
68
|
end
|
73
69
|
|
74
70
|
context "with a block" do
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
expect(statement).to be_a_statement
|
79
|
-
expect(statement).not_to be_a RDF::Query::Solution
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "calls #query_pattern" do
|
84
|
-
expect(subject).to receive(:query_pattern)
|
85
|
-
expect(subject).not_to receive(:query_execute)
|
86
|
-
subject.query([:s, :p, :o]) {}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
context "with a Query argument" do
|
90
|
-
it "yields statements" do
|
91
|
-
subject.query(query) do |solution|
|
92
|
-
expect(solution).not_to be_a_statement
|
93
|
-
expect(solution).to be_a RDF::Query::Solution
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it "calls #query_execute" do
|
98
|
-
expect(subject).to receive(:query_execute)
|
99
|
-
expect(subject).not_to receive(:query_pattern)
|
100
|
-
subject.query(query) {}
|
71
|
+
it "yields statements" do
|
72
|
+
@queryable.query([nil, nil, nil]) do |statement|
|
73
|
+
statement.should be_a_statement
|
101
74
|
end
|
102
75
|
end
|
103
76
|
end
|
104
77
|
|
105
78
|
context "without a block" do
|
106
79
|
it "returns an enumerator" do
|
107
|
-
|
80
|
+
@queryable.query([nil, nil, nil]).should be_an_enumerator
|
108
81
|
end
|
109
82
|
|
110
83
|
it "returns an enumerable enumerator" do
|
111
|
-
|
84
|
+
@queryable.query([nil, nil, nil]).should be_enumerable
|
112
85
|
end
|
113
86
|
|
114
87
|
it "returns a queryable enumerator" do
|
115
|
-
|
88
|
+
@queryable.query([nil, nil, nil]).should be_queryable
|
116
89
|
end
|
117
90
|
|
118
|
-
it "returns statements
|
119
|
-
|
120
|
-
|
121
|
-
expect(statement).not_to be_a RDF::Query::Solution
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
it "returns solutions given a query" do
|
126
|
-
subject.query(query).each do |solution|
|
127
|
-
expect(solution).not_to be_a_statement
|
128
|
-
expect(solution).to be_a RDF::Query::Solution
|
91
|
+
it "returns statements" do
|
92
|
+
@queryable.query([nil, nil, nil]).each do |statement|
|
93
|
+
statement.should be_a_statement
|
129
94
|
end
|
130
95
|
end
|
131
96
|
|
132
97
|
it "returns the correct number of results for array queries" do
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
98
|
+
@queryable.query([nil, nil, nil]).size.should == @statements.size
|
99
|
+
@queryable.query([@subject, nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
|
100
|
+
@queryable.query([RDF::URI("http://ar.to/#self"), nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
101
|
+
@queryable.query([@subject, RDF::DOAP.name, nil]).size.should == 1
|
102
|
+
@queryable.query([nil, nil, RDF::DOAP.Project]).size.should == 1
|
138
103
|
end
|
139
104
|
|
140
105
|
it "returns the correct number of results for hash queries" do
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
it "returns the correct number of results for query queries" do
|
148
|
-
expect(subject.query(query).size).to eq @statements.size
|
106
|
+
@queryable.query({}).size.should == @statements.size
|
107
|
+
@queryable.query(:subject => @subject) .size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
|
108
|
+
@queryable.query(:subject => @subject, :predicate => RDF::DOAP.name).size.should == 1
|
109
|
+
@queryable.query(:object => RDF::DOAP.Project).size.should == 1
|
149
110
|
end
|
150
111
|
end
|
151
112
|
|
152
113
|
context "with specific patterns from SPARQL" do
|
153
114
|
context "triple pattern combinations" do
|
154
115
|
it "?s p o" do
|
155
|
-
|
156
|
-
|
157
|
-
)
|
116
|
+
@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a.should ==
|
117
|
+
[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
158
118
|
end
|
159
119
|
|
160
120
|
it "s ?p o" do
|
161
|
-
|
162
|
-
|
163
|
-
)
|
121
|
+
@queryable.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a.should ==
|
122
|
+
[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
164
123
|
end
|
165
124
|
end
|
166
125
|
|
167
126
|
# From data-r2/expr-equals
|
168
127
|
context "data/r2/expr-equals" do
|
169
128
|
context "graph-1" do
|
170
|
-
|
171
|
-
|
129
|
+
before(:each) do
|
130
|
+
@solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a
|
131
|
+
end
|
172
132
|
|
173
133
|
it "has two solutions" do
|
174
|
-
|
134
|
+
@solutions.count.should == 2
|
135
|
+
end
|
136
|
+
|
137
|
+
it "has xi1 as a solution" do
|
138
|
+
@solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}.should be_true
|
175
139
|
end
|
176
140
|
|
177
141
|
it "has xi2 as a solution" do
|
178
|
-
|
142
|
+
@solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}.should be_true
|
179
143
|
end
|
180
144
|
end
|
181
145
|
|
146
|
+
|
182
147
|
context "graph-2" do
|
183
|
-
|
184
|
-
|
148
|
+
before(:each) do
|
149
|
+
@solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a
|
150
|
+
end
|
151
|
+
|
152
|
+
it "has one solution" do
|
153
|
+
@solutions.count.should == 1
|
154
|
+
end
|
185
155
|
|
186
156
|
it "has xd1 as a solution" do
|
187
|
-
|
157
|
+
@solutions.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}.should be_true
|
188
158
|
end
|
189
159
|
end
|
190
160
|
end
|
@@ -192,49 +162,30 @@ module RDF_Queryable
|
|
192
162
|
end
|
193
163
|
end
|
194
164
|
|
195
|
-
##
|
196
|
-
# @see RDF::Queryable#query_execute
|
197
|
-
describe "#query_execute" do
|
198
|
-
it "defines a protected #query_execute method" do
|
199
|
-
expect(subject.class.protected_method_defined?(:query_execute)).to be_true
|
200
|
-
end
|
201
|
-
|
202
|
-
context "when called" do
|
203
|
-
it "requires an argument" do
|
204
|
-
expect { subject.send(:query_execute) }.to raise_error(ArgumentError)
|
205
|
-
end
|
206
|
-
|
207
|
-
it "yields to the given block" do
|
208
|
-
expect {|b| subject.send(:query_execute, query, &b)}.to yield_control.exactly(@queryable.count).times
|
209
|
-
end
|
210
|
-
|
211
|
-
it "yields solutions" do
|
212
|
-
subject.send(:query_execute, query) do |solution|
|
213
|
-
expect(solution).to be_a RDF::Query::Solution
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
165
|
##
|
220
166
|
# @see RDF::Queryable#query_pattern
|
221
167
|
describe "#query_pattern" do
|
222
168
|
it "defines a protected #query_pattern method" do
|
223
|
-
|
169
|
+
@queryable.class.protected_method_defined?(:query_pattern).should be_true
|
224
170
|
end
|
225
171
|
|
226
172
|
context "when called" do
|
227
173
|
it "requires an argument" do
|
228
|
-
|
174
|
+
lambda { @queryable.send(:query_pattern) }.should raise_error(ArgumentError)
|
229
175
|
end
|
230
176
|
|
231
177
|
it "yields to the given block" do
|
232
|
-
|
178
|
+
called = false
|
179
|
+
@queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
|
180
|
+
called = true
|
181
|
+
break
|
182
|
+
end
|
183
|
+
called.should be_true
|
233
184
|
end
|
234
185
|
|
235
186
|
it "yields statements" do
|
236
|
-
|
237
|
-
|
187
|
+
@queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
|
188
|
+
statement.should be_a_statement
|
238
189
|
end
|
239
190
|
end
|
240
191
|
|
@@ -251,8 +202,8 @@ module RDF_Queryable
|
|
251
202
|
pattern = RDF::Query::Pattern.from(pattern)
|
252
203
|
it "returns #{result.inspect} given #{pattern.inspect}" do
|
253
204
|
solutions = []
|
254
|
-
|
255
|
-
|
205
|
+
@queryable.send(:query_pattern, pattern) {|s| solutions << s}
|
206
|
+
solutions.should == result
|
256
207
|
end
|
257
208
|
end
|
258
209
|
end
|
@@ -261,34 +212,34 @@ module RDF_Queryable
|
|
261
212
|
it "returns statements from all contexts with no context" do
|
262
213
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => nil)
|
263
214
|
solutions = []
|
264
|
-
|
265
|
-
|
215
|
+
@queryable.send(:query_pattern, pattern) {|s| solutions << s}
|
216
|
+
solutions.size.should == @statements.size
|
266
217
|
end
|
267
218
|
|
268
219
|
it "returns statements from unnamed contexts with false context" do
|
269
220
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => false)
|
270
221
|
solutions = []
|
271
|
-
|
272
|
-
context_statements =
|
273
|
-
|
222
|
+
@queryable.send(:query_pattern, pattern) {|s| solutions << s}
|
223
|
+
context_statements = @queryable.statements.reject {|st| st.has_context?}.length
|
224
|
+
solutions.size.should == context_statements
|
274
225
|
end
|
275
226
|
|
276
227
|
it "returns statements from named contexts with variable context" do
|
277
|
-
unless
|
228
|
+
unless @queryable.contexts.to_a.empty?
|
278
229
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => :c)
|
279
230
|
solutions = []
|
280
|
-
|
281
|
-
context_statements =
|
282
|
-
|
231
|
+
@queryable.send(:query_pattern, pattern) {|s| solutions << s}
|
232
|
+
context_statements = @queryable.statements.select {|st| st.has_context?}.length
|
233
|
+
solutions.size.should == context_statements
|
283
234
|
end
|
284
235
|
end
|
285
236
|
|
286
237
|
it "returns statements from specific context with URI context" do
|
287
|
-
unless
|
238
|
+
unless @queryable.contexts.to_a.empty?
|
288
239
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => RDF::URI("http://ar.to/#self"))
|
289
240
|
solutions = []
|
290
|
-
|
291
|
-
|
241
|
+
@queryable.send(:query_pattern, pattern) {|s| solutions << s}
|
242
|
+
solutions.size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
292
243
|
end
|
293
244
|
end
|
294
245
|
end
|
@@ -298,64 +249,68 @@ module RDF_Queryable
|
|
298
249
|
##
|
299
250
|
# @see RDF::Queryable#first
|
300
251
|
describe "#first" do
|
301
|
-
|
252
|
+
before :all do
|
253
|
+
@failing_pattern = [RDF::Node.new] * 3
|
254
|
+
end
|
302
255
|
|
303
256
|
it "should respond to #first" do
|
304
|
-
|
257
|
+
@queryable.should respond_to(:first)
|
305
258
|
end
|
306
259
|
|
307
260
|
it "returns enumerator without a pattern" do
|
308
|
-
|
309
|
-
|
261
|
+
lambda { @queryable.first }.should_not raise_error(ArgumentError)
|
262
|
+
@queryable.first.should == @queryable.each.first # uses an Enumerator
|
310
263
|
end
|
311
264
|
|
312
265
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
313
|
-
matching_patterns = [[nil, nil, nil],
|
266
|
+
matching_patterns = [[nil, nil, nil], @queryable.each.first]
|
314
267
|
matching_patterns.each do |matching_pattern|
|
315
|
-
|
268
|
+
@queryable.first(matching_pattern).should == @queryable.query(matching_pattern).each.first
|
316
269
|
end
|
317
270
|
end
|
318
271
|
|
319
272
|
it "returns nil when the pattern fails to match anything" do
|
320
|
-
|
273
|
+
@queryable.first(@failing_pattern).should be_nil
|
321
274
|
end
|
322
275
|
|
323
276
|
it "returns nil when self is empty" do
|
324
277
|
queryable = [].extend(RDF::Queryable)
|
325
|
-
|
326
|
-
|
278
|
+
queryable.first.should be_nil
|
279
|
+
queryable.first(@failing_pattern).should be_nil
|
327
280
|
end
|
328
281
|
end
|
329
282
|
|
330
283
|
##
|
331
284
|
# @see RDF::Queryable#first_subject
|
332
285
|
describe "#first_subject" do
|
333
|
-
|
286
|
+
before :all do
|
287
|
+
@failing_pattern = [RDF::Node.new, nil, nil]
|
288
|
+
end
|
334
289
|
|
335
290
|
it "should respond to #first_subject" do
|
336
|
-
|
291
|
+
@queryable.should respond_to(:first_subject)
|
337
292
|
end
|
338
293
|
|
339
294
|
it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
340
|
-
|
341
|
-
|
295
|
+
lambda { @queryable.first_subject }.should_not raise_error(ArgumentError)
|
296
|
+
@queryable.first_subject.should == @queryable.first.subject
|
342
297
|
end
|
343
298
|
|
344
299
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
345
|
-
matching_patterns = [[nil, nil, nil], [
|
300
|
+
matching_patterns = [[nil, nil, nil], [@queryable.first.subject, nil, nil]]
|
346
301
|
matching_patterns.each do |matching_pattern|
|
347
|
-
|
302
|
+
@queryable.first_subject(matching_pattern).should == @queryable.query(matching_pattern).first.subject
|
348
303
|
end
|
349
304
|
end
|
350
305
|
|
351
306
|
it "returns nil when the pattern fails to match anything" do
|
352
|
-
|
307
|
+
@queryable.first_subject(@failing_pattern).should be_nil
|
353
308
|
end
|
354
309
|
|
355
310
|
it "returns nil when self is empty" do
|
356
311
|
queryable = [].extend(RDF::Queryable)
|
357
|
-
|
358
|
-
|
312
|
+
queryable.first_subject.should be_nil
|
313
|
+
queryable.first_subject(@failing_pattern).should be_nil
|
359
314
|
end
|
360
315
|
end
|
361
316
|
|
@@ -363,30 +318,34 @@ module RDF_Queryable
|
|
363
318
|
# @see RDF::Queryable#first_predicate
|
364
319
|
|
365
320
|
describe "#first_predicate" do
|
366
|
-
|
321
|
+
before :all do
|
322
|
+
@failing_pattern = [nil, RDF::Node.new, nil]
|
323
|
+
end
|
367
324
|
|
368
|
-
it
|
325
|
+
it "should respond to #first_predicate" do
|
326
|
+
@queryable.should respond_to(:first_predicate)
|
327
|
+
end
|
369
328
|
|
370
329
|
it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
371
|
-
|
372
|
-
|
330
|
+
lambda { @queryable.first_predicate }.should_not raise_error(ArgumentError)
|
331
|
+
@queryable.first_predicate.should == @queryable.first.predicate
|
373
332
|
end
|
374
333
|
|
375
334
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
376
|
-
matching_patterns = [[nil, nil, nil], [nil,
|
335
|
+
matching_patterns = [[nil, nil, nil], [nil, @queryable.first.predicate, nil]]
|
377
336
|
matching_patterns.each do |matching_pattern|
|
378
|
-
|
337
|
+
@queryable.first_predicate(matching_pattern).should == @queryable.query(matching_pattern).first.predicate
|
379
338
|
end
|
380
339
|
end
|
381
340
|
|
382
341
|
it "returns nil when the pattern fails to match anything" do
|
383
|
-
|
342
|
+
@queryable.first_predicate(@failing_pattern).should be_nil
|
384
343
|
end
|
385
344
|
|
386
345
|
it "returns nil when self is empty" do
|
387
346
|
queryable = [].extend(RDF::Queryable)
|
388
|
-
|
389
|
-
|
347
|
+
queryable.first_predicate.should be_nil
|
348
|
+
queryable.first_predicate(@failing_pattern).should be_nil
|
390
349
|
end
|
391
350
|
end
|
392
351
|
|
@@ -394,67 +353,76 @@ module RDF_Queryable
|
|
394
353
|
# @see RDF::Queryable#first_object
|
395
354
|
|
396
355
|
describe "#first_object" do
|
397
|
-
|
398
|
-
|
356
|
+
before :all do
|
357
|
+
@failing_pattern = [nil, nil, RDF::Node.new]
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should respond to #first_object" do
|
361
|
+
@queryable.should respond_to(:first_object)
|
362
|
+
end
|
399
363
|
|
400
364
|
it "returns enurator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
401
|
-
|
402
|
-
|
365
|
+
lambda { @queryable.first_object }.should_not raise_error(ArgumentError)
|
366
|
+
@queryable.first_object.should == @queryable.first.object
|
403
367
|
end
|
404
368
|
|
405
369
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
406
|
-
matching_patterns = [[nil, nil, nil], [nil, nil,
|
370
|
+
matching_patterns = [[nil, nil, nil], [nil, nil, @queryable.first.object]]
|
407
371
|
matching_patterns.each do |matching_pattern|
|
408
|
-
|
372
|
+
@queryable.first_object(matching_pattern).should == @queryable.query(matching_pattern).first.object
|
409
373
|
end
|
410
374
|
end
|
411
375
|
|
412
376
|
it "returns nil when the pattern fails to match anything" do
|
413
|
-
|
377
|
+
@queryable.first_object(@failing_pattern).should be_nil
|
414
378
|
end
|
415
379
|
|
416
380
|
it "returns nil when self is empty" do
|
417
381
|
queryable = [].extend(RDF::Queryable)
|
418
|
-
|
419
|
-
|
382
|
+
queryable.first_object.should be_nil
|
383
|
+
queryable.first_object(@failing_pattern).should be_nil
|
420
384
|
end
|
421
385
|
end
|
422
386
|
|
423
387
|
##
|
424
388
|
# @see RDF::Queryable#first_literal
|
425
389
|
|
390
|
+
it "returns to #first_literal" do
|
391
|
+
@queryable.should respond_to(:first_literal)
|
392
|
+
end
|
393
|
+
|
426
394
|
describe "#first_literal" do
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
graph << [
|
432
|
-
graph << [
|
433
|
-
graph << [
|
395
|
+
before :each do
|
396
|
+
# FIXME: these tests should be using the provided @queryable, if possible.
|
397
|
+
@queryable = RDF::Graph.new do |graph|
|
398
|
+
@subject = RDF::Node.new
|
399
|
+
graph << [@subject, RDF.type, RDF::DOAP.Project]
|
400
|
+
graph << [@subject, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
|
401
|
+
graph << [@subject, RDF::DC.creator, @literal = RDF::Literal.new('J. Random Hacker')]
|
434
402
|
end
|
435
|
-
|
436
|
-
|
403
|
+
@failing_pattern = [nil, nil, RDF::Node.new]
|
404
|
+
end
|
437
405
|
|
438
406
|
it "returns a literal without a pattern" do
|
439
|
-
|
440
|
-
|
407
|
+
lambda { @queryable.first_literal }.should_not raise_error(ArgumentError)
|
408
|
+
@queryable.first_literal.should == @literal
|
441
409
|
end
|
442
410
|
|
443
411
|
it "returns the correct value when the pattern matches" do
|
444
|
-
matching_patterns = [[nil, nil, nil], [
|
412
|
+
matching_patterns = [[nil, nil, nil], [@subject, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, @literal]]
|
445
413
|
matching_patterns.each do |matching_pattern|
|
446
|
-
|
414
|
+
@queryable.first_literal(matching_pattern).should == @literal
|
447
415
|
end
|
448
416
|
end
|
449
417
|
|
450
418
|
it "returns nil when the pattern fails to match anything" do
|
451
|
-
|
419
|
+
@queryable.first_literal(@failing_pattern).should be_nil
|
452
420
|
end
|
453
421
|
|
454
422
|
it "returns nil when self is empty" do
|
455
423
|
queryable = [].extend(RDF::Queryable)
|
456
|
-
|
457
|
-
|
424
|
+
queryable.first_literal.should be_nil
|
425
|
+
queryable.first_literal(@failing_pattern).should be_nil
|
458
426
|
end
|
459
427
|
end
|
460
428
|
|
@@ -462,35 +430,40 @@ module RDF_Queryable
|
|
462
430
|
# @see RDF::Queryable#first_value
|
463
431
|
|
464
432
|
describe "#first_value" do
|
465
|
-
|
466
|
-
|
433
|
+
before :all do
|
434
|
+
@failing_pattern = [nil, nil, RDF::Node.new]
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should respond to #first_value" do
|
438
|
+
@queryable.should respond_to(:first_value)
|
439
|
+
end
|
467
440
|
|
468
441
|
it "returns first literal without a pattern" do
|
469
|
-
|
470
|
-
|
442
|
+
lambda { @queryable.first_value }.should_not raise_error(ArgumentError)
|
443
|
+
@queryable.first_value.should == @queryable.first_literal.value
|
471
444
|
end
|
472
445
|
|
473
446
|
it "returns the correct value when the pattern matches" do
|
474
447
|
matching_patterns = []
|
475
|
-
|
448
|
+
@queryable.each do |statement|
|
476
449
|
if statement.object.is_a?(RDF::Literal)
|
477
450
|
matching_pattern = [statement.subject, statement.predicate, nil]
|
478
451
|
unless matching_patterns.include?(matching_pattern)
|
479
452
|
matching_patterns << matching_pattern
|
480
|
-
|
453
|
+
@queryable.first_value(matching_pattern).should == @queryable.first_literal(matching_pattern).value
|
481
454
|
end
|
482
455
|
end
|
483
456
|
end
|
484
457
|
end
|
485
458
|
|
486
459
|
it "returns nil when the pattern fails to match anything" do
|
487
|
-
|
460
|
+
@queryable.first_value(@failing_pattern).should be_nil
|
488
461
|
end
|
489
462
|
|
490
463
|
it "returns nil when self is empty" do
|
491
464
|
queryable = [].extend(RDF::Queryable)
|
492
|
-
|
493
|
-
|
465
|
+
queryable.first_value.should be_nil
|
466
|
+
queryable.first_value(@failing_pattern).should be_nil
|
494
467
|
end
|
495
468
|
end
|
496
469
|
end
|