/
diacritics_fu_spec.rb
35 lines (26 loc) · 1.21 KB
/
diacritics_fu_spec.rb
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
require 'rubygems'
# allow activation of a specific version of activesupport for testing
gem 'activesupport', "= #{ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']}" if ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']
require File.dirname(__FILE__) + '/spec_helper'
require 'active_support'
describe DiacriticsFu do
before(:all) do
puts "Testing using ActiveSupport version #{ActiveSupport::VERSION::STRING}"
end
it "should remove the accents with grace" do
DiacriticsFu::escape("éphémère").should == "ephemere"
DiacriticsFu::escape("éêèïîù").should eql("eeeiiu")
end
it "should remove more exotic accents" do
DiacriticsFu::escape("räksmörgås").should eql("raksmorgas")
end
KNOWN_DIACRITICS = { "a" => "àäâ", "e" => "éèêë", "i" => "îï", "o" => "ôö", "u" => "üû", "c" => "ç",
"I" => "ÏÎ", "E" => "ÊË", "n" => "ñ", "O" => "ÔÖ", "Y" => "Ÿ", "y" => "ÿ", "N" => "Ñ" }
KNOWN_DIACRITICS.each do |expected_replacement,originals|
it "should transform any of '#{originals}' into '#{expected_replacement}'" do
originals.each_char do |original|
DiacriticsFu.escape(original).should eql(expected_replacement)
end
end
end
end