friendly_id 3.0.6 → 3.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,88 +0,0 @@
1
- # encoding: utf-8
2
- require(File.expand_path("../test_helper", __FILE__))
3
-
4
- module FriendlyId
5
- module Test
6
-
7
- class SlugStringTest < ::Test::Unit::TestCase
8
-
9
- test "should approximate ascii" do
10
- # create string with range of Unicode"s western characters with
11
- # diacritics, excluding the division and multiplication signs which for
12
- # some reason or other are floating in the middle of all the letters.
13
- s = SlugString.new((0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include? c}.pack("U*"))
14
- output = s.approximate_ascii
15
- assert(output.length > s.length)
16
- assert_match output, /^[a-zA-Z']*$/
17
- end
18
-
19
- test "should strip non-word chars" do
20
- s = SlugString.new "¡feliz año!"
21
- assert_equal "feliz año", s.word_chars
22
- end
23
-
24
- test "should lowercase strings" do
25
- assert_equal "feliz año", SlugString.new("FELIZ AÑO").downcase
26
- end
27
-
28
- test "should uppercase strings" do
29
- assert_equal "FELIZ AÑO", SlugString.new("feliz año").upcase
30
- end
31
-
32
- test "should replace whitespace with dashes" do
33
- assert_equal "a-b", SlugString.new("a b").clean.with_dashes
34
- end
35
-
36
- test "should replace multiple spaces with 1 dash" do
37
- assert_equal "a-b", SlugString.new("a b").clean.with_dashes
38
- end
39
-
40
- test "should replace multiple dashes with 1 dash" do
41
- assert_equal "male-female", SlugString.new("male - female").with_dashes
42
- end
43
-
44
- test "should strip trailing space" do
45
- assert_equal "ab", SlugString.new("ab ").clean
46
- end
47
-
48
- test "should strip leading space" do
49
- assert_equal "ab", SlugString.new(" ab").clean
50
- end
51
-
52
- test "should strip trailing slashes" do
53
- assert_equal "ab", SlugString.new("ab-").clean
54
- end
55
-
56
- test "should strip leading slashes" do
57
- assert_equal "ab", SlugString.new("-ab").clean
58
- end
59
-
60
- test "should not modify valid name strings" do
61
- assert_equal "a-b-c-d", SlugString.new("a-b-c-d").clean
62
- end
63
-
64
- test "should do special approximations for German" do
65
- assert_equal "Juergen", SlugString.new("Jürgen").approximate_ascii(:german)
66
- end
67
-
68
- test "should do special approximations for Spanish" do
69
- assert_equal "anno", SlugString.new("año").approximate_ascii(:spanish)
70
- end
71
-
72
- test "should work with non roman chars" do
73
- assert_equal "検-索", SlugString.new("検 索").with_dashes
74
- end
75
-
76
- test "should work with invalid UTF-8 strings" do
77
- %w[approximate_ascii clean downcase word_chars normalize to_ascii upcase with_dashes].each do |method|
78
- string = SlugString.new("\x93abc")
79
- assert_nothing_raised do
80
- method == "truncate" ? string.send(method, 32) : string.send(method)
81
- end
82
- end
83
-
84
- end
85
-
86
- end
87
- end
88
- end