Sha256: ab7f6152c62f0befb5ddeeab8fceef24da7bab6e70a84c768c10cbc2d58d4ea6

Contents?: true

Size: 1.32 KB

Versions: 34

Compression:

Stored size: 1.32 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

include TwitterCldr::Shared

describe NumberingSystem do
  describe "#for_name" do
    it "should return the correct numbering system for the given name" do
      expect(NumberingSystem.for_name("latn").digits).to eq(%w(0 1 2 3 4 5 6 7 8 9))
      expect(NumberingSystem.for_name("arab").digits).to eq(%w(٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩))
    end

    it "should raise an error if the system is not numeric" do
      expect { NumberingSystem.for_name("roman") }.to raise_error(UnsupportedNumberingSystemError)
    end
  end

  describe "#transliterate" do
    context "with the arabic numbering system" do
      let(:system) { NumberingSystem.for_name("arab") }

      it "replaces ascii numeral characters with arabic ones" do
        expect(system.transliterate(123)).to match_normalized("١٢٣")
        expect(system.transliterate(947)).to match_normalized("٩٤٧")
      end
    end

    context "with the Han decimal system" do
      let(:system) { NumberingSystem.for_name("hanidec") }

      it "replaces ascii numeral characters with Han ones" do
        expect(system.transliterate(123)).to match_normalized("一二三")
        expect(system.transliterate(947)).to match_normalized("九四七")
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
twitter_cldr-3.2.1 spec/shared/numbering_system_spec.rb
twitter_cldr-3.2.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.1.2 spec/shared/numbering_system_spec.rb
twitter_cldr-3.1.1 spec/shared/numbering_system_spec.rb
twitter_cldr-3.1.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.10 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.9 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.8 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.7 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.6 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.5 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.4 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.3 spec/shared/numbering_system_spec.rb
twitter_cldr-3.0.2 spec/shared/numbering_system_spec.rb