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
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/shared/numbering_system_spec.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.5 spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.4 spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.3 spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.2 spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.1 spec/shared/numbering_system_spec.rb
twitter_cldr-4.4.0 spec/shared/numbering_system_spec.rb
twitter_cldr-4.3.1 spec/shared/numbering_system_spec.rb
twitter_cldr-4.3.0 spec/shared/numbering_system_spec.rb
twitter_cldr-4.2.0 spec/shared/numbering_system_spec.rb
twitter_cldr-4.1.0 spec/shared/numbering_system_spec.rb
twitter_cldr-4.0.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.6.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.5.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.4.0 spec/shared/numbering_system_spec.rb
twitter_cldr-3.3.0 spec/shared/numbering_system_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/spec/shared/numbering_system_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/spec/shared/numbering_system_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/spec/shared/numbering_system_spec.rb