aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/string/unicode_normalized_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
commitc530d0faf064d561bf7755c55a34921572d343ef (patch)
treea3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/string/unicode_normalized_spec.rb
parent77eb1c94ee74f11ebf347f0539d3949b2cf4e2b3 (diff)
downloadruby-c530d0faf064d561bf7755c55a34921572d343ef.tar.gz
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/string/unicode_normalized_spec.rb')
-rw-r--r--spec/ruby/core/string/unicode_normalized_spec.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/ruby/core/string/unicode_normalized_spec.rb b/spec/ruby/core/string/unicode_normalized_spec.rb
new file mode 100644
index 0000000000..dc5e2742e4
--- /dev/null
+++ b/spec/ruby/core/string/unicode_normalized_spec.rb
@@ -0,0 +1,74 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "String#unicode_normalized?" do
+ before :each do
+ @nfc_normalized_str = "\u1e9b\u0323"
+ @nfd_normalized_str = "\u017f\u0323\u0307"
+ @nfkc_normalized_str = "\u1e69"
+ @nfkd_normalized_str = "\u0073\u0323\u0307"
+ end
+
+ it "returns true if string is in the specified normalization form" do
+ @nfc_normalized_str.unicode_normalized?(:nfc).should == true
+ @nfd_normalized_str.unicode_normalized?(:nfd).should == true
+ @nfkc_normalized_str.unicode_normalized?(:nfkc).should == true
+ @nfkd_normalized_str.unicode_normalized?(:nfkd).should == true
+ end
+
+ it "returns false if string is not in the supplied normalization form" do
+ @nfd_normalized_str.unicode_normalized?(:nfc).should == false
+ @nfc_normalized_str.unicode_normalized?(:nfd).should == false
+ @nfc_normalized_str.unicode_normalized?(:nfkc).should == false
+ @nfc_normalized_str.unicode_normalized?(:nfkd).should == false
+ end
+
+ it "defaults to the nfc normalization form if no forms are specified" do
+ @nfc_normalized_str.unicode_normalized?.should == true
+ @nfd_normalized_str.unicode_normalized?.should == false
+ end
+
+ it "returns true if string is empty" do
+ "".unicode_normalized?.should == true
+ end
+
+ it "returns true if string does not contain any unicode codepoints" do
+ "abc".unicode_normalized?.should == true
+ end
+
+ it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do
+ lambda { @nfc_normalized_str.force_encoding("ISO-8859-1").unicode_normalized? }.should raise_error(Encoding::CompatibilityError)
+ end
+
+ it "raises an ArgumentError if the specified form is invalid" do
+ lambda { @nfc_normalized_str.unicode_normalized?(:invalid_form) }.should raise_error(ArgumentError)
+ end
+
+ it "returns true if str is in Unicode normalization form (nfc)" do
+ str = "a\u0300"
+ str.unicode_normalized?(:nfc).should be_false
+ str.unicode_normalize!(:nfc)
+ str.unicode_normalized?(:nfc).should be_true
+ end
+
+ it "returns true if str is in Unicode normalization form (nfd)" do
+ str = "a\u00E0"
+ str.unicode_normalized?(:nfd).should be_false
+ str.unicode_normalize!(:nfd)
+ str.unicode_normalized?(:nfd).should be_true
+ end
+
+ it "returns true if str is in Unicode normalization form (nfkc)" do
+ str = "a\u0300"
+ str.unicode_normalized?(:nfkc).should be_false
+ str.unicode_normalize!(:nfkc)
+ str.unicode_normalized?(:nfkc).should be_true
+ end
+
+ it "returns true if str is in Unicode normalization form (nfkd)" do
+ str = "a\u00E0"
+ str.unicode_normalized?(:nfkd).should be_false
+ str.unicode_normalize!(:nfkd)
+ str.unicode_normalized?(:nfkd).should be_true
+ end
+end