Skip to content

Commit

Permalink
Select the code to load at compile-time depending on the ICU lib's ve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
olbat committed May 7, 2017
1 parent f851522 commit 80b571b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/currencies_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe "ICU::Currencies" do
end
end

{% if compare_versions(LibICU::VERSION, "49.0.0") >= 0 %}
describe "numeric_code" do
it "returns the code associated to a currency" do
ICU::Currencies.numeric_code("EUR").should eq(978)
Expand All @@ -24,4 +25,5 @@ describe "ICU::Currencies" do
end
end
end
{% end %}
end
2 changes: 2 additions & 0 deletions spec/region_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "./spec_helper"

{% if compare_versions(LibICU::VERSION, "52.0.0") >= 0 %}
describe "ICU::Region" do
describe "initialize" do
it "creates a new region from a code" do
Expand Down Expand Up @@ -57,3 +58,4 @@ describe "ICU::Region" do
end
end
end
{% end %}
2 changes: 2 additions & 0 deletions src/icu/currencies.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class ICU::Currencies
ICU.uchars_to_string(buff, len)
end

{% if compare_versions(LibICU::VERSION, "49.0.0") >= 0 %}
def self.numeric_code(currency : String) : Int32
num = LibICU.ucurr_get_numeric_code(ICU.string_to_uchars(currency))
raise ICU::Error.new(%(Unknown currency "#{currency}")) if num == 0
num
end
{% end %}
end
2 changes: 2 additions & 0 deletions src/icu/region.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% if compare_versions(LibICU::VERSION, "52.0.0") >= 0 %}
class ICU::Region
@uregion : LibICU::URegion
@code : String?
Expand Down Expand Up @@ -47,3 +48,4 @@ class ICU::Region
regions.map { |r| self.class.new(r) }
end
end
{% end %}

0 comments on commit 80b571b

Please sign in to comment.