Sha256: c30034ddcf3c541ea4130fb81fb7a5f57f57aa2628df6221687abc8c4e626360

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

# encoding: UTF-8

module ICU
  module Collation
    describe "Collation" do
      it "should collate an array of strings" do
        expect(Collation.collate("nb", %w[æ å ø])).to eq(%w[æ ø å])
      end
    end

    describe Collator do
      let(:collator) { Collator.new("nb") }

      it "should collate an array of strings" do
        expect(collator.collate(%w[å ø æ])).to eq(%w[æ ø å])
      end

      it "raises an error if argument does not respond to :sort" do
        expect { collator.collate(1) }.to raise_error(ArgumentError)
      end

      it "should return available locales" do
        locales = ICU::Collation.available_locales
        expect(locales).to be_an(Array)
        expect(locales).to_not be_empty
        expect(locales).to include("nb")
      end

      it "should return the locale of the collator" do
        expect(collator.locale).to eq('nb')
      end

      it "should compare two strings" do
        expect(collator.compare("blåbærsyltetøy", "blah")).to eq(1)
        expect(collator.compare("blah", "blah")).to eq(0)
        expect(collator.compare("ba", "bl")).to eq(-1)
      end

      it "should know if a string is greater than another" do
        expect(collator).to be_greater("z", "a")
        expect(collator).to_not be_greater("a", "z")
      end

      it "should know if a string is greater or equal to another" do
        expect(collator).to be_greater_or_equal("z", "a")
        expect(collator).to be_greater_or_equal("z", "z")
        expect(collator).to_not be_greater_or_equal("a", "z")
      end

      it "should know if a string is equal to another" do
        expect(collator).to be_equal("a", "a")
        expect(collator).to_not be_equal("a", "b")
      end

      it "should return rules" do
        expect(collator.rules).to_not be_empty
        # ö sorts before Ö
        expect(collator.rules).to include('ö<<<Ö')
      end

    end
  end # Collate
end # ICU

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ffi-icu-0.4.3 spec/collation_spec.rb
ffi-icu-0.4.2 spec/collation_spec.rb
ffi-icu-0.4.1 spec/collation_spec.rb
ffi-icu-0.4.0 spec/collation_spec.rb
ffi-icu-0.3.0 spec/collation_spec.rb