Sha256: ab7ccaa564ce181c0dc4a0512c4c63c05e81191a1c18a0fd1bc1eadff76f4b69

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

# encoding: UTF-8

require 'spec_helper'

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

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

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

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

      it "should return available locales" do
        locales = ICU::Collation.available_locales
        locales.should be_kind_of(Array)
        locales.should_not be_empty
        locales.should include("nb")
      end

      it "should return the locale of the collator" do
        l = collator.locale
        l.should == "nb"
      end

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

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

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

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

      it "should return rules" do
        collator.rules.should_not be_empty
        # ö sorts before Ö
        collator.rules.include?('ö<<<Ö').should be_true
      end

    end
  end # Collate
end # ICU

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffi-icu-0.2.0 spec/collation_spec.rb
ffi-icu-0.1.10 spec/collation_spec.rb
ffi-icu-0.1.9 spec/collation_spec.rb
ffi-icu-0.1.8 spec/collation_spec.rb
ffi-icu-0.1.7 spec/collation_spec.rb
ffi-icu-0.1.6 spec/collation_spec.rb
ffi-icu-0.1.5 spec/collation_spec.rb
ffi-icu-0.1.4 spec/collation_spec.rb
ffi-icu-0.1.3 spec/collation_spec.rb