Sha256: ad8e0dbed9a5ddbeb8e780dbd5b072500e822a1e9fa8e551baecd8b9e1da5feb

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

include TwitterCldr::Formatters

describe DecimalFormatter do
  let(:data_reader) { TwitterCldr::DataReaders::NumberDataReader.new(:nl, :type => :decimal) }
  let(:formatter) { data_reader.formatter }
  let(:tokenizer) { data_reader.tokenizer }
  let(:negative_number) { -12 }
  let(:number) { 12 }

  describe "#format" do
    it "should format positive decimals correctly" do
      pattern = data_reader.pattern(number)
      tokens = tokenizer.tokenize(pattern)
      expect(formatter.format(tokens, number)).to eq("12")
    end

    it "should format negative decimals correctly" do
      pattern = data_reader.pattern(negative_number)
      tokens = tokenizer.tokenize(pattern)
      expect(formatter.format(tokens, negative_number)).to eq("-12")
    end

    it "should respect the :precision option" do
      { number => "12,000", negative_number => "-12,000" }.each_pair do |num, formatted|
        pattern = data_reader.pattern(num)
        tokens = tokenizer.tokenize(pattern)
        expect(formatter.format(tokens, num, :precision => 3)).to eq(formatted)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/spec/formatters/numbers/decimal_formatter_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/spec/formatters/numbers/decimal_formatter_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.2.1 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.2.0 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.1.2 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.1.1 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.1.0 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.10 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.9 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.8 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.7 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.6 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.5 spec/formatters/numbers/decimal_formatter_spec.rb
twitter_cldr-3.0.4 spec/formatters/numbers/decimal_formatter_spec.rb