diff options
Diffstat (limited to 'spec/unit/util/zaml_spec.rb')
-rwxr-xr-x | spec/unit/util/zaml_spec.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb index d77cf99d2..858ae6044 100755 --- a/spec/unit/util/zaml_spec.rb +++ b/spec/unit/util/zaml_spec.rb @@ -1,4 +1,16 @@ #!/usr/bin/env rspec +# encoding: UTF-8 +# +# The above encoding line is a magic comment to set the default source encoding +# of this file for the Ruby interpreter. It must be on the first or second +# line of the file if an interpreter is in use. In Ruby 1.9 and later, the +# source encoding determines the encoding of String and Regexp objects created +# from this source file. This explicit encoding is important becuase otherwise +# Ruby will pick an encoding based on LANG or LC_CTYPE environment variables. +# These may be different from site to site so it's important for us to +# establish a consistent behavior. For more information on M17n please see: +# http://links.puppetlabs.com/understanding_m17n + require 'spec_helper' require 'puppet/util/monkey_patches' @@ -60,3 +72,28 @@ describe "Pure ruby yaml implementation" do x2[2].should equal(x2) end end + +# Note, many of these tests will pass on Ruby 1.8 but fail on 1.9 if the patch +# fix is not applied to Puppet or there's a regression. These version +# dependant failures are intentional since the string encoding behavior changed +# significantly in 1.9. +describe "UTF-8 encoded String#to_yaml (Bug #11246)" do + # JJM All of these snowmen are different representations of the same + # UTF-8 encoded string. + let(:snowman) { 'Snowman: [☃]' } + let(:snowman_escaped) { "Snowman: [\xE2\x98\x83]" } + + describe "UTF-8 String Literal" do + subject { snowman } + + it "should serialize to YAML" do + subject.to_yaml + end + it "should serialize and deserialize to the same thing" do + YAML.load(subject.to_yaml).should == subject + end + it "should serialize and deserialize to a String compatible with a UTF-8 encoded Regexp" do + YAML.load(subject.to_yaml).should =~ /☃/u + end + end +end |