File: converter_test.rb

package info (click to toggle)
ruby-charlock-holmes 0.6.9.4.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 304 kB
  • ctags: 94
  • sloc: ruby: 361; ansic: 264; lisp: 237; cpp: 101; sh: 21; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,380 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# encoding: utf-8
require File.expand_path("../helper", __FILE__)

class ConverterTest < MiniTest::Unit::TestCase
  def test_convert_ascii_from_iso859_1_to_utf16_and_back
    input = 'test'

    output = CharlockHolmes::Converter.convert input, 'ISO-8859-1', 'UTF-16'
    assert input.bytesize < output.bytesize
    assert input != output

    output = CharlockHolmes::Converter.convert output, 'UTF-16', 'ISO-8859-1'
    assert input.bytesize == output.bytesize
    assert input == output
  end

  def test_convert_utf8_to_utf16_and_back
    input = 'λ, λ, λ'

    output = CharlockHolmes::Converter.convert input, 'UTF-8', 'UTF-16'
    assert input.bytesize < output.bytesize
    assert input != output

    output = CharlockHolmes::Converter.convert output, 'UTF-16', 'UTF-8'
    assert input.bytesize == output.bytesize
    assert input == output
  end

  def test_params_must_be_strings
    assert_raises TypeError do
      CharlockHolmes::Converter.convert nil, 'UTF-8', 'UTF-16'
    end

    assert_raises TypeError do
      CharlockHolmes::Converter.convert 'lol', nil, 'UTF-16'
    end

    assert_raises TypeError do
      CharlockHolmes::Converter.convert 'lol', 'UTF-8', nil
    end

    begin
      CharlockHolmes::Converter.convert 'lol', 'UTF-8', 'UTF-16'
    rescue Exception => e
      assert_nil e, "#{e.class.name} raised, expected nothing"
    end
  end
end