diff --git a/lib/ymlr/encoder_test.exs b/lib/ymlr/encoder_test.exs index dc0ec7a..7901591 100644 --- a/lib/ymlr/encoder_test.exs +++ b/lib/ymlr/encoder_test.exs @@ -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 @@ -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