Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
movermeyer committed Aug 17, 2022
1 parent 17b57bc commit 91a58e0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 63 deletions.
22 changes: 11 additions & 11 deletions lib/cldr/export/data/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(locale)
private

def number_systems
number_systems = select("/descendant::*[attribute::numberSystem]").map { |node| node["numberSystem"] }.uniq
number_systems = select("/descendant::*[attribute::numberSystem]").map { |node| node["numberSystem"] }.uniq.map(&:to_sym)
number_systems.to_h do |number_system|
children = {
symbols: symbols(number_system),
Expand Down Expand Up @@ -61,7 +61,7 @@ def format(number_system, type)
end

result = select("numbers/#{type}Formats[@numberSystem=\"#{number_system}\"]/#{type}FormatLength").each_with_object({}) do |format_length_node, format_result|
format_length_key = format_length_node["type"] || default_format_length_type
format_length_key = format_length_node["type"]&.to_sym || default_format_length_type

aliased = select_single(format_length_node, "alias")
if aliased
Expand All @@ -82,10 +82,10 @@ def format(number_system, type)
def parse_default_currency_format_length_node(number_system, format_length_node, type)
result = {}
select(format_length_node, "#{type}Format").each do |format_node|
format_key = format_node["type"] || default_format_type
format_key = format_node["type"]&.to_sym || default_format_type

if (aliased = select_single(format_node, "alias"))
format_length_key = format_length_node["type"] || default_format_length_type
format_length_key = format_length_node["type"]&.to_sym || default_format_length_type
result[format_key] = xpath_to_default_currency_format_length_node_alias(aliased["path"], number_system, format_length_key)
else
pattern_nodes = select_single(format_node, "pattern")
Expand All @@ -98,11 +98,11 @@ def parse_default_currency_format_length_node(number_system, format_length_node,
def parse_currency_format_length_node(format_length_node, type)
result = {}
select(format_length_node, "#{type}Format").each do |format_node|
format_key = format_node["type"] || default_format_type
format_key = format_node["type"]&.to_sym || default_format_type

result[format_key] ||= select(format_node, "pattern").each_with_object({}) do |pattern_node, pattern_result|
pattern_key = pattern_node["type"] || default_pattern_type # TODO: In currencies, it is only used for compact number formatting??
pattern_count = pattern_node["count"]
pattern_key = pattern_node["type"]&.to_sym || default_pattern_type
pattern_count = pattern_node["count"]&.to_sym

if pattern_count
if pattern_result[pattern_key].nil?
Expand All @@ -124,7 +124,7 @@ def default_format_length_type
# TODO: It would be better is this were one of the valid values for the type attribute
# <!ATTLIST decimalFormatLength type (full | long | medium | short) #IMPLIED >
# But I haven't been able to figure out what the default is.
@default_format_length_type ||= "default"
@default_format_length_type ||= :default
end

def default_format_type
Expand All @@ -136,15 +136,15 @@ def default_format_type

raise "The default type for #{type}Format has changed. Some code will need to be updated."
end
"standard"
:standard
end
end

def default_pattern_type
@default_pattern_type ||= begin
ldml_dtd_file = File.read("vendor/cldr/common/dtd/ldml.dtd")
ldml_dtd_file.match("<!ATTLIST pattern type NMTOKEN \"([^\"]+)\" >")[1]
end
end.to_sym
end

def xpath_to_default_currency_format_length_node_alias(xpath, number_system, format_length_key)
Expand Down Expand Up @@ -181,7 +181,7 @@ def xpath_to_format_alias(xpath, type)

def unit(number_system)
select("numbers/currencyFormats[@numberSystem=\"#{number_system}\"]/unitPattern").each_with_object({}) do |node, result|
count = node["count"]
count = node["count"].to_sym
result[count] = node.content
end
end
Expand Down
109 changes: 59 additions & 50 deletions test/export/data/numbers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,83 @@ class TestCldrDataNumbers < Test::Unit::TestCase
superscripting_exponent: "·",
time_separator: ":",
}
assert_equal expected, Cldr::Export::Data::Numbers.new(:de)[:numbers][:symbols]
assert_equal expected, Cldr::Export::Data::Numbers.new(:de)[:numbers][:latn][:symbols]
end

test "number formats :de" do
expected = {
currency: {
number_system: "latn",
patterns: {
:default => "#,##0.00 ¤",
"short" => {
"1000" => { "one" => "0", "other" => "0" },
"10000" => { "one" => "0", "other" => "0" },
"100000" => { "one" => "0", "other" => "0" },
"1000000" => { "one" => "0 Mio'.' ¤", "other" => "0 Mio'.' ¤" },
"10000000" => { "one" => "00 Mio'.' ¤", "other" => "00 Mio'.' ¤" },
"100000000" => { "one" => "000 Mio'.' ¤", "other" => "000 Mio'.' ¤" },
"1000000000" => { "one" => "0 Mrd'.' ¤", "other" => "0 Mrd'.' ¤" },
"10000000000" => { "one" => "00 Mrd'.' ¤", "other" => "00 Mrd'.' ¤" },
"100000000000" => { "one" => "000 Mrd'.' ¤", "other" => "000 Mrd'.' ¤" },
"1000000000000" => { "one" => "0 Bio'.' ¤", "other" => "0 Bio'.' ¤" },
"10000000000000" => { "one" => "00 Bio'.' ¤", "other" => "00 Bio'.' ¤" },
"100000000000000" => { "one" => "000 Bio'.' ¤", "other" => "000 Bio'.' ¤" },
default: {
accounting: "#,##0.00 ¤",
standard: "#,##0.00 ¤",
},
short: {
standard: {
"1000": { one: "0", other: "0" },
"10000": { one: "0", other: "0" },
"100000": { one: "0", other: "0" },
"1000000": { one: "0 Mio'.' ¤", other: "0 Mio'.' ¤" },
"10000000": { one: "00 Mio'.' ¤", other: "00 Mio'.' ¤" },
"100000000": { one: "000 Mio'.' ¤", other: "000 Mio'.' ¤" },
"1000000000": { one: "0 Mrd'.' ¤", other: "0 Mrd'.' ¤" },
"10000000000": { one: "00 Mrd'.' ¤", other: "00 Mrd'.' ¤" },
"100000000000": { one: "000 Mrd'.' ¤", other: "000 Mrd'.' ¤" },
"1000000000000": { one: "0 Bio'.' ¤", other: "0 Bio'.' ¤" },
"10000000000000": { one: "00 Bio'.' ¤", other: "00 Bio'.' ¤" },
"100000000000000": { one: "000 Bio'.' ¤", other: "000 Bio'.' ¤" },
},
},
},
unit: { "one" => "{0} {1}", "other" => "{0} {1}" },
unit: { one: "{0} {1}", other: "{0} {1}" },
},
decimal: {
number_system: "latn",
patterns: {
:default => "#,##0.###",
"long" => {
"1000" => { "one" => "0 Tausend", "other" => "0 Tausend" },
"10000" => { "one" => "00 Tausend", "other" => "00 Tausend" },
"100000" => { "one" => "000 Tausend", "other" => "000 Tausend" },
"1000000" => { "one" => "0 Million", "other" => "0 Millionen" },
"10000000" => { "one" => "00 Millionen", "other" => "00 Millionen" },
"100000000" => { "one" => "000 Millionen", "other" => "000 Millionen" },
"1000000000" => { "one" => "0 Milliarde", "other" => "0 Milliarden" },
"10000000000" => { "one" => "00 Milliarden", "other" => "00 Milliarden" },
"100000000000" => { "one" => "000 Milliarden", "other" => "000 Milliarden" },
"1000000000000" => { "one" => "0 Billion", "other" => "0 Billionen" },
"10000000000000" => { "one" => "00 Billionen", "other" => "00 Billionen" },
"100000000000000" => { "one" => "000 Billionen", "other" => "000 Billionen" },
default: {
standard: "#,##0.###",
},
long: {
standard: {
"1000": { one: "0 Tausend", other: "0 Tausend" },
"10000": { one: "00 Tausend", other: "00 Tausend" },
"100000": { one: "000 Tausend", other: "000 Tausend" },
"1000000": { one: "0 Million", other: "0 Millionen" },
"10000000": { one: "00 Millionen", other: "00 Millionen" },
"100000000": { one: "000 Millionen", other: "000 Millionen" },
"1000000000": { one: "0 Milliarde", other: "0 Milliarden" },
"10000000000": { one: "00 Milliarden", other: "00 Milliarden" },
"100000000000": { one: "000 Milliarden", other: "000 Milliarden" },
"1000000000000": { one: "0 Billion", other: "0 Billionen" },
"10000000000000": { one: "00 Billionen", other: "00 Billionen" },
"100000000000000": { one: "000 Billionen", other: "000 Billionen" },
},
},
"short" => {
"1000" => { "one" => "0", "other" => "0" },
"10000" => { "one" => "0", "other" => "0" },
"100000" => { "one" => "0", "other" => "0" },
"1000000" => { "one" => "0 Mio'.'", "other" => "0 Mio'.'" },
"10000000" => { "one" => "00 Mio'.'", "other" => "00 Mio'.'" },
"100000000" => { "one" => "000 Mio'.'", "other" => "000 Mio'.'" },
"1000000000" => { "one" => "0 Mrd'.'", "other" => "0 Mrd'.'" },
"10000000000" => { "one" => "00 Mrd'.'", "other" => "00 Mrd'.'" },
"100000000000" => { "one" => "000 Mrd'.'", "other" => "000 Mrd'.'" },
"1000000000000" => { "one" => "0 Bio'.'", "other" => "0 Bio'.'" },
"10000000000000" => { "one" => "00 Bio'.'", "other" => "00 Bio'.'" },
"100000000000000" => { "one" => "000 Bio'.'", "other" => "000 Bio'.'" },
short: {
standard: {
"1000": { one: "0", other: "0" },
"10000": { one: "0", other: "0" },
"100000": { one: "0", other: "0" },
"1000000": { one: "0 Mio'.'", other: "0 Mio'.'" },
"10000000": { one: "00 Mio'.'", other: "00 Mio'.'" },
"100000000": { one: "000 Mio'.'", other: "000 Mio'.'" },
"1000000000": { one: "0 Mrd'.'", other: "0 Mrd'.'" },
"10000000000": { one: "00 Mrd'.'", other: "00 Mrd'.'" },
"100000000000": { one: "000 Mrd'.'", other: "000 Mrd'.'" },
"1000000000000": { one: "0 Bio'.'", other: "0 Bio'.'" },
"10000000000000": { one: "00 Bio'.'", other: "00 Bio'.'" },
"100000000000000": { one: "000 Bio'.'", other: "000 Bio'.'" },
},
},
},
},
percent: { number_system: "latn", patterns: { default: "#,##0 %" } },
scientific: { number_system: "latn", patterns: { default: "#E0" } },
percent: { patterns: { default: { standard: "#,##0 %" } } },
scientific: { patterns: { default: { standard: "#E0" } } },
}
assert_equal expected, Cldr::Export::Data::Numbers.new(:de)[:numbers][:formats]
assert_equal expected, Cldr::Export::Data::Numbers.new(:de)[:numbers][:latn][:formats]
end

test "redirects in root locale" do
assert_equal :"numbers.formats.decimal.patterns.short",
Cldr::Export::Data::Numbers.new(:root)[:numbers][:formats][:decimal][:patterns]["long"]
assert_equal :"numbers.latn.formats.decimal.patterns.short",
Cldr::Export::Data::Numbers.new(:root)[:numbers][:latn][:formats][:decimal][:patterns][:long]
end
end
4 changes: 2 additions & 2 deletions test/export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def tmp_dir

test "passing the merge option generates and merge data for all fallback locales" do
data = Cldr::Export.data(:Numbers, :"de-AT")
assert !data[:numbers][:formats][:nan]
assert !data[:numbers][:latn][:formats][:nan]

data = Cldr::Export.data(:Numbers, :"de-AT", merge: true)
assert_equal "NaN", data[:numbers][:symbols][:nan]
assert_equal "NaN", data[:numbers][:latn][:symbols][:nan]
end

test "passing the merge option generates and merges Plurals data from fallback locales" do
Expand Down

0 comments on commit 91a58e0

Please sign in to comment.