From 8be8aebbbad4f578f27ade3c377a77ecd82401dc Mon Sep 17 00:00:00 2001 From: Jacob Burroughs Date: Wed, 2 Dec 2020 11:28:25 -0600 Subject: [PATCH] Support macos big sur Also makes tests pass against newer icu and ruby fixes #44 --- .travis.yml | 4 ---- lib/ffi-icu/lib.rb | 7 ++++++- spec/locale_spec.rb | 7 ++++++- spec/number_formatting_spec.rb | 9 +++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index eba7470..e7eef9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,3 @@ rvm: before_script: - sudo apt-get install -y libicu-dev -jobs: - allow_failures: - - rvm: 2.7 - - rvm: ruby-head diff --git a/lib/ffi-icu/lib.rb b/lib/ffi-icu/lib.rb index edfa896..c83261d 100644 --- a/lib/ffi-icu/lib.rb +++ b/lib/ffi-icu/lib.rb @@ -39,7 +39,12 @@ module ICU [find_lib("libicui18n.#{FFI::Platform::LIBSUFFIX}.??"), find_lib("libicutu.#{FFI::Platform::LIBSUFFIX}.??")] when :osx - [find_lib("libicucore.#{FFI::Platform::LIBSUFFIX}")] + # See https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes (62986286) + if Gem::Version.new(`sw_vers -productVersion`) >= Gem::Version.new('11') + ["libicucore.#{FFI::Platform::LIBSUFFIX}"] + else + [find_lib("libicucore.#{FFI::Platform::LIBSUFFIX}")] + end when :linux [find_lib("libicui18n.#{FFI::Platform::LIBSUFFIX}.??"), find_lib("libicutu.#{FFI::Platform::LIBSUFFIX}.??")] diff --git a/spec/locale_spec.rb b/spec/locale_spec.rb index 4e744b5..ad44603 100644 --- a/spec/locale_spec.rb +++ b/spec/locale_spec.rb @@ -77,7 +77,12 @@ module ICU if Gem::Version.new('4.4') <= Gem::Version.new(Lib.version) 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') + # Support for this "magic" transform was dropped with https://unicode-org.atlassian.net/browse/ICU-20187, so don't test it + if Gem::Version.new(Lib.version) < Gem::Version.new('64') + expect(Locale.new('zh_Hans_CH_PINYIN').to_language_tag).to eq('zh-Hans-CH-u-co-pinyin') + else + expect(Locale.new('zh_Hans_CH@collation=pinyin').to_language_tag).to eq('zh-Hans-CH-u-co-pinyin') + end else expect(Locale.new('en_US').to_language_tag).to eq('en-us') expect(Locale.new('zh_TW').to_language_tag).to eq('zh-tw') diff --git a/spec/number_formatting_spec.rb b/spec/number_formatting_spec.rb index 7bbaada..27e759c 100644 --- a/spec/number_formatting_spec.rb +++ b/spec/number_formatting_spec.rb @@ -20,7 +20,7 @@ module ICU end it 'should format a decimal' do - expect(NumberFormatting.format_number("en", BigDecimal.new("10000.123"))).to eq("10,000.123") + expect(NumberFormatting.format_number("en", BigDecimal("10000.123"))).to eq("10,000.123") end it 'should format a currency' do @@ -54,7 +54,12 @@ module ICU 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) - expect(curf.format(1_000.12, 'USD')).to eq("USD1,000.12") + expected = if ICU::Lib.version.to_a.first >= 62 + "USD\u00A01,000.12" + else + "USD1,000.12" + end + expect(curf.format(1_000.12, 'USD')).to eq(expected) curf = NumberFormatting.create('en-US', :currency, style: :plural) 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)