Added assertions for newline decorators

This commit is contained in:
Nobuyoshi Nakada 2020-01-11 10:14:53 +09:00
Родитель 52a9e4ffd3
Коммит 8bb24712de
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4BC7D6DF58D8DF60
2 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -912,6 +912,19 @@ class TestEncodingConverter < Test::Unit::TestCase
assert_raise_with_message(ArgumentError, /\u{3042}/) {
Encoding::Converter.new("", "", newline: "\u{3042}".to_sym)
}
newlines = %i[universal_newline crlf_newline cr_newline]
(2..newlines.size).each do |i|
newlines.combination(i) do |opts|
assert_raise(Encoding::ConverterNotFoundError, "#{opts} are mutually exclusive") do
Encoding::Converter.new("", "", **opts.inject({}) {|o,nl|o[nl]=true;o})
end
end
end
newlines.each do |nl|
opts = {newline: :universal, nl => true}
ec2 = Encoding::Converter.new("", "", **opts)
assert_equal(ec1, ec2)
end
end
def test_default_external

Просмотреть файл

@ -2242,12 +2242,19 @@ class TestTranscode < Test::Unit::TestCase
"#{bug} coderange should not have side effects")
end
def test_universal_newline
def test_newline_options
bug11324 = '[ruby-core:69841] [Bug #11324]'
usascii = Encoding::US_ASCII
s = "A\nB\r\nC".force_encoding(usascii)
assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true), bug11324)
assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true, undef: :replace), bug11324)
assert_equal("A\nB\nC", s.encode(usascii, universal_newline: true, undef: :replace, replace: ''), bug11324)
assert_equal("A\nB\nC", s.encode(usascii, newline: :universal))
assert_equal("A\nB\nC", s.encode(usascii, newline: :universal, undef: :replace))
assert_equal("A\nB\nC", s.encode(usascii, newline: :universal, undef: :replace, replace: ''))
assert_equal("A\rB\r\rC", s.encode(usascii, cr_newline: true))
assert_equal("A\rB\r\rC", s.encode(usascii, newline: :cr))
assert_equal("A\r\nB\r\r\nC", s.encode(usascii, crlf_newline: true))
assert_equal("A\r\nB\r\r\nC", s.encode(usascii, newline: :crlf))
end
end