|
47 | 47 | end |
48 | 48 | end |
49 | 49 |
|
50 | | - describe "#to_sym" do |
51 | | - specify {expect(subject.to_sym).to eq :nquads} |
52 | | - end |
53 | | - |
54 | | - describe "#name" do |
55 | | - specify {expect(subject.name).to eq "N-Quads"} |
56 | | - end |
57 | | - |
58 | 50 | describe ".detect" do |
59 | 51 | { |
60 | 52 | nquads: "<a> <b> <c> <d> . ", |
|
82 | 74 | end |
83 | 75 | end |
84 | 76 | end |
| 77 | + |
| 78 | + describe "#to_sym" do |
| 79 | + specify {expect(subject.to_sym).to eq :nquads} |
| 80 | + end |
| 81 | + |
| 82 | + describe "#name" do |
| 83 | + specify {expect(subject.name).to eq "N-Quads"} |
| 84 | + end |
85 | 85 | end |
86 | 86 |
|
87 | 87 | describe RDF::NQuads::Reader do |
|
123 | 123 | it "should accept strings" do |
124 | 124 | expect { described_class.new('') }.to_not raise_error |
125 | 125 | end |
| 126 | + |
| 127 | + it "sets version from reader option" do |
| 128 | + expect(described_class.new('', version: '1.2').version).to eql '1.2' |
| 129 | + end |
126 | 130 | end |
127 | 131 |
|
128 | 132 | context "#initialize" do |
|
143 | 147 | end |
144 | 148 | end |
145 | 149 |
|
146 | | - context "with simple triples" do |
147 | | - [ |
148 | | - ['<a> <b> <c> .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"))], |
149 | | - ['<a> <b> _:c .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::Node.new("c"))], |
150 | | - ['<a> <b> "c" .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::Literal("c"))], |
151 | | - ['_:a <b> <c> .', RDF::Statement(RDF::Node.new("a"), RDF::URI("b"), RDF::URI("c"))], |
152 | | - ].each do |(str, statement)| |
153 | | - it "parses #{str.inspect}" do |
154 | | - graph = RDF::Graph.new << described_class.new(str) |
155 | | - expect(graph.size).to eq 1 |
156 | | - expect(graph.statements.first).to eq statement |
157 | | - end |
158 | | - end |
159 | | - end |
160 | | - |
161 | | - context "with simple quads" do |
162 | | - [ |
163 | | - ['<a> <b> <c> <d> .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::URI("d"))], |
164 | | - ['<a> <b> <c> _:d .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::Node.new("d"))], |
165 | | - ['<a> <b> <c> "d" .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::Literal("d"))], |
166 | | - ].each do |(str, statement)| |
167 | | - it "parses #{str.inspect}" do |
168 | | - graph = RDF::Graph.new << described_class.new(str) |
169 | | - expect(graph.size).to eq 1 |
170 | | - expect(graph.statements.first).to eq statement |
171 | | - end |
172 | | - |
173 | | - it "serializes #{statement.inspect}" do |
174 | | - expect(RDF::NQuads.serialize(statement).chomp).to eq str |
175 | | - end |
176 | | - |
177 | | - it "unserializes #{str.inspect}" do |
178 | | - expect(RDF::NQuads.unserialize(str)).to eq statement |
| 150 | + describe "Grammar" do |
| 151 | + context "with simple triples" do |
| 152 | + [ |
| 153 | + ['<a> <b> <c> .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"))], |
| 154 | + ['<a> <b> _:c .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::Node.new("c"))], |
| 155 | + ['<a> <b> "c" .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::Literal("c"))], |
| 156 | + ['_:a <b> <c> .', RDF::Statement(RDF::Node.new("a"), RDF::URI("b"), RDF::URI("c"))], |
| 157 | + ].each do |(str, statement)| |
| 158 | + it "parses #{str.inspect}" do |
| 159 | + graph = RDF::Graph.new << described_class.new(str) |
| 160 | + expect(graph.size).to eq 1 |
| 161 | + expect(graph.statements.first).to eq statement |
| 162 | + end |
179 | 163 | end |
180 | 164 | end |
181 | | - end |
182 | 165 |
|
183 | | - context "triple terms" do |
184 | | - ill_statements = { |
185 | | - "subject-iii": '<<<http://example/s1> <http://example/p1> <http://example/o1>>> <http://example/p> <http://example/o> <http://example/g> .', |
186 | | - "subject-iib": '<<<http://example/s1> <http://example/p1> _:o1>> <http://example/p> <http://example/o> <http://example/g> .', |
187 | | - "subject-iil": '<<<http://example/s1> <http://example/p1> "o1">> <http://example/p> <http://example/o> <http://example/g> .', |
188 | | - "subject-bii": '<<_:s1 <http://example/p1> <http://example/o1>>> <http://example/p> <http://example/o> <http://example/g> .', |
189 | | - "subject-bib": '<<_:s1 <http://example/p1> _:o1>> <http://example/p> <http://example/o> <http://example/g> .', |
190 | | - "subject-bil": '<<_:s1 <http://example/p1> "o">> <http://example/p> <http://example/o> <http://example/g> .', |
191 | | - "subject-ws": '<< <http://example/s1> <http://example/p1> <http://example/o1> >> <http://example/p> <http://example/o> <http://example/g> .', |
192 | | - "recursive-subject": '<<(<<(<http://example/s2> <http://example/p2> <http://example/o2>)>> <http://example/p1> <http://example/o1>)>> <http://example/p> <http://example/o> <http://example/g> .', |
193 | | - } |
| 166 | + context "with simple quads" do |
| 167 | + [ |
| 168 | + ['<a> <b> <c> <d> .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::URI("d"))], |
| 169 | + ['<a> <b> <c> _:d .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::Node.new("d"))], |
| 170 | + ['<a> <b> <c> "d" .', RDF::Statement(RDF::URI("a"), RDF::URI("b"), RDF::URI("c"), graph_name: RDF::Literal("d"))], |
| 171 | + ].each do |(str, statement)| |
| 172 | + it "parses #{str.inspect}" do |
| 173 | + graph = RDF::Graph.new << described_class.new(str) |
| 174 | + expect(graph.size).to eq 1 |
| 175 | + expect(graph.statements.first).to eq statement |
| 176 | + end |
194 | 177 |
|
195 | | - statements = { |
196 | | - "object-iii": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> <http://example/o1>)>> <http://example/g> .', |
197 | | - "object-iib": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> _:o1)>> <http://example/g> .', |
198 | | - "object-iil": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> "o1")>> <http://example/g> .', |
199 | | - "object-ws": '<http://example/s> <http://example/p> <<( <http://example/s1> <http://example/p1> <http://example/o1> )>> <http://example/g> .', |
200 | | - } |
| 178 | + it "serializes #{statement.inspect}" do |
| 179 | + expect(RDF::NQuads.serialize(statement).chomp).to eq str |
| 180 | + end |
201 | 181 |
|
202 | | - context "without rdfstar option" do |
203 | | - it "Raises an error" do |
204 | | - expect do |
205 | | - expect {RDF::Repository.new << RDF::NQuads::Reader.new(statements.values.first)}.to raise_error(RDF::ReaderError) |
206 | | - end.to write(:something).to(:error) |
| 182 | + it "unserializes #{str.inspect}" do |
| 183 | + expect(RDF::NQuads.unserialize(str)).to eq statement |
| 184 | + end |
207 | 185 | end |
208 | 186 | end |
209 | 187 |
|
210 | | - context "with rdfstar option" do |
211 | | - ill_statements.each do |name, st| |
212 | | - context name do |
213 | | - it "Raises an error" do |
214 | | - expect do |
215 | | - expect {RDF::Repository.new << RDF::NQuads::Reader.new(statements.values.first)}.to raise_error(RDF::ReaderError) |
216 | | - end.to write(:something).to(:error) |
217 | | - end |
| 188 | + context "triple terms" do |
| 189 | + ill_statements = { |
| 190 | + "subject-iii": '<<<http://example/s1> <http://example/p1> <http://example/o1>>> <http://example/p> <http://example/o> <http://example/g> .', |
| 191 | + "subject-iib": '<<<http://example/s1> <http://example/p1> _:o1>> <http://example/p> <http://example/o> <http://example/g> .', |
| 192 | + "subject-iil": '<<<http://example/s1> <http://example/p1> "o1">> <http://example/p> <http://example/o> <http://example/g> .', |
| 193 | + "subject-bii": '<<_:s1 <http://example/p1> <http://example/o1>>> <http://example/p> <http://example/o> <http://example/g> .', |
| 194 | + "subject-bib": '<<_:s1 <http://example/p1> _:o1>> <http://example/p> <http://example/o> <http://example/g> .', |
| 195 | + "subject-bil": '<<_:s1 <http://example/p1> "o">> <http://example/p> <http://example/o> <http://example/g> .', |
| 196 | + "subject-ws": '<< <http://example/s1> <http://example/p1> <http://example/o1> >> <http://example/p> <http://example/o> <http://example/g> .', |
| 197 | + "recursive-subject": '<<(<<(<http://example/s2> <http://example/p2> <http://example/o2>)>> <http://example/p1> <http://example/o1>)>> <http://example/p> <http://example/o> <http://example/g> .', |
| 198 | + } |
| 199 | + |
| 200 | + statements = { |
| 201 | + "object-iii": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> <http://example/o1>)>> <http://example/g> .', |
| 202 | + "object-iib": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> _:o1)>> <http://example/g> .', |
| 203 | + "object-iil": '<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> "o1")>> <http://example/g> .', |
| 204 | + "object-ws": '<http://example/s> <http://example/p> <<( <http://example/s1> <http://example/p1> <http://example/o1> )>> <http://example/g> .', |
| 205 | + } |
| 206 | + |
| 207 | + context "without rdfstar option" do |
| 208 | + it "Raises an error" do |
| 209 | + expect do |
| 210 | + expect {RDF::Repository.new << RDF::NQuads::Reader.new(statements.values.first)}.to raise_error(RDF::ReaderError) |
| 211 | + end.to write(:something).to(:error) |
218 | 212 | end |
219 | 213 | end |
220 | 214 |
|
221 | | - statements.each do |name, st| |
222 | | - context name do |
223 | | - let(:graph) do |
224 | | - RDF::Repository.new {|r| r << RDF::NQuads::Reader.new(st, rdfstar: true)} |
225 | | - end |
226 | | - |
227 | | - it "creates a statement" do |
228 | | - expect(graph.count).to eql(1) |
| 215 | + context "with rdfstar option" do |
| 216 | + ill_statements.each do |name, st| |
| 217 | + context name do |
| 218 | + it "Raises an error" do |
| 219 | + expect do |
| 220 | + expect {RDF::Repository.new << RDF::NQuads::Reader.new(statements.values.first)}.to raise_error(RDF::ReaderError) |
| 221 | + end.to write(:something).to(:error) |
| 222 | + end |
229 | 223 | end |
| 224 | + end |
230 | 225 |
|
231 | | - it "statements which are object of another statement are triple terms" do |
232 | | - referencing = graph.statements.first |
233 | | - expect(referencing).to be_a_statement |
234 | | - expect(referencing.object).to be_a_statement |
235 | | - expect(referencing.object).to be_tripleTerm |
| 226 | + statements.each do |name, st| |
| 227 | + context name do |
| 228 | + let(:graph) do |
| 229 | + RDF::Repository.new {|r| r << RDF::NQuads::Reader.new(st, rdfstar: true)} |
| 230 | + end |
| 231 | + |
| 232 | + it "creates a statement" do |
| 233 | + expect(graph.count).to eql(1) |
| 234 | + end |
| 235 | + |
| 236 | + it "statements which are object of another statement are triple terms" do |
| 237 | + referencing = graph.statements.first |
| 238 | + expect(referencing).to be_a_statement |
| 239 | + expect(referencing.object).to be_a_statement |
| 240 | + expect(referencing.object).to be_tripleTerm |
| 241 | + end |
236 | 242 | end |
237 | 243 | end |
238 | 244 | end |
239 | 245 | end |
240 | | - end |
241 | 246 |
|
242 | | - it "should parse W3C's test data" do |
243 | | - expect(described_class.new(File.open(testfile)).to_a.size).to eq 19 |
| 247 | + it "should parse W3C's test data" do |
| 248 | + expect(described_class.new(File.open(testfile)).to_a.size).to eq 19 |
| 249 | + end |
244 | 250 | end |
245 | 251 | end |
246 | 252 |
|
|
0 commit comments