Sha256: 9915541b424808814d92eac0b180bbd34f9350b5f80d955f7777adf136954c76
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 require 'spec_helper' include TwitterCldr::Formatters describe ShortDecimalFormatter do let(:data_reader) do TwitterCldr::DataReaders::NumberDataReader.new(:en, :type => :short_decimal) end let(:formatter) { data_reader.formatter } let(:tokenizer) { data_reader.tokenizer } it "formats valid numbers correctly (from 10^3 - 10^15)" do expected = { 10 ** 3 => "1K", 10 ** 4 => "10K", 10 ** 5 => "100K", 10 ** 6 => "1M", 10 ** 7 => "10M", 10 ** 8 => "100M", 10 ** 9 => "1B", 10 ** 10 => "10B", 10 ** 11 => "100B", 10 ** 12 => "1T", 10 ** 13 => "10T", 10 ** 14 => "100T" } expected.each do |num, text| pattern = data_reader.pattern(num) expect(formatter.format(tokenizer.tokenize(pattern), num)).to eq(text) end end it "formats the number as if it were a straight decimal if it exceeds 10^15" do number = 10**15 pattern = data_reader.pattern(number) expect(formatter.format(tokenizer.tokenize(pattern), number)).to eq("1,000,000,000,000,000") end it "formats the number as if it were a straight decimal if it's less than 1000" do number = 500 pattern = data_reader.pattern(number) expect(formatter.format(tokenizer.tokenize(pattern), number)).to eq("500") end it "respects the :precision option" do number = 12345 pattern = data_reader.pattern(number) expect(formatter.format(tokenizer.tokenize(pattern), number, :precision => 3)).to match_normalized("12.345K") end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
twitter_cldr-3.0.3 | spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb |
twitter_cldr-3.0.2 | spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb |