blob: 216e8b5a3dfe9878484f368a56e657c3c767017c (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#!/usr/bin/env ruby
require 'spec_helper'
require 'puppet/util/pson'
class PsonUtil
include Puppet::Util::Pson
end
describe Puppet::Util::Pson 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
|