Skip to content

Commit

Permalink
added spec for load_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
walf443 committed Jan 3, 2009
1 parent b95338a commit df0e7db
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions spec/yaml_compatible_spec.rb
Expand Up @@ -12,56 +12,49 @@
require 'yaml'

describe YAML::LibYAML do
describe ".load" do
with_fixtures :yaml => :message do
it "should be compatible to YAML (:message)" do |yaml,message|
if message =~ /anchor/
warn YAML.load(yaml)
end
YAML::LibYAML.load(yaml).should == YAML.load(yaml)
end

test_data = <<-EOF_TEST_DATA
=== TODO: scalar Fixnum
test_data = <<-EOF_TEST_DATA
### TODO: scalar Fixnum
---
100
=== TODO: scalar Float
### TODO: scalar Float
---
10.1
=== nil
### nil
---
~
=== scalar UTF8 String
### scalar UTF8 String
---
あいうえお
=== simple mapping
### simple mapping
---
key: val
=== inline mapping
### inline mapping
---
{ key: val }
=== simple sequense
### simple sequense
---
- foo
- bar
- baz
=== inline sequense
### inline sequense
---
[ foo, bar, baz ]
=== seq in map
### seq in map
---
global:
- foo
- bar
- baz
=== TODO: anchor ( hmm, fail also in YAML. )
### TODO: anchor ( hmm, fail also in YAML. )
---
my_config1: &anchor1
- foo
Expand All @@ -71,15 +64,15 @@
my_config2: *anchor1
# from yaml spec exmaple, see also http://yaml.org/spec/1.1/
=== TODO: Example 2.19. integers
### TODO: Example 2.19. integers
---
canonical: 12345
decimal: +12_345
sexagesimal: 3:25:45
octal: 014
hexadecimal: 0xC
=== TODO: Example 2.20 Floating Point
### TODO: Example 2.20 Floating Point
---
canonical: 1.23015e+3
exponential: 12.3015e+02
Expand All @@ -88,29 +81,43 @@
negative infinity: -.inf
not a number: .NaN
=== TODO: Example 2.21 Miscelleneous
### TODO: Example 2.21 Miscelleneous
---
null: ~
true: boolean
false: boolean
string: '12345'
=== TODO: Example 2.22 Timestamps
### TODO: Example 2.22 Timestamps
---
canonical: 2001-12-15T02:59:43.1Z
iso8601: 2001-12-14t21:59:43.10-05:00
spaced: 2001-12-14 21:59:43.10 -5
date: 2002-12-14
EOF_TEST_DATA
describe '.load_stream' do
it 'should be compatible to YAML' do
YAML::LibYAML.load_stream(test_data).documents.should == YAML.load_stream(test_data).documents
end
end

describe ".load" do
with_fixtures :yaml => :message do
it "should be compatible to YAML (:message)" do |yaml,message|
if message =~ /anchor/
warn YAML.load(yaml)
end
YAML::LibYAML.load(yaml).should == YAML.load(yaml)
end

# making fixture data
data = test_data.split(/^(===.+)$\n/)
data = test_data.split(/^(###.+)$\n/)
data.shift # remove garbage

fixtures = []
while message = data.shift
message.gsub!(/^===\s+/, '')
message.gsub!(/^###\s+/, '')
yaml = data.shift
fixtures << [ { yaml => message }, message ]
end
Expand Down

0 comments on commit df0e7db

Please sign in to comment.