Sha256: 942b9d2c0abc0da36252764dc3c9cb3f75c06a54d71c2a314f41b954f2c9e98b

Contents?: true

Size: 1.33 KB

Versions: 35

Compression:

Stored size: 1.33 KB

Contents

#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/util/pson'

class PsonUtil
  include Puppet::Util::Pson
end

describe Puppet::Util::Pson, :'fails_on_ruby_1.9.2' => true do
  it "should fail if no data is provided" do
    lambda { PsonUtil.new.pson_create("type" => "foo") }.should raise_error(ArgumentError)
  end

  it "should call 'from_pson' with the provided data" do
    pson = PsonUtil.new
    pson.expects(:from_pson).with("mydata")
    pson.pson_create("type" => "foo", "data" => "mydata")
  end


  { 
    'foo' => '"foo"',
    1 => '1',
    "\x80" => "\"\x80\"",
    [] => '[]'
  }.each { |str,pson|
    it "should be able to encode #{str.inspect}" do
      str.to_pson.should == pson
    end
  }

  it "should be able to handle arbitrary binary data" do
    bin_string = (1..20000).collect { |i| ((17*i+13*i*i) % 255).chr }.join
    PSON.parse(%Q{{ "type": "foo", "data": #{bin_string.to_pson} }})["data"].should == bin_string
  end

  it "should be able to handle UTF8 that isn't a real unicode character" do
    s = ["\355\274\267"]
    PSON.parse( [s].to_pson ).should == [s]
  end

  it "should be able to handle UTF8 for \\xFF" do
    s = ["\xc3\xbf"]
    PSON.parse( [s].to_pson ).should == [s]
  end

  it "should be able to handle invalid UTF8 bytes" do
    s = ["\xc3\xc3"]
    PSON.parse( [s].to_pson ).should == [s]
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/util/pson_spec.rb
puppet-2.7.25 spec/unit/util/pson_spec.rb
puppet-2.7.24 spec/unit/util/pson_spec.rb
puppet-2.7.23 spec/unit/util/pson_spec.rb
puppet-2.7.22 spec/unit/util/pson_spec.rb
puppet-2.7.21 spec/unit/util/pson_spec.rb
puppet-2.7.20 spec/unit/util/pson_spec.rb
puppet-2.7.20.rc1 spec/unit/util/pson_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/pson_spec.rb
puppet-2.7.19 spec/unit/util/pson_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/pson_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/pson_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/pson_spec.rb
puppet-2.7.18 spec/unit/util/pson_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/pson_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/pson_spec.rb
puppet-2.7.17 spec/unit/util/pson_spec.rb
puppet-2.7.16 spec/unit/util/pson_spec.rb
puppet-2.7.14 spec/unit/util/pson_spec.rb
puppet-2.7.13 spec/unit/util/pson_spec.rb