Sha256: e0a99316e09796f2cd90ebc58d897343f4b5fbfbdd1e27273193427bdd97d8dc

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 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) { 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)
    formatter.format(tokens, number).should == "12 %"
  end

  it "should format negative numbers correctly" do
    pattern = data_reader.pattern(negative_number)
    tokens = tokenizer.tokenize(pattern)
    formatter.format(tokens, negative_number).should == "-12 %"
  end

  it "should respect the :precision option" do
    pattern = data_reader.pattern(negative_number)
    tokens = tokenizer.tokenize(pattern)
    formatter.format(tokens, negative_number, :precision => 3).should match_normalized("-12,000 %")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twitter_cldr-3.0.1 spec/formatters/numbers/percent_formatter_spec.rb
twitter_cldr-3.0.0 spec/formatters/numbers/percent_formatter_spec.rb