-
Notifications
You must be signed in to change notification settings - Fork 14
/
misc_spec.rb
172 lines (165 loc) · 5.65 KB
/
misc_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
$:.unshift File.expand_path("../..", __FILE__)
require 'spec_helper'
# Misclaneous test cases, based on observed or reported problems
describe SPARQL::Grammar do
let(:logger) {RDF::Spec.logger.tap {|l| l.level = Logger::INFO}}
describe "misclaneous" do
{
"rdfa 0085" => {
graphs: { default: { format: :ttl, data: %q(
<http://www.example.org/#somebody> <http://xmlns.com/foaf/0.1/knows> _:a .
_:a <http://xmlns.com/foaf/0.1/knows> <http://www.ivan-herman.org/Ivan_Herman> .
_:a <http://xmlns.com/foaf/0.1/knows> <http://www.w3.org/People/Berners-Lee/card#i> .
_:a <http://xmlns.com/foaf/0.1/knows> <http://danbri.org/foaf.rdf#danbri> .
)
}},
query: %q(
ASK WHERE {
<http://www.example.org/#somebody> <http://xmlns.com/foaf/0.1/knows> _:a .
_:a <http://xmlns.com/foaf/0.1/knows> <http://www.ivan-herman.org/Ivan_Herman> ,
<http://www.w3.org/People/Berners-Lee/card#i> ,
<http://danbri.org/foaf.rdf#danbri> .
}
)
}
}.each do |test, options|
it "returns true for #{test}" do
result = sparql_query(repository: "sparql-spec",
form: :ask,
all_vars: true,
to_hash: false,
logger: logger, **options)
expect(result).to produce(RDF::Literal::TRUE, logger: logger)
end
end
{
"issue 25" => {
query: %(
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?class (group_concat(DISTINCT ?item;separator=",") as ?keys) WHERE {
?class rdf:type owl:Class .
?class owl:hasKey ?key .
?key rdf:rest*/rdf:first ?item .
}
GROUP BY ?class ?key
),
sse: %{
(project
(?class ?keys)
(extend ((?keys ??.0))
(group (?class ?key)
((??.0 (group_concat (separator ",") distinct ?item)))
(sequence
(bgp
(triple ?class <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>)
(triple ?class <http://www.w3.org/2002/07/owl#hasKey> ?key))
(path ?key
(seq
(path* <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>)
<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>
)
?item)))))
}
},
"issue 27" => {
query: %(
PREFIX simc: <http://www.ifi.uio.no/INF3580/simpson-collection#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?r ?f WHERE {
simc:Collection rdf:rest* ?r .
?r rdf:first ?f
}
),
sse: %{(project (?r ?f)
(sequence
(path <http://www.ifi.uio.no/INF3580/simpson-collection#Collection>
(path* <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>)
?r)
(bgp (triple ?r <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> ?f))
)
)}
},
"issue 33" => {
query: %(
CONSTRUCT {
?uri <http://prop3> ?anotherURI .
}
WHERE
{
?uri a ?type ;
<http://prop1> / <http://prop2> ?anotherURI
}
),
sse: %{(construct
((triple ?uri <http://prop3> ?anotherURI))
(sequence
(bgp (triple ?uri a ?type))
(path ?uri (seq <http://prop1> <http://prop2>) ?anotherURI)
)
)}
},
"pp bgp sequence" => {
query: %(
PREFIX : <http://example/>
SELECT * {?a :b/:b _:o . _:o :c :d .}
),
sse: %{(sequence
(path ?a (seq <http://example/b> <http://example/b>) ??o)
(bgp (triple ??o <http://example/c> <http://example/d>))
)}
},
"issue 42" => {
query: %(
PREFIX : <http://example/>
SELECT * {?a :b/:b [ :c :d] .}
),
sse: %{(sequence
(path ?a (seq <http://example/b> <http://example/b>) ??0)
(bgp (triple ??0 <http://example/c> <http://example/d>))
)}
},
"issue 46" => {
query: %(
PREFIX ex: <http://example.org/>
SELECT ?ev (MIN(?a) as ?a_min) (MIN(?b) as ?b_min)
WHERE {?ev ex:a ?a ; ex:b ?b . }
GROUP BY ?ev
),
sse: %{(project (?ev ?a_min ?b_min)
(extend ((?a_min ??.0) (?b_min ??.1))
(group (?ev) ((??.0 (min ?a)) (??.1 (min ?b)))
(bgp
(triple ?ev <http://example.org/a> ?a)
(triple ?ev <http://example.org/b> ?b)))))
}
}
}.each do |test, options|
it "parses #{test}" do
expect(options[:query]).to generate(options[:sse], logger: logger)
end
end
end
describe "property path errors" do
{
"{}" => {
query: %(SELECT * WHERE {:a :b{,} :c}),
exception: /expect property range to have integral elements/
},
"{,}" => {
query: %(SELECT * WHERE {:a :b{,} :c}),
exception: /expect property range to have integral elements/
},
"{2,1}" => {
query: %(SELECT * WHERE {:a :b{2,1} :c}),
exception: /expect min <= max/
},
}.each do |test, options|
it "#{test}" do
expect {
sparql_query(logger: logger, **options)
}.to raise_error(options[:exception])
end
end
end
end