Sha256: 2e85a249a2f5b12f82db58b258df0fc9a4b10256d3b9d8a2001bd4ff906502be

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

include TwitterCldr::Formatters

describe PercentFormatter do
  let(:data_reader) { TwitterCldr::DataReaders::NumberDataReader.new(:da, type: :percent) }
  let(:formatter) { data_reader.formatter }
  let(:tokenizer) { data_reader.tokenizer }
  let(:negative_number) { -12 }
  let(:number) { 12 }

  it "should format the number correctly" do
    pattern = data_reader.pattern(number)
    tokens = tokenizer.tokenize(pattern)
    expect(formatter.format(tokens, number)).to eq("12 %")
  end

  it "should format negative numbers 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
    pattern = data_reader.pattern(negative_number)
    tokens = tokenizer.tokenize(pattern)
    expect(formatter.format(tokens, negative_number, precision: 3)).to match_normalized("-12,000 %")
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/formatters/numbers/percent_formatter_spec.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.5 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.4 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.3 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.2 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.1 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.4.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.3.1 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.3.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.2.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.1.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-4.0.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-3.6.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-3.5.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-3.4.0 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-3.3.0 spec/formatters/numbers/percent_formatter_spec.rb