Sha256: 6ae3ced605a4f5b28a2c3cdd8ebea48e15fa5284b9fceaf0fb98c15dd31ec08e

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

include TwitterCldr::Formatters

describe CurrencyFormatter do
  describe "#format" do
    before(:each) do
      @formatter = CurrencyFormatter.new(:locale => :msa)
    end

    it "should use a dollar sign when no other currency symbol is given (and default to a precision of 2)" do
      @formatter.format(12).should == "$12.00"
    end

    it "handles negative numbers" do
      # yes, the parentheses really are part of the format, don't worry about it
      @formatter.format(-12).should == "-($12.00)"
    end

    it "should use the specified currency symbol when specified" do
      # S/. is the symbol for the Peruvian Nuevo Sol, just in case you were curious
      @formatter.format(12, :currency => "S/.").should == "S/.12.00"
    end

    it "should use the currency symbol for the corresponding currency code" do
      @formatter.format(12, :currency => "PEN").should == "S/.12.00"
    end

    it "overrides the default precision" do
      @formatter.format(12, :precision => 3).should == "$12.000"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter_cldr-1.9.1 spec/formatters/numbers/currency_formatter_spec.rb
twitter_cldr-1.9.0 spec/formatters/numbers/currency_formatter_spec.rb
twitter_cldr-1.8.1 spec/formatters/numbers/currency_formatter_spec.rb
twitter_cldr-1.8.0 spec/formatters/numbers/currency_formatter_spec.rb
twitter_cldr-1.7.0 spec/formatters/numbers/currency_formatter_spec.rb