Skip to content

Commit ba335f4

Browse files
committed
Improve coverage.
1 parent 6a7b805 commit ba335f4

4 files changed

Lines changed: 74 additions & 41 deletions

File tree

lib/ld/patch/algebra/update_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def execute(queryable, options = {})
3232
# Bind variables to path
3333
if var_or_iri.variable?
3434
raise LD::Patch::Error("Operand uses unbound variable #{var_or_iri.inspect}", code: 400) unless solution.bound?(var_or_iri)
35-
var_or_iri = solution[variable]
35+
var_or_iri = solution[var_or_iri]
3636
end
3737

3838
list_heads = queryable.query(subject: var_or_iri, predicate: predicate).map {|s| s.object}

spec/algebra_spec.rb

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
_:bpb <http://example.org/l> "b" .
2727
)
2828
EXAMPLE_4 = %(
29-
_:g70253998307400 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "lorem" .
30-
_:g70253998307400 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:g70253998308700 .
31-
_:g70253998308700 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "ipsum" .
32-
_:g70253998308700 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:g70253998317740 .
33-
_:g70253998317740 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "dolor" .
34-
_:g70253998317740 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:g70253998318780 .
35-
_:g70253998318780 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "sit" .
36-
_:g70253998318780 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:g70253998319960 .
37-
_:g70253998319960 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
38-
_:g70253998319960 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
39-
<http://example.org/#> <http://example.org/vocab#preferredLanguages> _:g70253998307400 .
29+
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "lorem" .
30+
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b .
31+
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "ipsum" .
32+
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c .
33+
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "dolor" .
34+
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:d .
35+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "sit" .
36+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:e .
37+
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
38+
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
39+
<http://example.org/#> <http://example.org/vocab#preferredLanguages> _:a .
4040
)
4141

4242
describe "positive evaluation" do
@@ -126,21 +126,27 @@
126126
)
127127
},
128128
"updatelist" => {
129-
data: %(
129+
data: EXAMPLE_4,
130+
patch: %(
131+
UpdateList <http://example.org/#> <http://example.org/vocab#preferredLanguages> 1..3 ( "IPSUM DOLOR" ) .
132+
),
133+
result: %(
130134
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "lorem" .
131135
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b .
132-
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "ipsum" .
136+
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "IPSUM DOLOR" .
133137
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c .
134-
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "dolor" .
138+
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "sit" .
135139
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:d .
136-
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "sit" .
137-
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:e .
138-
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
139-
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
140-
<http://example/#> <http://example.org/vocab#preferredLanguages> _:a .
141-
),
140+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
141+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
142+
<http://example.org/#> <http://example.org/vocab#preferredLanguages> _:a .
143+
)
144+
},
145+
"updatelist-var" => {
146+
data: EXAMPLE_4,
142147
patch: %(
143-
UpdateList <http://example/#> <http://example.org/vocab#preferredLanguages> 1..3 ( "IPSUM DOLOR" ) .
148+
Bind ?var <http://example.org/#> .
149+
UpdateList ?var <http://example.org/vocab#preferredLanguages> 1..3 ( "IPSUM DOLOR" ) .
144150
),
145151
result: %(
146152
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "lorem" .
@@ -151,7 +157,28 @@
151157
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:d .
152158
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
153159
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
154-
<http://example/#> <http://example.org/vocab#preferredLanguages> _:a .
160+
<http://example.org/#> <http://example.org/vocab#preferredLanguages> _:a .
161+
)
162+
},
163+
"updatelist-empty-slice" => {
164+
data: EXAMPLE_4,
165+
patch: %(
166+
UpdateList <http://example.org/#> <http://example.org/vocab#preferredLanguages> .. ( "IPSUM DOLOR" ) .
167+
),
168+
result: %(
169+
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "lorem" .
170+
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b .
171+
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "ipsum" .
172+
_:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c .
173+
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "dolor" .
174+
_:c <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:d .
175+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "sit" .
176+
_:d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:e .
177+
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "amet" .
178+
_:e <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:f .
179+
_:f <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "IPSUM DOLOR" .
180+
_:f <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
181+
<http://example.org/#> <http://example.org/vocab#preferredLanguages> _:a .
155182
)
156183
},
157184
"nested_collection" => {

spec/matchers.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ def normalize(graph)
6262
end
6363
end
6464

65-
RSpec::Matchers.define :produce do |expected, info|
66-
match do |actual|
67-
expect(actual).to eq expected
68-
end
69-
70-
failure_message do |actual|
71-
"Expected: #{[Array, Hash].include?(expected.class) ? expected.to_json(JSON_STATE) : expected.inspect}\n" +
72-
"Actual : #{[Array, Hash].include?(actual.class) ? actual.to_json(JSON_STATE) : actual.inspect}\n" +
73-
#(expected.is_a?(Hash) && actual.is_a?(Hash) ? "Diff: #{expected.diff(actual).to_json(JSON_STATE)}\n" : "") +
74-
"Processing results:\n#{info.join("\n")}"
75-
end
76-
end
77-
7865
RSpec::Matchers.define :generate do |expected, options = {}|
7966
def parser(options = {})
8067
@debug = options[:progress] ? 2 : []
@@ -97,7 +84,7 @@ def normalize(obj)
9784

9885
match do |input|
9986
case
100-
when expected == EBNF::LL1::Parser::Error
87+
when expected == LD::Patch::ParseError
10188
expect {parser(options).call(input)}.to raise_error(expected)
10289
when expected.is_a?(String)
10390
@actual = parser(options).call(input)

spec/parser_spec.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
$:.unshift File.expand_path("../..", __FILE__)
22
require 'spec_helper'
33

4+
describe LD::Patch do
5+
describe ".parse" do
6+
specify do
7+
input = %(Add { <http://example.org/s2> <http://example.org/p2> <http://example.org/o2> } .)
8+
expect(described_class.parse(input)).to be_a(SPARQL::Algebra::Operator)
9+
end
10+
end
11+
end
12+
413
describe LD::Patch::Parser do
514
before(:each) {$stderr = StringIO.new}
615
after(:each) {$stderr = STDERR}
@@ -270,9 +279,19 @@
270279
end
271280
end
272281

273-
def parse(input, options = {})
274-
production = options.fetch(:production, :ldpatch)
275-
@debug = options[:debug] || []
276-
described_class.new(input, {debug: @debug, resolve_iris: false}.merge(options)).parse(production)
282+
describe "NegativeSyntax" do
283+
{
284+
"s_bad_a_empty_graph.v" => {
285+
input: %(
286+
@prefix THIS_FILE_WAS_GENERATED__DO_NOT_CHANGE_IT: <>.
287+
A {}.
288+
),
289+
result: LD::Patch::ParseError
290+
},
291+
}.each do |name, params|
292+
it name do
293+
expect(params[:input]).to generate(params[:result])
294+
end
295+
end
277296
end
278297
end

0 commit comments

Comments
 (0)