Skip to content

Commit

Permalink
new failing tests for char escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
jlgeering authored and mruoss committed Aug 25, 2022
1 parent a730ebc commit 13e1279
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/ymlr/encoder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ defmodule Ymlr.EncoderTest do
end

test "quoted strings - escape seq forces double quotes (tab char)" do
assert MUT.to_s!("a\tb") == ~s("a\tb")
assert MUT.to_s!("!a\tb") == ~s("!a\tb")
assert MUT.to_s!("a\tb") == ~S("a\tb")
assert MUT.to_s!("!a\tb") == ~S("!a\tb")
assert MUT.to_s!("a\tb\nc") == ~s("a\\tb\nc")
end

test "quoted strings - listy and mappy things" do
Expand All @@ -84,7 +85,18 @@ defmodule Ymlr.EncoderTest do
assert MUT.to_s!("{}") == ~S('{}')
assert MUT.to_s!("[{}]") == ~S('[{}]')
# ... (use double quotes if string contains single quotes)
assert MUT.to_s!(~S(["I don't know!\nRea|\y?"])) == ~S("[\"I don't know!\\nRea|\\y?\"]")
assert MUT.to_s!(~S(["I don't know!\nRea|\y?"])) == ~S("[\"I don't know!\nRea|\\y?\"]")
end

test "quoted strings - handling backslashes" do
# double quotes because of single quote
assert MUT.to_s!(~s(a'bc\\w)) == ~S("a'bc\\w")
# double quotes because of tab
assert MUT.to_s!(~s(a\tbc\\w)) == ~S("a\tbc\\w")
# double quotes because of tab but with newline
assert MUT.to_s!(~s(a\tb\nc\\w)) == ~s("a\\tb\nc\\\\w")
# no double quotes
assert MUT.to_s!(~S(a\b)) == ~S(a\b)
end

test "quoted strings - in map key" do
Expand Down

0 comments on commit 13e1279

Please sign in to comment.