Skip to content

Commit

Permalink
Merge 6c90d46 into b382c8e
Browse files Browse the repository at this point in the history
  • Loading branch information
no-reply committed Feb 8, 2019
2 parents b382c8e + 6c90d46 commit e765a91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/rdf/turtle/writer.rb
Expand Up @@ -447,7 +447,8 @@ def reset
# @return [String]
def quoted(string)
if string.to_s.match(/[\t\n\r]/)
string = string.gsub('\\', '\\\\\\\\').gsub('"""', '\\"""')
string = string.gsub('\\', '\\\\\\\\').gsub('"', '\\"')

%("""#{string}""")
else
"\"#{escaped(string)}\""
Expand Down
33 changes: 24 additions & 9 deletions spec/writer_spec.rb
Expand Up @@ -147,7 +147,7 @@
end
end
end

describe "lists" do
{
"bare list": {
Expand Down Expand Up @@ -301,7 +301,7 @@
describe "literals" do
describe "plain" do
{
"embedded \"\"\"": {
"\"\"\" delimited": {
input: %(<http://a> <http:/b> """testing string parsing in Turtle.\n""" .),
regexp: [/testing string parsing in Turtle.\n/]
},
Expand All @@ -318,20 +318,35 @@
regexp: [/string with \\\\ escaped quote mark/],
prefixes: {nil => ""}
},
"embedded \"\"\" multi-line": {
input: %(:a :b """string with \\""" escaped triple-quote marks\n""" .),
regexp: [/string with \\"\\"\\" escaped triple-quote marks/],
prefixes: {nil => ""}
},
"embedded \"\"\"\"\" multi-line": {
input: %(:a :b """string with many \\"""\\"" escaped quote marks\n""" .),
regexp: [/string with many \\"\\"\\"\\"\\" escaped quote marks/],
prefixes: {nil => ""}
},
"ending \" multi-line": {
input: %(:a :b """multi-line \nstring with ending \\"quote marks\\\"""" .),
regexp: [/multi-line \nstring with ending \\"quote marks\\"/],
prefixes: {nil => ""}
},
}.each do |name, params|
it name do
serialize(params[:input], params[:regexp], params)
end
end
end

describe "with language" do
it "specifies language for literal with language" do
ttl = %q(<http://a> <http:/b> "string"@en .)
serialize(ttl, [%r("string"@en)])
end
end

describe "xsd:anyURI" do
it "uses xsd namespace for datatype" do
ttl = %q(@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <http://a> <http:/b> "http://foo/"^^xsd:anyURI .)
Expand All @@ -341,7 +356,7 @@
])
end
end

describe "xsd:boolean" do
[
[%q("true"^^xsd:boolean), /true ./],
Expand Down Expand Up @@ -397,7 +412,7 @@
end
end
end

describe "xsd:integer" do
[
[%q("1"^^xsd:integer), /1 ./],
Expand Down Expand Up @@ -520,7 +535,7 @@
end
end
end

describe "xsd:double" do
[
[%q("1.0e1"^^xsd:double), /1.0e1 ./],
Expand Down Expand Up @@ -639,7 +654,7 @@ def serialize(ntstr, regexps = [], base_uri: nil, **options)
logger.info "match: #{re.inspect}"
expect(result).to match_re(re, about: base_uri, logger: logger, input: ntstr), logger.to_s
end

result
end
end
end

0 comments on commit e765a91

Please sign in to comment.