mirror of https://github.com/erickguan/ffi-icu.git
Update RSpec to 3.9 and address deprecation warnings (#40)
See https://relishapp.com/rspec/rspec-core/v/3-9/docs for more on docs This addresses deprecation warnings re: `should` and friends as well.
This commit is contained in:
parent
487bcb4cf4
commit
8aea54b8a7
|
@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|||
s.summary = %q{Simple Ruby FFI wrappers for things I need from ICU.}
|
||||
|
||||
s.add_runtime_dependency "ffi", "~> 1.0", ">= 1.0.9"
|
||||
s.add_development_dependency 'rspec', '~> 2.5', '>= 2.5.0'
|
||||
s.add_development_dependency 'rspec', '~> 3.9'
|
||||
s.add_development_dependency "rake", [">= 12.3.3"]
|
||||
end
|
||||
|
||||
|
|
|
@ -1,75 +1,77 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
module ICU
|
||||
describe BreakIterator do
|
||||
|
||||
it "should return available locales" do
|
||||
locales = ICU::BreakIterator.available_locales
|
||||
locales.should be_kind_of(Array)
|
||||
locales.should_not be_empty
|
||||
locales.should include("en_US")
|
||||
expect(locales).to be_an(Array)
|
||||
expect(locales).to_not be_empty
|
||||
expect(locales).to include("en_US")
|
||||
end
|
||||
|
||||
it "finds all word boundaries in an English string" do
|
||||
iterator = BreakIterator.new :word, "en_US"
|
||||
iterator.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
||||
iterator.to_a.should == [0, 5, 6, 11, 12, 17, 18, 21, 22, 26, 27, 28, 39, 40, 51, 52, 56, 57, 58, 61, 62, 64, 65, 72, 73, 79, 80, 90, 91, 93, 94, 100, 101, 103, 104, 110, 111, 116, 117, 123, 124]
|
||||
expect(iterator.to_a).to eq(
|
||||
[0, 5, 6, 11, 12, 17, 18, 21, 22, 26, 27, 28, 39, 40, 51, 52, 56, 57, 58, 61, 62, 64, 65, 72, 73, 79, 80, 90, 91, 93, 94, 100, 101, 103, 104, 110, 111, 116, 117, 123, 124]
|
||||
)
|
||||
end
|
||||
|
||||
it "returns each substring" do
|
||||
iterator = BreakIterator.new :word, "en_US"
|
||||
iterator.text = "Lorem ipsum dolor sit amet."
|
||||
|
||||
iterator.substrings.should == ["Lorem", " ", "ipsum", " ", "dolor", " ", "sit", " ", "amet", "."]
|
||||
expect(iterator.substrings).to eq(["Lorem", " ", "ipsum", " ", "dolor", " ", "sit", " ", "amet", "."])
|
||||
end
|
||||
|
||||
it "returns the substrings of a non-ASCII string" do
|
||||
iterator = BreakIterator.new :word, "th_TH"
|
||||
iterator.text = "รู้อะไรไม่สู้รู้วิชา รู้รักษาตัวรอดเป็นยอดดี"
|
||||
|
||||
iterator.substrings.should == ["รู้", "อะไร", "ไม่สู้", "รู้", "วิชา", " ", "รู้", "รักษา", "ตัว", "รอด", "เป็น", "ยอดดี"]
|
||||
expect(iterator.substrings).to eq(
|
||||
["รู้", "อะไร", "ไม่สู้", "รู้", "วิชา", " ", "รู้", "รักษา", "ตัว", "รอด", "เป็น", "ยอดดี"]
|
||||
)
|
||||
end
|
||||
|
||||
it "finds all word boundaries in a non-ASCII string" do
|
||||
iterator = BreakIterator.new :word, "th_TH"
|
||||
iterator.text = "การทดลอง"
|
||||
iterator.to_a.should == [0, 3, 8]
|
||||
expect(iterator.to_a).to eq([0, 3, 8])
|
||||
end
|
||||
|
||||
it "finds all sentence boundaries in an English string" do
|
||||
iterator = BreakIterator.new :sentence, "en_US"
|
||||
iterator.text = "This is a sentence. This is another sentence, with a comma in it."
|
||||
iterator.to_a.should == [0, 20, 65]
|
||||
expect(iterator.to_a).to eq([0, 20, 65])
|
||||
end
|
||||
|
||||
it "can navigate back and forward" do
|
||||
iterator = BreakIterator.new :word, "en_US"
|
||||
iterator.text = "Lorem ipsum dolor sit amet."
|
||||
|
||||
iterator.first.should == 0
|
||||
expect(iterator.first).to eq(0)
|
||||
iterator.next
|
||||
iterator.current.should == 5
|
||||
iterator.last.should == 27
|
||||
expect(iterator.current).to eq(5)
|
||||
expect(iterator.last).to eq(27)
|
||||
end
|
||||
|
||||
it "fetches info about given offset" do
|
||||
iterator = BreakIterator.new :word, "en_US"
|
||||
iterator.text = "Lorem ipsum dolor sit amet."
|
||||
|
||||
iterator.following(3).should == 5
|
||||
iterator.preceding(6).should == 5
|
||||
expect(iterator.following(3)).to eq(5)
|
||||
expect(iterator.preceding(6)).to eq(5)
|
||||
|
||||
iterator.should be_boundary(5)
|
||||
iterator.should_not be_boundary(10)
|
||||
expect(iterator).to be_boundary(5)
|
||||
expect(iterator).to_not be_boundary(10)
|
||||
end
|
||||
|
||||
it "returns an Enumerator if no block was given" do
|
||||
iterator = BreakIterator.new :word, "nb"
|
||||
expected = ICU.ruby19? ? Enumerator : Enumerable::Enumerator
|
||||
|
||||
iterator.each.should be_kind_of(expected)
|
||||
expect(iterator.each).to be_kind_of(expected)
|
||||
end
|
||||
|
||||
end # BreakIterator
|
||||
|
|
|
@ -1,29 +1,27 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ICU::CharDet::Detector do
|
||||
|
||||
let(:detector) { ICU::CharDet::Detector.new }
|
||||
|
||||
it "should recognize UTF-8" do
|
||||
m = detector.detect("æåø")
|
||||
m.name.should == "UTF-8"
|
||||
m.language.should be_kind_of(String)
|
||||
expect(m.name).to eq("UTF-8")
|
||||
expect(m.language).to be_a(String)
|
||||
end
|
||||
|
||||
it "has a list of detectable charsets" do
|
||||
cs = detector.detectable_charsets
|
||||
cs.should be_kind_of(Array)
|
||||
cs.should_not be_empty
|
||||
expect(cs).to be_an(Array)
|
||||
expect(cs).to_not be_empty
|
||||
|
||||
cs.first.should be_kind_of(String)
|
||||
expect(cs.first).to be_a(String)
|
||||
end
|
||||
|
||||
it "should disable / enable the input filter" do
|
||||
detector.input_filter_enabled?.should be_false
|
||||
expect(detector.input_filter_enabled?).to be_falsey
|
||||
detector.input_filter_enabled = true
|
||||
detector.input_filter_enabled?.should be_true
|
||||
expect(detector.input_filter_enabled?).to be_truthy
|
||||
end
|
||||
|
||||
it "should should set declared encoding" do
|
||||
|
@ -31,14 +29,14 @@ describe ICU::CharDet::Detector do
|
|||
end
|
||||
|
||||
it "should detect several matching encodings" do
|
||||
detector.detect_all("foo bar").should be_instance_of(Array)
|
||||
expect(detector.detect_all("foo bar")).to be_an(Array)
|
||||
end
|
||||
|
||||
it "should support null bytes" do
|
||||
# Create a utf-16 string and then force it to binary (ascii) to mimic data from net/http
|
||||
string = "foo".encode("UTF-16").force_encoding("binary")
|
||||
m = detector.detect(string)
|
||||
m.name.should == "UTF-16BE"
|
||||
m.language.should be_kind_of(String)
|
||||
expect(m.name).to eq("UTF-16BE")
|
||||
expect(m.language).to be_a(String)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
module Collation
|
||||
describe "Collation" do
|
||||
it "should collate an array of strings" do
|
||||
Collation.collate("nb", %w[æ å ø]).should == %w[æ ø å]
|
||||
expect(Collation.collate("nb", %w[æ å ø])).to eq(%w[æ ø å])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -14,51 +12,50 @@ module ICU
|
|||
let(:collator) { Collator.new("nb") }
|
||||
|
||||
it "should collate an array of strings" do
|
||||
collator.collate(%w[å ø æ]).should == %w[æ ø å]
|
||||
expect(collator.collate(%w[å ø æ])).to eq(%w[æ ø å])
|
||||
end
|
||||
|
||||
it "raises an error if argument does not respond to :sort" do
|
||||
lambda { collator.collate(1) }.should raise_error(ArgumentError)
|
||||
expect { collator.collate(1) }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should return available locales" do
|
||||
locales = ICU::Collation.available_locales
|
||||
locales.should be_kind_of(Array)
|
||||
locales.should_not be_empty
|
||||
locales.should include("nb")
|
||||
expect(locales).to be_an(Array)
|
||||
expect(locales).to_not be_empty
|
||||
expect(locales).to include("nb")
|
||||
end
|
||||
|
||||
it "should return the locale of the collator" do
|
||||
l = collator.locale
|
||||
l.should == "nb"
|
||||
expect(collator.locale).to eq('nb')
|
||||
end
|
||||
|
||||
it "should compare two strings" do
|
||||
collator.compare("blåbærsyltetøy", "blah").should == 1
|
||||
collator.compare("blah", "blah").should == 0
|
||||
collator.compare("ba", "bl").should == -1
|
||||
expect(collator.compare("blåbærsyltetøy", "blah")).to eq(1)
|
||||
expect(collator.compare("blah", "blah")).to eq(0)
|
||||
expect(collator.compare("ba", "bl")).to eq(-1)
|
||||
end
|
||||
|
||||
it "should know if a string is greater than another" do
|
||||
collator.should be_greater("z", "a")
|
||||
collator.should_not be_greater("a", "z")
|
||||
expect(collator).to be_greater("z", "a")
|
||||
expect(collator).to_not be_greater("a", "z")
|
||||
end
|
||||
|
||||
it "should know if a string is greater or equal to another" do
|
||||
collator.should be_greater_or_equal("z", "a")
|
||||
collator.should be_greater_or_equal("z", "z")
|
||||
collator.should_not be_greater_or_equal("a", "z")
|
||||
expect(collator).to be_greater_or_equal("z", "a")
|
||||
expect(collator).to be_greater_or_equal("z", "z")
|
||||
expect(collator).to_not be_greater_or_equal("a", "z")
|
||||
end
|
||||
|
||||
it "should know if a string is equal to another" do
|
||||
collator.should be_equal("a", "a")
|
||||
collator.should_not be_equal("a", "b")
|
||||
expect(collator).to be_equal("a", "a")
|
||||
expect(collator).to_not be_equal("a", "b")
|
||||
end
|
||||
|
||||
it "should return rules" do
|
||||
collator.rules.should_not be_empty
|
||||
expect(collator.rules).to_not be_empty
|
||||
# ö sorts before Ö
|
||||
collator.rules.include?('ö<<<Ö').should be_true
|
||||
expect(collator.rules).to include('ö<<<Ö')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
module Lib
|
||||
describe VersionInfo do
|
||||
its(:to_a) { should be_an Array }
|
||||
its(:to_s) do
|
||||
should be_a String
|
||||
should match /^[0-9.]+$/
|
||||
describe '.to_a' do
|
||||
subject { described_class.new.to_a }
|
||||
|
||||
it { is_expected.to be_an(Array) }
|
||||
end
|
||||
|
||||
describe '.to_s' do
|
||||
subject { described_class.new.to_s }
|
||||
|
||||
it { is_expected.to be_a(String) }
|
||||
it { is_expected.to match(/^[0-9.]+$/) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
describe Lib do
|
||||
describe 'error checking' do
|
||||
|
@ -9,8 +7,8 @@ module ICU
|
|||
|
||||
context 'upon success' do
|
||||
it 'returns the block result' do
|
||||
Lib.check_error { |status| return_value }.should == return_value
|
||||
Lib.check_error { |status| status.write_int(0); return_value }.should == return_value
|
||||
expect(Lib.check_error { |status| return_value }).to eq(return_value)
|
||||
expect(Lib.check_error { |status| status.write_int(0); return_value }).to eq(return_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,8 +26,9 @@ module ICU
|
|||
before(:each) { $VERBOSE = true }
|
||||
|
||||
it 'prints to STDERR and returns the block result' do
|
||||
$stderr.should_receive(:puts) { |message| message.should match /U_.*_WARNING/ }
|
||||
Lib.check_error { |status| status.write_int(-127); return_value }.should == return_value
|
||||
expect($stderr).to receive(:puts) { |message| expect(message).to match /U_.*_WARNING/ }
|
||||
error_check = Lib.check_error { |status| status.write_int(-127); return_value }
|
||||
expect(error_check).to eq(return_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,8 +36,9 @@ module ICU
|
|||
before(:each) { $VERBOSE = false }
|
||||
|
||||
it 'returns the block result' do
|
||||
$stderr.should_not_receive(:puts)
|
||||
Lib.check_error { |status| status.write_int(-127); return_value }.should == return_value
|
||||
expect($stderr).to_not receive(:puts)
|
||||
error_check = Lib.check_error { |status| status.write_int(-127); return_value }
|
||||
expect(error_check).to eq(return_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -49,15 +49,15 @@ module ICU
|
|||
subject { Lib.cldr_version }
|
||||
|
||||
it { should be_a Lib::VersionInfo }
|
||||
it('is populated') { subject.to_a.should_not == [0,0,0,0] }
|
||||
it('is populated') { expect(subject.to_a).to_not eq([0,0,0,0]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ICU version' do
|
||||
subject { Lib.version }
|
||||
|
||||
it { should be_a Lib::VersionInfo }
|
||||
it('is populated') { subject.to_a.should_not == [0,0,0,0] }
|
||||
it { is_expected.to be_a Lib::VersionInfo }
|
||||
it('is populated') { expect(subject.to_a).to_not eq([0,0,0,0]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,31 +1,38 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
describe Locale do
|
||||
describe 'the available locales' do
|
||||
subject { Locale.available }
|
||||
|
||||
it { should be_an Array }
|
||||
it { should_not be_empty }
|
||||
its(:first) { should be_a Locale }
|
||||
it { is_expected.to be_an Array }
|
||||
it { is_expected.to_not be_empty }
|
||||
|
||||
it 'should be an array of available Locales' do
|
||||
expect(subject.first).to be_a(Locale)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the available ISO 639 country codes' do
|
||||
subject { Locale.iso_countries }
|
||||
|
||||
it { should be_an Array }
|
||||
it { should_not be_empty }
|
||||
its(:first) { should be_a String }
|
||||
it { is_expected.to be_an Array }
|
||||
it { is_expected.to_not be_empty }
|
||||
|
||||
it 'should be an array of Strings' do
|
||||
expect(subject.first).to be_a(String)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the available ISO 639 language codes' do
|
||||
subject { Locale.iso_languages }
|
||||
|
||||
it { should be_an Array }
|
||||
it { should_not be_empty }
|
||||
its(:first) { should be_a String }
|
||||
it { is_expected.to be_an Array }
|
||||
it { is_expected.to_not be_empty }
|
||||
|
||||
it 'should be an array of Strings' do
|
||||
expect(subject.first).to be_a(String)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the default' do
|
||||
|
@ -37,44 +44,44 @@ module ICU
|
|||
locales.respond_to?(:sample) ? locales.sample : locales.choice
|
||||
end
|
||||
|
||||
it { should be_a Locale }
|
||||
it { is_expected.to be_a Locale }
|
||||
|
||||
it 'can be assigned using Locale' do
|
||||
(Locale.default = locale).should == locale
|
||||
Locale.default.should == locale
|
||||
expect(Locale.default = locale).to eq(locale)
|
||||
expect(Locale.default).to eq(locale)
|
||||
end
|
||||
|
||||
it 'can be assigned using string' do
|
||||
string = locale.to_s
|
||||
|
||||
(Locale.default = string).should == string
|
||||
Locale.default.should == Locale.new(string)
|
||||
expect(Locale.default = string).to eq(string)
|
||||
expect(Locale.default).to eq(Locale.new(string))
|
||||
end
|
||||
|
||||
it 'can be assigned using symbol' do
|
||||
symbol = locale.to_s.to_sym
|
||||
|
||||
(Locale.default = symbol).should == symbol
|
||||
Locale.default.should == Locale.new(symbol)
|
||||
expect(Locale.default = symbol).to eq(symbol)
|
||||
expect(Locale.default).to eq(Locale.new(symbol))
|
||||
end
|
||||
end
|
||||
|
||||
if Gem::Version.new('4.2') <= Gem::Version.new(Lib.version)
|
||||
describe 'BCP 47 language tags' do
|
||||
it 'converts a language tag to a locale' do
|
||||
Locale.for_language_tag('en-us').should == Locale.new('en_US')
|
||||
Locale.for_language_tag('nan-Hant-tw').should == Locale.new('nan_Hant_TW')
|
||||
expect(Locale.for_language_tag('en-us')).to eq(Locale.new('en_US'))
|
||||
expect(Locale.for_language_tag('nan-Hant-tw')).to eq(Locale.new('nan_Hant_TW'))
|
||||
end
|
||||
|
||||
it 'returns a language tag for a locale' do
|
||||
if Gem::Version.new('4.4') <= Gem::Version.new(Lib.version)
|
||||
Locale.new('en_US').to_language_tag.should == 'en-US'
|
||||
Locale.new('zh_TW').to_language_tag.should == 'zh-TW'
|
||||
Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-Hans-CH-u-co-pinyin'
|
||||
expect(Locale.new('en_US').to_language_tag).to eq('en-US')
|
||||
expect(Locale.new('zh_TW').to_language_tag).to eq('zh-TW')
|
||||
expect(Locale.new('zh_Hans_CH_PINYIN').to_language_tag).to eq('zh-Hans-CH-u-co-pinyin')
|
||||
else
|
||||
Locale.new('en_US').to_language_tag.should == 'en-us'
|
||||
Locale.new('zh_TW').to_language_tag.should == 'zh-tw'
|
||||
Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-hans-ch-u-co-pinyin'
|
||||
expect(Locale.new('en_US').to_language_tag).to eq('en-us')
|
||||
expect(Locale.new('zh_TW').to_language_tag).to eq('zh-tw')
|
||||
expect(Locale.new('zh_Hans_CH_PINYIN').to_language_tag).to eq('zh-hans-ch-u-co-pinyin')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -82,13 +89,13 @@ module ICU
|
|||
|
||||
describe 'Win32 locale IDs' do
|
||||
it 'converts an LCID to a locale' do
|
||||
Locale.for_lcid(1033).should == Locale.new('en_US')
|
||||
Locale.for_lcid(1036).should == Locale.new('fr_FR')
|
||||
expect(Locale.for_lcid(1033)).to eq(Locale.new('en_US'))
|
||||
expect(Locale.for_lcid(1036)).to eq(Locale.new('fr_FR'))
|
||||
end
|
||||
|
||||
it 'returns an LCID for a locale' do
|
||||
Locale.new('en_US').lcid.should == 1033
|
||||
Locale.new('es_US').lcid.should == 21514
|
||||
expect(Locale.new('en_US').lcid).to eq(1033)
|
||||
expect(Locale.new('es_US').lcid).to eq(21514)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -97,39 +104,39 @@ module ICU
|
|||
|
||||
context 'in a specific locale' do
|
||||
it 'returns the country' do
|
||||
Locale.new('de_DE').display_country('en').should == 'Germany'
|
||||
Locale.new('en_US').display_country('fr').should == 'États-Unis'
|
||||
expect(Locale.new('de_DE').display_country('en')).to eq('Germany')
|
||||
expect(Locale.new('en_US').display_country('fr')).to eq('États-Unis')
|
||||
end
|
||||
|
||||
it 'returns the language' do
|
||||
Locale.new('fr_FR').display_language('de').should == 'Französisch'
|
||||
Locale.new('zh_CH').display_language('en').should == 'Chinese'
|
||||
expect(Locale.new('fr_FR').display_language('de')).to eq('Französisch')
|
||||
expect(Locale.new('zh_CH').display_language('en')).to eq('Chinese')
|
||||
end
|
||||
|
||||
it 'returns the name' do
|
||||
Locale.new('en_US').display_name('de').should == 'Englisch (Vereinigte Staaten)'
|
||||
Locale.new('zh_CH').display_name('fr').should == 'chinois (Suisse)'
|
||||
expect(Locale.new('en_US').display_name('de')).to eq('Englisch (Vereinigte Staaten)')
|
||||
expect(Locale.new('zh_CH').display_name('fr')).to eq('chinois (Suisse)')
|
||||
end
|
||||
|
||||
it 'returns the script' do
|
||||
Locale.new('ja_Hira_JP').display_script('en').should == 'Hiragana'
|
||||
Locale.new('ja_Hira_JP').display_script('ru').should == 'хирагана'
|
||||
expect(Locale.new('ja_Hira_JP').display_script('en')).to eq('Hiragana')
|
||||
expect(Locale.new('ja_Hira_JP').display_script('ru')).to eq('хирагана')
|
||||
end
|
||||
|
||||
it 'returns the variant' do
|
||||
Locale.new('be_BY_TARASK').display_variant('de').should == 'Taraskievica-Orthographie'
|
||||
Locale.new('zh_CH_POSIX').display_variant('en').should == 'Computer'
|
||||
expect(Locale.new('be_BY_TARASK').display_variant('de')).to eq('Taraskievica-Orthographie')
|
||||
expect(Locale.new('zh_CH_POSIX').display_variant('en')).to eq('Computer')
|
||||
end
|
||||
|
||||
# If memory set for 'read_uchar_buffer' is set too low it will throw an out
|
||||
# of bounds memory error, which results in a Segmentation fault error.
|
||||
it 'insures memory sizes is set correctly' do
|
||||
# Currently, testing the longest known locales. May need to be update in the future.
|
||||
Locale.new('en_VI').display_country('ccp').should_not be_nil
|
||||
Locale.new('yue_Hant').display_language('ccp').should_not be_nil
|
||||
Locale.new('en_VI').display_name('ccp').should_not be_nil
|
||||
Locale.new('yue_Hant').display_script('ccp').should_not be_nil
|
||||
Locale.new('en_US_POSIX').display_variant('sl').should_not be_nil
|
||||
expect(Locale.new('en_VI').display_country('ccp')).to_not be_nil
|
||||
expect(Locale.new('yue_Hant').display_language('ccp')).to_not be_nil
|
||||
expect(Locale.new('en_VI').display_name('ccp')).to_not be_nil
|
||||
expect(Locale.new('yue_Hant').display_script('ccp')).to_not be_nil
|
||||
expect(Locale.new('en_US_POSIX').display_variant('sl')).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -137,23 +144,23 @@ module ICU
|
|||
let(:locale) { Locale.new('de_DE') }
|
||||
|
||||
it 'returns the country' do
|
||||
locale.display_country.should == locale.display_country(Locale.default)
|
||||
expect(locale.display_country).to eq(locale.display_country(Locale.default))
|
||||
end
|
||||
|
||||
it 'returns the language' do
|
||||
locale.display_language.should == locale.display_language(Locale.default)
|
||||
expect(locale.display_language).to eq(locale.display_language(Locale.default))
|
||||
end
|
||||
|
||||
it 'returns the name' do
|
||||
locale.display_name.should == locale.display_name(Locale.default)
|
||||
expect(locale.display_name).to eq(locale.display_name(Locale.default))
|
||||
end
|
||||
|
||||
it 'returns the script' do
|
||||
locale.display_script.should == locale.display_script(Locale.default)
|
||||
expect(locale.display_script).to eq(locale.display_script(Locale.default))
|
||||
end
|
||||
|
||||
it 'returns the variant' do
|
||||
locale.display_variant.should == locale.display_variant(Locale.default)
|
||||
expect(locale.display_variant).to eq(locale.display_variant(Locale.default))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -161,26 +168,26 @@ module ICU
|
|||
describe 'formatting' do
|
||||
let(:locale) { Locale.new('de-de.utf8@collation = phonebook') }
|
||||
|
||||
it('is formatted') { locale.name.should == 'de_DE.utf8@collation=phonebook' }
|
||||
it('is formatted without keywords') { locale.base_name.should == 'de_DE.utf8' }
|
||||
it('is formatted for ICU') { locale.canonical.should == 'de_DE@collation=phonebook' }
|
||||
it('is formatted') { expect(locale.name).to eq('de_DE.utf8@collation=phonebook') }
|
||||
it('is formatted without keywords') { expect(locale.base_name).to eq('de_DE.utf8') }
|
||||
it('is formatted for ICU') { expect(locale.canonical).to eq('de_DE@collation=phonebook') }
|
||||
end
|
||||
|
||||
it 'truncates a properly formatted locale, returning the "parent"' do
|
||||
Locale.new('es-mx').parent.should == ''
|
||||
Locale.new('es_MX').parent.should == 'es'
|
||||
Locale.new('zh_Hans_CH_PINYIN').parent.should == 'zh_Hans_CH'
|
||||
expect(Locale.new('es-mx').parent).to eq('')
|
||||
expect(Locale.new('es_MX').parent).to eq('es')
|
||||
expect(Locale.new('zh_Hans_CH_PINYIN').parent).to eq('zh_Hans_CH')
|
||||
end
|
||||
|
||||
describe 'ISO codes' do
|
||||
it 'returns the ISO 3166 alpha-3 country code' do
|
||||
Locale.new('en_US').iso_country.should == 'USA'
|
||||
Locale.new('zh_CN').iso_country.should == 'CHN'
|
||||
expect(Locale.new('en_US').iso_country).to eq('USA')
|
||||
expect(Locale.new('zh_CN').iso_country).to eq('CHN')
|
||||
end
|
||||
|
||||
it 'returns the ISO 639 three-letter language code' do
|
||||
Locale.new('en_US').iso_language.should == 'eng'
|
||||
Locale.new('zh_CN').iso_language.should == 'zho'
|
||||
expect(Locale.new('en_US').iso_language).to eq('eng')
|
||||
expect(Locale.new('zh_CN').iso_language).to eq('zho')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -197,64 +204,64 @@ module ICU
|
|||
let(:locale) { Locale.new('de_DE@currency=EUR') }
|
||||
|
||||
it 'returns the list of keywords' do
|
||||
locale.keywords.should == ['currency']
|
||||
expect(locale.keywords).to eq(['currency'])
|
||||
end
|
||||
end
|
||||
|
||||
it 'can be read' do
|
||||
Locale.new('en_US@calendar=chinese').keyword('calendar').should == 'chinese'
|
||||
Locale.new('en_US@calendar=chinese').keyword(:calendar).should == 'chinese'
|
||||
Locale.new('en_US@some=thing').keyword('missing').should == ''
|
||||
expect(Locale.new('en_US@calendar=chinese').keyword('calendar')).to eq('chinese')
|
||||
expect(Locale.new('en_US@calendar=chinese').keyword(:calendar)).to eq('chinese')
|
||||
expect(Locale.new('en_US@some=thing').keyword('missing')).to eq('')
|
||||
end
|
||||
|
||||
it 'can be added' do
|
||||
Locale.new('de_DE').with_keyword('currency', 'EUR').should == Locale.new('de_DE@currency=EUR')
|
||||
Locale.new('de_DE').with_keyword(:currency, :EUR).should == Locale.new('de_DE@currency=EUR')
|
||||
expect(Locale.new('de_DE').with_keyword('currency', 'EUR')).to eq(Locale.new('de_DE@currency=EUR'))
|
||||
expect(Locale.new('de_DE').with_keyword(:currency, :EUR)).to eq(Locale.new('de_DE@currency=EUR'))
|
||||
end
|
||||
|
||||
it 'can be added using hash' do
|
||||
Locale.new('fr').with_keywords(:a => :b, :c => :d).should == Locale.new('fr@a=b;c=d')
|
||||
expect(Locale.new('fr').with_keywords(:a => :b, :c => :d)).to eq(Locale.new('fr@a=b;c=d'))
|
||||
end
|
||||
|
||||
it 'can be removed' do
|
||||
Locale.new('en_US@some=thing').with_keyword(:some, nil).should == Locale.new('en_US')
|
||||
Locale.new('en_US@some=thing').with_keyword(:some, '').should == Locale.new('en_US')
|
||||
expect(Locale.new('en_US@some=thing').with_keyword(:some, nil)).to eq(Locale.new('en_US'))
|
||||
expect(Locale.new('en_US@some=thing').with_keyword(:some, '')).to eq(Locale.new('en_US'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'orientation' do
|
||||
it 'returns the character orientation' do
|
||||
Locale.new('ar').character_orientation.should == :rtl
|
||||
Locale.new('en').character_orientation.should == :ltr
|
||||
Locale.new('fa').character_orientation.should == :rtl
|
||||
expect(Locale.new('ar').character_orientation).to eq(:rtl)
|
||||
expect(Locale.new('en').character_orientation).to eq(:ltr)
|
||||
expect(Locale.new('fa').character_orientation).to eq(:rtl)
|
||||
end
|
||||
|
||||
it 'returns the line orientation' do
|
||||
Locale.new('ar').line_orientation.should == :ttb
|
||||
Locale.new('en').line_orientation.should == :ttb
|
||||
Locale.new('fa').line_orientation.should == :ttb
|
||||
expect(Locale.new('ar').line_orientation).to eq(:ttb)
|
||||
expect(Locale.new('en').line_orientation).to eq(:ttb)
|
||||
expect(Locale.new('fa').line_orientation).to eq(:ttb)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'subtags' do
|
||||
let(:locale) { Locale.new('zh-hans-ch-pinyin') }
|
||||
|
||||
it('returns the country code') { locale.country.should == 'CH' }
|
||||
it('returns the language code') { locale.language.should == 'zh' }
|
||||
it('returns the script code') { locale.script.should == 'Hans' }
|
||||
it('returns the variant code') { locale.variant.should == 'PINYIN' }
|
||||
it('returns the country code') { expect(locale.country).to eq('CH') }
|
||||
it('returns the language code') { expect(locale.language).to eq('zh') }
|
||||
it('returns the script code') { expect(locale.script).to eq('Hans') }
|
||||
it('returns the variant code') { expect(locale.variant).to eq('PINYIN') }
|
||||
|
||||
describe 'likely subtags according to UTS #35' do
|
||||
it 'adds likely subtags' do
|
||||
Locale.new('en').with_likely_subtags.should == Locale.new('en_Latn_US')
|
||||
Locale.new('sr').with_likely_subtags.should == Locale.new('sr_Cyrl_RS')
|
||||
Locale.new('zh_TW').with_likely_subtags.should == Locale.new('zh_Hant_TW')
|
||||
expect(Locale.new('en').with_likely_subtags).to eq(Locale.new('en_Latn_US'))
|
||||
expect(Locale.new('sr').with_likely_subtags).to eq(Locale.new('sr_Cyrl_RS'))
|
||||
expect(Locale.new('zh_TW').with_likely_subtags).to eq(Locale.new('zh_Hant_TW'))
|
||||
end
|
||||
|
||||
it 'removes likely subtags' do
|
||||
Locale.new('en_US').with_minimized_subtags.should == Locale.new('en')
|
||||
Locale.new('sr_RS').with_minimized_subtags.should == Locale.new('sr')
|
||||
Locale.new('zh_Hant_TW').with_minimized_subtags.should == Locale.new('zh_TW')
|
||||
expect(Locale.new('en_US').with_minimized_subtags).to eq(Locale.new('en'))
|
||||
expect(Locale.new('sr_RS').with_minimized_subtags).to eq(Locale.new('sr'))
|
||||
expect(Locale.new('zh_Hant_TW').with_minimized_subtags).to eq(Locale.new('zh_TW'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
module Normalization
|
||||
# http://bugs.icu-project.org/trac/browser/icu/trunk/source/test/cintltst/cnormtst.c
|
||||
|
@ -9,11 +7,11 @@ module ICU
|
|||
describe "Normalization" do
|
||||
|
||||
it "should normalize a string - decomposed" do
|
||||
ICU::Normalization.normalize("Å", :nfd).unpack("U*").should == [65, 778]
|
||||
expect(ICU::Normalization.normalize("Å", :nfd).unpack("U*")).to eq([65, 778])
|
||||
end
|
||||
|
||||
it "should normalize a string - composed" do
|
||||
ICU::Normalization.normalize("Å", :nfc).unpack("U*").should == [197]
|
||||
expect(ICU::Normalization.normalize("Å", :nfc).unpack("U*")).to eq([197])
|
||||
end
|
||||
|
||||
# TODO: add more normalization tests
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
describe Normalizer do
|
||||
describe 'NFD: nfc decompose' do
|
||||
let(:normalizer) { ICU::Normalizer.new(nil, 'nfc', :decompose) }
|
||||
|
||||
it "should normalize a string" do
|
||||
normalizer.normalize("Å").unpack("U*").should == [65, 778]
|
||||
normalizer.normalize("ô").unpack("U*").should == [111, 770]
|
||||
normalizer.normalize("a").unpack("U*").should == [97]
|
||||
normalizer.normalize("中文").unpack("U*").should == [20013, 25991]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 64259, 110]
|
||||
normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 8547]
|
||||
expect(normalizer.normalize("Å").unpack("U*")).to eq([65, 778])
|
||||
expect(normalizer.normalize("ô").unpack("U*")).to eq([111, 770])
|
||||
expect(normalizer.normalize("a").unpack("U*")).to eq([97])
|
||||
expect(normalizer.normalize("中文").unpack("U*")).to eq([20013, 25991])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 64259, 110])
|
||||
expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 8547])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,14 +21,14 @@ module ICU
|
|||
let(:normalizer) { ICU::Normalizer.new(nil, 'nfc', :compose) }
|
||||
|
||||
it "should normalize a string" do
|
||||
normalizer.normalize("Å").unpack("U*").should == [197]
|
||||
normalizer.normalize("ô").unpack("U*").should == [244]
|
||||
normalizer.normalize("a").unpack("U*").should == [97]
|
||||
normalizer.normalize("中文").unpack("U*").should == [20013, 25991]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [196, 64259, 110]
|
||||
normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 8547]
|
||||
expect(normalizer.normalize("Å").unpack("U*")).to eq([197])
|
||||
expect(normalizer.normalize("ô").unpack("U*")).to eq([244])
|
||||
expect(normalizer.normalize("a").unpack("U*")).to eq([97])
|
||||
expect(normalizer.normalize("中文").unpack("U*")).to eq([20013, 25991])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 64259, 110])
|
||||
expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 8547])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,10 +36,10 @@ module ICU
|
|||
let(:normalizer) { ICU::Normalizer.new(nil, 'nfkc', :decompose) }
|
||||
|
||||
it "should normalize a string" do
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
|
||||
normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,10 +47,10 @@ module ICU
|
|||
let(:normalizer) { ICU::Normalizer.new(nil, 'nfkc', :compose) }
|
||||
|
||||
it "should normalize a string" do
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
|
||||
normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
|
||||
normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
|
||||
expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
|
||||
end
|
||||
end
|
||||
end # Normalizer
|
||||
|
|
|
@ -1,68 +1,66 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
module NumberFormatting
|
||||
describe 'NumberFormatting' do
|
||||
it 'should format a simple integer' do
|
||||
NumberFormatting.format_number("en", 1).should == "1"
|
||||
NumberFormatting.format_number("en", 1_000).should == "1,000"
|
||||
NumberFormatting.format_number("de-DE", 1_000_000).should == "1.000.000"
|
||||
expect(NumberFormatting.format_number("en", 1)).to eq("1")
|
||||
expect(NumberFormatting.format_number("en", 1_000)).to eq("1,000")
|
||||
expect(NumberFormatting.format_number("de-DE", 1_000_000)).to eq("1.000.000")
|
||||
end
|
||||
|
||||
it 'should format a float' do
|
||||
NumberFormatting.format_number("en", 1.0).should == "1"
|
||||
NumberFormatting.format_number("en", 1.123).should == "1.123"
|
||||
NumberFormatting.format_number("en", 1_000.1238).should == "1,000.124"
|
||||
NumberFormatting.format_number("en", 1_000.1238, max_fraction_digits: 4).should == "1,000.1238"
|
||||
expect(NumberFormatting.format_number("en", 1.0)).to eq("1")
|
||||
expect(NumberFormatting.format_number("en", 1.123)).to eq("1.123")
|
||||
expect(NumberFormatting.format_number("en", 1_000.1238)).to eq("1,000.124")
|
||||
expect(NumberFormatting.format_number("en", 1_000.1238, max_fraction_digits: 4)).to eq("1,000.1238")
|
||||
NumberFormatting.set_default_options(fraction_digits: 5)
|
||||
NumberFormatting.format_number("en", 1_000.1238).should == "1,000.12380"
|
||||
expect(NumberFormatting.format_number("en", 1_000.1238)).to eq("1,000.12380")
|
||||
NumberFormatting.clear_default_options
|
||||
end
|
||||
|
||||
it 'should format a decimal' do
|
||||
NumberFormatting.format_number("en", BigDecimal.new("10000.123")).should == "10,000.123"
|
||||
expect(NumberFormatting.format_number("en", BigDecimal.new("10000.123"))).to eq("10,000.123")
|
||||
end
|
||||
|
||||
it 'should format a currency' do
|
||||
NumberFormatting.format_currency("en", 123.45, 'USD').should == "$123.45"
|
||||
NumberFormatting.format_currency("en", 123_123.45, 'USD').should == "$123,123.45"
|
||||
NumberFormatting.format_currency("de-DE", 123_123.45, 'EUR').should == "123.123,45\u{A0}€"
|
||||
expect(NumberFormatting.format_currency("en", 123.45, 'USD')).to eq("$123.45")
|
||||
expect(NumberFormatting.format_currency("en", 123_123.45, 'USD')).to eq("$123,123.45")
|
||||
expect(NumberFormatting.format_currency("de-DE", 123_123.45, 'EUR')).to eq("123.123,45\u{A0}€")
|
||||
end
|
||||
|
||||
it 'should format a percent' do
|
||||
NumberFormatting.format_percent("en", 1.1).should == "110%"
|
||||
NumberFormatting.format_percent("da", 0.15).should == "15\u{A0}%"
|
||||
NumberFormatting.format_percent("da", -0.1545, max_fraction_digits: 10).should == "-15,45\u{A0}%"
|
||||
expect(NumberFormatting.format_percent("en", 1.1)).to eq("110%")
|
||||
expect(NumberFormatting.format_percent("da", 0.15)).to eq("15\u{A0}%")
|
||||
expect(NumberFormatting.format_percent("da", -0.1545, max_fraction_digits: 10)).to eq("-15,45\u{A0}%")
|
||||
end
|
||||
|
||||
it 'should spell numbers' do
|
||||
NumberFormatting.spell("en_US", 1_000).should == 'one thousand'
|
||||
NumberFormatting.spell("de-DE", 123.456).should == "ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs"
|
||||
expect(NumberFormatting.spell("en_US", 1_000)).to eq('one thousand')
|
||||
expect(NumberFormatting.spell("de-DE", 123.456)).to eq("ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs")
|
||||
end
|
||||
|
||||
it 'should be able to re-use number formatter objects' do
|
||||
numf = NumberFormatting.create('fr-CA')
|
||||
numf.format(1_000).should == "1\u{A0}000"
|
||||
numf.format(1_000.123).should == "1\u{A0}000,123"
|
||||
expect(numf.format(1_000)).to eq("1\u{A0}000")
|
||||
expect(numf.format(1_000.123)).to eq("1\u{A0}000,123")
|
||||
end
|
||||
|
||||
it 'should be able to re-use currency formatter objects' do
|
||||
curf = NumberFormatting.create('en-US', :currency)
|
||||
curf.format(1_000.12, 'USD').should == "$1,000.12"
|
||||
expect(curf.format(1_000.12, 'USD')).to eq("$1,000.12")
|
||||
end
|
||||
|
||||
it 'should allow for various styles of currency formatting if the version is new enough' do
|
||||
if ICU::Lib.version.to_a.first >= 53
|
||||
curf = NumberFormatting.create('en-US', :currency, style: :iso)
|
||||
curf.format(1_000.12, 'USD').should == "USD1,000.12"
|
||||
expect(curf.format(1_000.12, 'USD')).to eq("USD1,000.12")
|
||||
curf = NumberFormatting.create('en-US', :currency, style: :plural)
|
||||
curf.format(1_000.12, 'USD').should == "1,000.12 US dollars"
|
||||
expect(curf.format(1_000.12, 'USD')).to eq("1,000.12 US dollars")
|
||||
expect { NumberFormatting.create('en-US', :currency, style: :fake) }.to raise_error(StandardError)
|
||||
else
|
||||
curf = NumberFormatting.create('en-US', :currency, style: :default)
|
||||
curf.format(1_000.12, 'USD').should == '$1,000.12'
|
||||
expect(curf.format(1_000.12, 'USD')).to eq('$1,000.12')
|
||||
expect { NumberFormatting.create('en-US', :currency, style: :iso) }.to raise_error(StandardError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
--color
|
|
@ -1,7 +1,5 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
describe TimeFormatting do
|
||||
describe 'the TimeFormatting ' do
|
||||
|
@ -17,21 +15,21 @@ module ICU
|
|||
|
||||
f1 = TimeFormatting.create(:locale => 'cs_CZ', :zone => 'Europe/Prague', :date => :long , :time => :long, :tz_style => :localized_long)
|
||||
it 'check date_format for lang=cs_CZ' do
|
||||
f1.date_format(true).should eql "d. MMMM y H:mm:ss ZZZZ"
|
||||
f1.date_format(false).should eql "d. MMMM y H:mm:ss ZZZZ"
|
||||
expect(f1.date_format(true)).to eq("d. MMMM y H:mm:ss ZZZZ")
|
||||
expect(f1.date_format(false)).to eq("d. MMMM y H:mm:ss ZZZZ")
|
||||
end
|
||||
|
||||
it "for lang=cs_CZ zone=Europe/Prague" do
|
||||
f1.should be_an_instance_of TimeFormatting::DateTimeFormatter
|
||||
f1.format(t0).should eql "12. listopadu 2008 15:21:16 GMT+01:00"
|
||||
f1.format(t1).should eql "25. října 2008 1:15:17 GMT+02:00"
|
||||
f1.format(t2).should eql "25. října 2008 2:16:18 GMT+02:00"
|
||||
f1.format(t3).should eql "25. října 2008 3:17:19 GMT+02:00"
|
||||
f1.format(t4).should eql "25. října 2008 4:18:20 GMT+02:00"
|
||||
f1.format(t5).should eql "29. března 2008 1:35:21 GMT+01:00"
|
||||
f1.format(t6).should eql "29. března 2008 2:36:22 GMT+01:00"
|
||||
f1.format(t7).should eql "29. března 2008 3:37:23 GMT+01:00"
|
||||
f1.format(t8).should eql "29. března 2008 4:38:24 GMT+01:00"
|
||||
expect(f1).to be_an_instance_of TimeFormatting::DateTimeFormatter
|
||||
expect(f1.format(t0)).to eq("12. listopadu 2008 15:21:16 GMT+01:00")
|
||||
expect(f1.format(t1)).to eq("25. října 2008 1:15:17 GMT+02:00")
|
||||
expect(f1.format(t2)).to eq("25. října 2008 2:16:18 GMT+02:00")
|
||||
expect(f1.format(t3)).to eq("25. října 2008 3:17:19 GMT+02:00")
|
||||
expect(f1.format(t4)).to eq("25. října 2008 4:18:20 GMT+02:00")
|
||||
expect(f1.format(t5)).to eq("29. března 2008 1:35:21 GMT+01:00")
|
||||
expect(f1.format(t6)).to eq("29. března 2008 2:36:22 GMT+01:00")
|
||||
expect(f1.format(t7)).to eq("29. března 2008 3:37:23 GMT+01:00")
|
||||
expect(f1.format(t8)).to eq("29. března 2008 4:38:24 GMT+01:00")
|
||||
end
|
||||
|
||||
f2 = TimeFormatting.create(:locale => 'en_US', :zone => 'Europe/Moscow', :date => :short , :time => :long, :tz_style => :generic_location)
|
||||
|
@ -45,20 +43,20 @@ module ICU
|
|||
|
||||
en_exp = "M/d/yy#{en_sep} h:mm:ss a VVVV"
|
||||
it 'check date_format for lang=en_US' do
|
||||
f2.date_format(true).should eql en_exp
|
||||
f2.date_format(false).should eql en_exp
|
||||
expect(f2.date_format(true)).to eq(en_exp)
|
||||
expect(f2.date_format(false)).to eq(en_exp)
|
||||
end
|
||||
|
||||
it "lang=en_US zone=Europe/Moscow" do
|
||||
f2.format(t0).should eql "11/12/08#{en_sep} 5:21:16 PM #{en_tz}"
|
||||
f2.format(t1).should eql "10/25/08#{en_sep} 3:15:17 AM #{en_tz}"
|
||||
f2.format(t2).should eql "10/25/08#{en_sep} 4:16:18 AM #{en_tz}"
|
||||
f2.format(t3).should eql "10/25/08#{en_sep} 5:17:19 AM #{en_tz}"
|
||||
f2.format(t4).should eql "10/25/08#{en_sep} 6:18:20 AM #{en_tz}"
|
||||
f2.format(t5).should eql "3/29/08#{en_sep} 3:35:21 AM #{en_tz}"
|
||||
f2.format(t6).should eql "3/29/08#{en_sep} 4:36:22 AM #{en_tz}"
|
||||
f2.format(t7).should eql "3/29/08#{en_sep} 5:37:23 AM #{en_tz}"
|
||||
f2.format(t8).should eql "3/29/08#{en_sep} 6:38:24 AM #{en_tz}"
|
||||
expect(f2.format(t0)).to eq("11/12/08#{en_sep} 5:21:16 PM #{en_tz}")
|
||||
expect(f2.format(t1)).to eq("10/25/08#{en_sep} 3:15:17 AM #{en_tz}")
|
||||
expect(f2.format(t2)).to eq("10/25/08#{en_sep} 4:16:18 AM #{en_tz}")
|
||||
expect(f2.format(t3)).to eq("10/25/08#{en_sep} 5:17:19 AM #{en_tz}")
|
||||
expect(f2.format(t4)).to eq("10/25/08#{en_sep} 6:18:20 AM #{en_tz}")
|
||||
expect(f2.format(t5)).to eq("3/29/08#{en_sep} 3:35:21 AM #{en_tz}")
|
||||
expect(f2.format(t6)).to eq("3/29/08#{en_sep} 4:36:22 AM #{en_tz}")
|
||||
expect(f2.format(t7)).to eq("3/29/08#{en_sep} 5:37:23 AM #{en_tz}")
|
||||
expect(f2.format(t8)).to eq("3/29/08#{en_sep} 6:38:24 AM #{en_tz}")
|
||||
end
|
||||
|
||||
f3 = TimeFormatting.create(:locale => 'de_DE', :zone => 'Africa/Dakar ', :date => :short , :time => :long)
|
||||
|
@ -69,22 +67,21 @@ module ICU
|
|||
|
||||
ge_exp = "dd.MM.yy#{ge_sep} HH:mm:ss z"
|
||||
it 'check date_format for lang=de_DE' do
|
||||
f3.date_format(true).should eql ge_exp
|
||||
f3.date_format(false).should eql ge_exp
|
||||
expect(f3.date_format(true)).to eq(ge_exp)
|
||||
expect(f3.date_format(false)).to eq(ge_exp)
|
||||
end
|
||||
|
||||
it "lang=de_DE zone=Africa/Dakar" do
|
||||
f3.format(t0).should eql "12.11.08#{ge_sep} 14:21:16 GMT"
|
||||
f3.format(t1).should eql "24.10.08#{ge_sep} 23:15:17 GMT"
|
||||
f3.format(t2).should eql "25.10.08#{ge_sep} 00:16:18 GMT"
|
||||
f3.format(t3).should eql "25.10.08#{ge_sep} 01:17:19 GMT"
|
||||
f3.format(t4).should eql "25.10.08#{ge_sep} 02:18:20 GMT"
|
||||
f3.format(t5).should eql "29.03.08#{ge_sep} 00:35:21 GMT"
|
||||
f3.format(t6).should eql "29.03.08#{ge_sep} 01:36:22 GMT"
|
||||
f3.format(t7).should eql "29.03.08#{ge_sep} 02:37:23 GMT"
|
||||
f3.format(t8).should eql "29.03.08#{ge_sep} 03:38:24 GMT"
|
||||
expect(f3.format(t0)).to eq("12.11.08#{ge_sep} 14:21:16 GMT")
|
||||
expect(f3.format(t1)).to eq("24.10.08#{ge_sep} 23:15:17 GMT")
|
||||
expect(f3.format(t2)).to eq("25.10.08#{ge_sep} 00:16:18 GMT")
|
||||
expect(f3.format(t3)).to eq("25.10.08#{ge_sep} 01:17:19 GMT")
|
||||
expect(f3.format(t4)).to eq("25.10.08#{ge_sep} 02:18:20 GMT")
|
||||
expect(f3.format(t5)).to eq("29.03.08#{ge_sep} 00:35:21 GMT")
|
||||
expect(f3.format(t6)).to eq("29.03.08#{ge_sep} 01:36:22 GMT")
|
||||
expect(f3.format(t7)).to eq("29.03.08#{ge_sep} 02:37:23 GMT")
|
||||
expect(f3.format(t8)).to eq("29.03.08#{ge_sep} 03:38:24 GMT")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
module ICU
|
||||
describe Transliteration::Transliterator do
|
||||
def transliterator_for(*args)
|
||||
|
@ -16,7 +14,7 @@ module ICU
|
|||
].each do |id, input, output|
|
||||
it "should transliterate #{id}" do
|
||||
tl = transliterator_for(id)
|
||||
tl.transliterate(input).should == output
|
||||
expect(tl.transliterate(input)).to eq(output)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -25,12 +23,13 @@ module ICU
|
|||
describe Transliteration do
|
||||
it "should provide a list of available ids" do
|
||||
ids = ICU::Transliteration.available_ids
|
||||
ids.should be_kind_of(Array)
|
||||
ids.should_not be_empty
|
||||
|
||||
expect(ids).to be_an(Array)
|
||||
expect(ids).to_not be_empty
|
||||
end
|
||||
|
||||
it "should transliterate custom rules" do
|
||||
ICU::Transliteration.translit("NFD; [:Nonspacing Mark:] Remove; NFC", "âêîôû").should == "aeiou"
|
||||
expect(ICU::Transliteration.translit("NFD; [:Nonspacing Mark:] Remove; NFC", "âêîôû")).to eq("aeiou")
|
||||
end
|
||||
|
||||
end # Transliteration
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
module ICU
|
||||
describe UCharPointer do
|
||||
it 'allocates enough memory for 16-bit characters' do
|
||||
UCharPointer.new(5).size.should == 10
|
||||
expect(UCharPointer.new(5).size).to eq(10)
|
||||
end
|
||||
|
||||
it 'builds a buffer from a string' do
|
||||
ptr = UCharPointer.from_string('abc')
|
||||
ptr.should be_a UCharPointer
|
||||
ptr.size.should == 6
|
||||
ptr.read_array_of_uint16(3).should == [0x61, 0x62, 0x63]
|
||||
expect(ptr).to be_a UCharPointer
|
||||
expect(ptr.size).to eq(6)
|
||||
expect(ptr.read_array_of_uint16(3)).to eq([0x61, 0x62, 0x63])
|
||||
end
|
||||
|
||||
it 'takes an optional capacity' do
|
||||
ptr = UCharPointer.from_string('abc', 5)
|
||||
ptr.size.should == 10
|
||||
expect(ptr.size).to eq(10)
|
||||
end
|
||||
|
||||
describe 'converting to string' do
|
||||
let(:ptr) { UCharPointer.new(3).write_array_of_uint16 [0x78, 0x0, 0x79] }
|
||||
|
||||
it 'returns the the entire buffer by default' do
|
||||
ptr.string.should == "x\0y"
|
||||
expect(ptr.string).to eq("x\0y")
|
||||
end
|
||||
|
||||
it 'returns strings of the specified length' do
|
||||
ptr.string(0).should == ""
|
||||
ptr.string(2).should == "x\0"
|
||||
expect(ptr.string(0)).to eq("")
|
||||
expect(ptr.string(2)).to eq("x\0")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue