2019-04-30 10:27:42 +10:00
# frozen_string_literal: true
2022-07-28 05:27:38 +03:00
RSpec . describe Encodings do
2018-07-31 12:02:18 +02:00
def to_utf8 ( filename )
2018-07-27 19:41:53 +02:00
string = File . read ( " #{ Rails . root } /spec/fixtures/encodings/ #{ filename } " ) . chomp
2018-07-31 12:02:18 +02:00
Encodings . to_utf8 ( string )
2018-07-27 19:41:53 +02:00
end
2022-07-27 18:14:14 +02:00
describe " unicode " do
2023-01-09 11:18:21 +00:00
let ( :expected ) do
" Τ ο σύστημα γραφής είναι ένα συμβολικό, οπτικό σύστημα καταγραφής της γλώσσας."
end
2018-07-27 19:41:53 +02:00
it " correctly encodes UTF-8 as UTF-8 " do
2023-01-09 11:18:21 +00:00
expect ( to_utf8 ( " utf-8.txt " ) ) . to eq ( expected )
2018-07-27 19:41:53 +02:00
end
it " correctly encodes UTF-8 with BOM as UTF-8 " do
2023-01-09 11:18:21 +00:00
expect ( to_utf8 ( " utf-8-bom.txt " ) ) . to eq ( expected )
2018-07-27 19:41:53 +02:00
end
it " correctly encodes UTF-16LE with BOM as UTF-8 " do
2023-01-09 11:18:21 +00:00
expect ( to_utf8 ( " utf-16le.txt " ) ) . to eq ( expected )
2018-07-27 19:41:53 +02:00
end
it " correctly encodes UTF-16BE with BOM as UTF-8 " do
2023-01-09 11:18:21 +00:00
expect ( to_utf8 ( " utf-16be.txt " ) ) . to eq ( expected )
2018-07-27 19:41:53 +02:00
end
end
it " correctly encodes ISO-8859-5 as UTF-8 " do
2023-01-09 11:18:21 +00:00
expect ( to_utf8 ( " iso-8859-5.txt " ) ) . to eq (
" Письменность отличается от других существующих или возможных систем символической коммуникации тем, что всегда ассоциируется с некоторым языком и устной речью на этом языке " ,
)
2018-07-27 19:41:53 +02:00
end
end