Skip to content

Commit 91bc9ee

Browse files
committed
Make sure buffer encoding set using format or passed option.
1 parent 4ba5756 commit 91bc9ee

1 file changed

Lines changed: 39 additions & 12 deletions

File tree

lib/rdf/spec/writer.rb

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313
let(:reader_class) { writer_class.format.reader}
1414
let(:format_class) { writer_class.format }
1515

16+
let(:graph) do
17+
@graph ||= begin
18+
n1 = RDF::Node("a")
19+
n2 = RDF::Node("a")
20+
p = RDF::URI("http://example/pred")
21+
s1 = RDF::Statement(n1, p, n1)
22+
s2 = RDF::Statement(n2, p, n2)
23+
s3 = RDF::Statement(n1, p, n2)
24+
s4 = RDF::Statement(n2, p, n1)
25+
RDF::Graph.new.insert(s1, s2, s3, s4)
26+
end
27+
end
28+
29+
let(:serialized) do
30+
@serialized ||= begin
31+
writer_class.buffer do |w|
32+
w << graph
33+
end
34+
end
35+
end
36+
1637
describe ".each" do
1738
it "yields each writer" do
1839
writer_class.each do |r|
@@ -31,25 +52,31 @@
3152

3253
it "should serialize different BNodes sharing a common identifier to using different BNode ids" do
3354
if reader_class
34-
n1 = RDF::Node("a")
35-
n2 = RDF::Node("a")
36-
p = RDF::URI("http://example/pred")
37-
s1 = RDF::Statement(n1, p, n1)
38-
s2 = RDF::Statement(n2, p, n2)
39-
s3 = RDF::Statement(n1, p, n2)
40-
s4 = RDF::Statement(n2, p, n1)
41-
graph = RDF::Graph.new.insert(s1, s2, s3, s4)
42-
expect(graph.count).to eql 4
43-
serialized = writer_class.buffer do |w|
44-
w << graph
45-
end
4655
expect(serialized).not_to be_empty
4756
graph2 = RDF::Graph.new do |g|
4857
g << reader_class.new(serialized)
4958
end
5059
expect(graph2.count).to eql 4
5160
end
5261
end
62+
63+
it "returns a string" do
64+
expect(serialized).to be_a(String)
65+
end
66+
67+
it "should use encoding defined for format by default" do
68+
writer_class.new do |w|
69+
expect(serialized.encoding).to eql w.encoding
70+
end
71+
end
72+
73+
it "should use provided encoding if specified" do
74+
str = writer_class.buffer(encoding: Encoding::ASCII_8BIT) do |w|
75+
w << graph
76+
end
77+
78+
expect(str.encoding).to eql Encoding::ASCII_8BIT
79+
end
5380
end
5481

5582
describe ".open" do

0 commit comments

Comments
 (0)