8000 Adding tests for YAML types · devrandom/ruby@6bcd7b7 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 6bcd7b7

Browse files
committed
Adding tests for YAML types
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent b337740 commit 6bcd7b7

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

test/yaml/test_boolean.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'test/unit'
2+
require 'yaml'
3+
4+
module YAML
5+
###
6+
# Test booleans from YAML spec:
7+
# http://yaml.org/type/bool.html
8+
class TestBoolean < Test::Unit::TestCase
9+
%w{ yes Yes YES true True TRUE on On ON }.each do |truth|
10+
define_method(:"test_#{truth}") do
11+
assert_equal true, YAML.load("--- #{truth}")
12+
end
13+
end
14+
15+
%w{ no No NO false False FALSE off Off OFF }.each do |truth|
16+
define_method(:"test_#{truth}") do
17+
assert_equal false, YAML.load("--- #{truth}")
18+
end
19+
end
20+
21+
###
22+
# YAML spec says "y" and "Y" may be used as true, but Syck treats them
23+
# as literal strings
24+
def test_y
25+
assert_equal "y", YAML.load("--- y")
26+
assert_equal "Y", YAML.load("--- Y")
27+
end
28+
29+
###
30+
# YAML spec says "n" and "N" may be used as false, but Syck treats them
31+
# as literal strings
32+
def test_y
33+
assert_equal "n", YAML.load("--- n")
34+
assert_equal "N", YAML.load("--- N")
35+
end
36+
end
37+
end

test/yaml/test_null.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'test/unit'
2+
require 'yaml'
3+
4+
module YAML
5+
###
6+
# Test null from YAML spec:
7+
# http://yaml.org/type/null.html
8+
class TestNull < Test::Unit::TestCase
9+
def test_null_list
10+
assert_equal [nil] * 5, YAML.load(<<-eoyml)
11+
---
12+
- ~
13+
- null
14+
-
15+
- Null
16+
- NULL
17+
eoyml
18+
end
19+
end
20+
end

test/yaml/test_omap.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'test/unit'
2+
require 'yaml'
3+
4+
module YAML
5+
class TestOmap < Test::Unit::TestCase
6+
def test_keys
7+
map = YAML::Omap.new
8+
map['foo'] = 'bar'
9+
assert_equal 'bar', map['foo']
10+
end
11+
12+
def test_order
13+
map = YAML::Omap.new
14+
map['a'] = 'b'
15+
map['b'] = 'c'
16+
assert_equal [%w{a b}, %w{b c}], map.to_a
17+
end
18+
19+
def test_square
20+
list = [["a", "b"], ["b", "c"]]
21+
map = YAML::Omap[*list.flatten]
22+
assert_equal list, map.to_a
23+
assert_equal 'b', map['a']
24+
assert_equal 'c', map['b']
25+
end
26+
27+
def test_to_yaml
28+
map = YAML::Omap['a', 'b', 'c', 'd']
29+
yaml = map.to_yaml
30+
assert_match('!omap', yaml)
31+
assert_match('- a: b', yaml)
32+
assert_match('- c: d', yaml)
33+
end
34+
35+
def test_round_trip
36+
list = [["a", "b"], ["b", "c"]]
37+
map = YAML::Omap[*list.flatten]
38+
loaded = YAML.load(YAML.dump(map))
39+
40+
assert_equal map, loaded
41+
assert_equal list, loaded.to_a
42+
end
43+
44+
###
45+
# FIXME: Syck should also support !!omap as shorthand
46+
def test_load
47+
list = [["a", "b"], ["c", "d"]]
48+
map = YAML.load(<<-eoyml)
49+
--- !omap
50+
- a: b
51+
- c: d
52+
eoyml
53+
assert_equal list, map.to_a
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)
0