Skip to content

Commit

Permalink
add test coverage for cases where strings starting with "?", ":", or …
Browse files Browse the repository at this point in the history
…"-" may be encoded in Plain Style
  • Loading branch information
mlwilkerson authored and mruoss committed Dec 27, 2023
1 parent 257028b commit e793e4d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/ymlr/encode_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ defmodule Ymlr.EncodeTest do
test "plain strings" do
assert_identity_and_output("hello world", "hello world")
assert_identity_and_output("that's it", "that's it")

# Strings where the ":", "?", or "-" indicator character is used as the
# first character may be encoded in Plain Style (without being quoted)
# if followed by a non-space “safe” character.
# https://yaml.org/spec/1.2.2/#733-plain-style
assert_identity_and_output("?x", ~S(?x))
assert_identity_and_output(":x", ~S(:x))
assert_identity_and_output("-x", ~S(-x))
end

# see http://blogs.perl.org/users/tinita/2018/03/strings-in-yaml---to-quote-or-not-to-quote.html
Expand Down Expand Up @@ -71,7 +79,7 @@ defmodule Ymlr.EncodeTest do
assert_identity_and_output("@", ~S('@'))
assert_identity_and_output("`", ~S('`'))
end

test "quoted strings - starts with special char" do
assert_identity_and_output("!tag", ~S('!tag'))
assert_identity_and_output("&anchor", ~S('&anchor'))
Expand Down

0 comments on commit e793e4d

Please sign in to comment.