text 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__), 'preamble')
2
2
 
3
- begin
4
- require 'rubygems' rescue nil
5
- require 'fastercsv'
6
- METHOD = [ FasterCSV, :foreach, { :col_sep => ', ' } ]
7
- rescue LoadError
8
- require 'csv'
9
- METHOD = [ CSV, :open, 'r', ', ' ]
10
- end
3
+ require 'csv'
11
4
 
12
5
  class DoubleMetaphoneTest < Test::Unit::TestCase
13
6
 
14
7
  def test_cases
15
- METHOD.shift.send(METHOD.shift, File.rel('data', 'double_metaphone.csv'), *METHOD) do |row|
8
+ CSV.open(File.rel('data', 'double_metaphone.csv'), 'r').to_a.each do |row|
16
9
  primary, secondary = Text::Metaphone.double_metaphone(row[0])
17
-
10
+
18
11
  assert_equal row[1], primary
19
12
  assert_equal row[2], secondary.nil?? primary : secondary
20
13
  end
@@ -2,16 +2,17 @@ require File.join(File.dirname(__FILE__), 'preamble')
2
2
 
3
3
  class FigletTest < Test::Unit::TestCase
4
4
 
5
- def test_hello_world
6
- font = Text::Figlet::Font.new(File.rel('data', 'big.flf'))
7
- figlet = Text::Figlet::Typesetter.new(font)
8
- assert_equal File.read(File.rel('data', 'big.txt')), figlet['Hello World']
9
- end
5
+ if !Text.is_19?
6
+ def test_hello_world
7
+ font = Text::Figlet::Font.new(File.rel('data', 'big.flf'))
8
+ figlet = Text::Figlet::Typesetter.new(font)
9
+ assert_equal File.read(File.rel('data', 'big.txt')), figlet['Hello World']
10
+ end
10
11
 
11
- def test_no_smushing
12
- font = Text::Figlet::Font.new(File.rel('data', 'chunky.flf'))
13
- figlet = Text::Figlet::Typesetter.new(font, :smush => false)
14
- assert_equal File.read(File.rel('data', 'chunky.txt')), figlet['Chunky Bacon']
12
+ def test_no_smushing
13
+ font = Text::Figlet::Font.new(File.rel('data', 'chunky.flf'))
14
+ figlet = Text::Figlet::Typesetter.new(font, :smush => false)
15
+ assert_equal File.read(File.rel('data', 'chunky.txt')), figlet['Chunky Bacon']
16
+ end
15
17
  end
16
-
17
18
  end
@@ -41,16 +41,28 @@ class LevenshteinTest < Test::Unit::TestCase
41
41
 
42
42
  def assert_set(name)
43
43
  TEST_CASES[name].each do |s, t, x|
44
+ if defined?(Encoding) && Encoding.default_internal # Change the encoding if in 1.9
45
+ t.force_encoding(Encoding.default_internal)
46
+ s.force_encoding(Encoding.default_internal)
47
+ end
48
+
44
49
  assert_equal x, distance(s, t)
45
50
  assert_equal x, distance(t, s)
46
51
  end
47
52
  end
48
53
 
49
- def with_kcode(k)
50
- old_kcode = $KCODE
51
- $KCODE = k
52
- yield
53
- $KCODE = old_kcode
54
+ def with_encoding(kcode, encoding)
55
+ if Text.is_19?
56
+ old_encoding = Encoding.default_internal
57
+ Encoding.default_internal = encoding
58
+ yield
59
+ Encoding.default_internal = old_encoding
60
+ else # 1.8 backwards compat
61
+ old_kcode = $KCODE
62
+ $KCODE = kcode
63
+ yield
64
+ $KCODE = old_kcode
65
+ end
54
66
  end
55
67
 
56
68
  def test_easy_cases
@@ -66,13 +78,13 @@ class LevenshteinTest < Test::Unit::TestCase
66
78
  end
67
79
 
68
80
  def test_utf8_cases
69
- with_kcode('U') do
81
+ with_encoding('U', 'UTF-8') do
70
82
  assert_set(:utf8)
71
83
  end
72
84
  end
73
85
 
74
86
  def test_iso_8859_1_cases
75
- with_kcode('NONE') do
87
+ with_encoding('NONE', 'ISO-8859-1') do
76
88
  assert_set(:iso_8859_1)
77
89
  end
78
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-10-11 00:00:00 +01:00
14
+ date: 2010-02-02 00:00:00 +00:00
15
15
  default_executable:
16
16
  dependencies: []
17
17