Sha256: d209910101c40073e3a0205b483e742747a3c0b9f63db67f6e9dc12daa88a501

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

require_relative "../lib/unicode/types"
require "minitest/autorun"

describe Unicode::Types do
  describe ".types (alias .of)" do
    it "will always return an Array" do
      assert_equal [], Unicode::Types.of("")
    end 

    it "will return all types that characters in the string belong to" do
      assert_equal ["Control", "Graphic"], Unicode::Types.of("A\tb")
    end 

    it "will return all types sorted order" do
      assert_equal ["Control", "Graphic"], Unicode::Types.of("A\t")
      assert_equal ["Control", "Graphic"], Unicode::Types.of("\tA")
    end 

    it "will call .type for every character" do
      mocked_method = MiniTest::Mock.new
      mocked_method.expect :call, "first type",  ["A"]
      mocked_method.expect :call, "second type", ["2"]
      Unicode::Types.stub :type, mocked_method do
        Unicode::Types.of("A2")
      end 
      mocked_method.verify
    end 
  end

  describe ".type" do
    it "will return type for that character" do
      assert_equal "Format", Unicode::Types.type("­")
    end

    it "will return Noncharacter for codepoints defined as noncharacter" do
      assert_equal "Noncharacter", Unicode::Types.type("\u{10ffff}")
    end

    it "will return Reserved for unassigned codepoints" do
      assert_equal "Reserved", Unicode::Types.type("\u{10c50}")
      assert_equal "Reserved", Unicode::Types.type("\u{c03a6}")
    end
  end

  describe ".names" do
    it "will return a list of all types" do
      assert_equal %w[ 
        Graphic
        Format
        Control
        Private-use
        Surrogate
        Noncharacter
        Reserved
      ], Unicode::Types.names
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unicode-types-1.1.1 spec/unicode_types_spec.rb
unicode-types-1.1.0 spec/unicode_types_spec.rb
unicode-types-1.0.1 spec/unicode_types_spec.rb