Sha256: 450434ff707b56336713c78b5b6c0e828b53019eabeb4179b5ee435d9914125e

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'

include TwitterCldr::DataReaders

describe NumberDataReader do
  let(:data_reader) { NumberDataReader.new(:en) }

  describe "#get_key_for" do
    it "builds a power-of-ten key based on the number of digits in the input" do
      (3..15).each do |i|
        value = data_reader.send(:get_key_for, "1337#{"0" * (i - 3)}")
        expect(value).to eq((10 ** i).to_s.to_sym)
      end
    end
  end

  describe '#format_number' do
    it 'works with options' do
      expect(data_reader.format_number(1000, precision: 2)).to eq('1,000.00')
    end

    it "works when options aren't specified" do
      expect(data_reader.format_number(1000)).to eq('1,000')
    end
  end

  describe "#pattern" do
    let(:symbols) { { nan: 'NaN', minus_sign: '<->' } } # unique locale-specific minus sign

    before(:each) do
      allow(TwitterCldr).to receive(:get_locale_resource).with(:en, :numbers) {
        {
          en: {
            numbers: {
              formats: { decimal: { patterns: { default: "#,##0.###" } } },
              symbols: symbols
            }
          }
        }
      }
    end

    it "returns pattern for a number" do
      expect(data_reader.pattern(2)).to eq("#,##0.###")
    end

    it "returns pattern for a negative number" do
      expect(data_reader.pattern(-2)).to eq("<->#,##0.###")
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/data_readers/number_data_reader_spec.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.5 spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.4 spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.3 spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.2 spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.1 spec/data_readers/number_data_reader_spec.rb
twitter_cldr-4.4.0 spec/data_readers/number_data_reader_spec.rb