Sha256: 1f0e75748dc36197773c83065473c0d0329b037b08131d417229d33f25e76245

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require "test_helper"

describe "Charset" do

  describe "is_gsm method" do

    it "should return true if all characters are in GSM 03.38 charset" do
      assert_equal true, TextMagic::API.is_gsm(("a".."z").to_a.join)
      assert_equal true, TextMagic::API.is_gsm(("A".."Z").to_a.join)
      assert_equal true, TextMagic::API.is_gsm(("0".."9").to_a.join)
      assert_equal true, TextMagic::API.is_gsm("@£$¥€")
      assert_equal true, TextMagic::API.is_gsm("\n\r\e\f\\\"")
      assert_equal true, TextMagic::API.is_gsm("èéùìòÇØøÅåÉÆæß")
      assert_equal true, TextMagic::API.is_gsm("ΔΦΓΛΩΠΨΣΘΞ")
      assert_equal true, TextMagic::API.is_gsm("^{}[~]| !#¤%&'()")
      assert_equal true, TextMagic::API.is_gsm("*+,-./_:;<=>?¡¿§")
      assert_equal true, TextMagic::API.is_gsm("ÖÑÜöñüàäÄ")
    end

    it "should return false if some characters are outside of GSM 03.38 charset" do
      assert_equal false, TextMagic::API.is_gsm("Arabic: مرحبا فيلما")
      assert_equal false, TextMagic::API.is_gsm("Chinese: 您好")
      assert_equal false, TextMagic::API.is_gsm("Cyrilic: Вильма Привет")
      assert_equal false, TextMagic::API.is_gsm("Thai: สวัสดี")
    end
  end

  describe "real_length method" do

    it "should count escaped characters as two and all others as one for non-unicode text" do
      escaped = "{}\\~[]|€"
      unescaped = random_string
      text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
      assert_equal unescaped.size + escaped.size * 2, TextMagic::API.real_length(text, false)
    end

    it "should count all characters as one for unicode text" do
      escaped = "{}\\~[]|€"
      unescaped = random_string
      text = "#{escaped}#{unescaped}".scan(/./).sort_by { rand }.join
      assert_equal unescaped.size + escaped.size, TextMagic::API.real_length(text, true)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
textmagic-0.7.1 test/test_charset.rb
textmagic-0.7.0 test/test_charset.rb