• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, http://www.snakeyaml.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.yaml.snakeyaml;
17 
18 import java.util.List;
19 import java.util.Map;
20 
21 import junit.framework.TestCase;
22 
23 /**
24  * Test Chapter 2.2 from the YAML specification
25  *
26  * @see <a href="http://yaml.org/spec/1.1/"></a>
27  */
28 public class Chapter2_2Test extends TestCase {
29 
30     @SuppressWarnings("unchecked")
testExample_2_7()31     public void testExample_2_7() {
32         YamlStream resource = new YamlStream("example2_7.yaml");
33         List<Object> list = (List<Object>) resource.getNativeData();
34         assertEquals(2, list.size());
35         List<String> list1 = (List<String>) list.get(0);
36         assertEquals(3, list1.size());
37         assertEquals("Mark McGwire", list1.get(0));
38         assertEquals("Sammy Sosa", list1.get(1));
39         assertEquals("Ken Griffey", list1.get(2));
40         List<String> list2 = (List<String>) list.get(1);
41         assertEquals(2, list2.size());
42         assertEquals("Chicago Cubs", list2.get(0));
43         assertEquals("St Louis Cardinals", list2.get(1));
44     }
45 
46     @SuppressWarnings("unchecked")
testExample_2_8()47     public void testExample_2_8() {
48         YamlStream resource = new YamlStream("example2_8.yaml");
49         List<Object> list = (List<Object>) resource.getNativeData();
50         assertEquals(2, list.size());
51         Map<String, String> map1 = (Map<String, String>) list.get(0);
52         assertEquals(3, map1.size());
53         assertEquals(new Integer(72200), map1.get("time"));
54         assertEquals("Sammy Sosa", map1.get("player"));
55         assertEquals("strike (miss)", map1.get("action"));
56         Map<String, String> map2 = (Map<String, String>) list.get(1);
57         assertEquals(3, map2.size());
58         assertEquals(new Integer(72227), map2.get("time"));
59         assertEquals("Sammy Sosa", map2.get("player"));
60         assertEquals("grand slam", map2.get("action"));
61     }
62 
63     @SuppressWarnings("unchecked")
testExample_2_9()64     public void testExample_2_9() {
65         YamlDocument document = new YamlDocument("example2_9.yaml");
66         Map<String, Object> map = (Map<String, Object>) document.getNativeData();
67         assertEquals(map.toString(), 2, map.size());
68         List<String> list1 = (List<String>) map.get("hr");
69         assertEquals(2, list1.size());
70         assertEquals("Mark McGwire", list1.get(0));
71         assertEquals("Sammy Sosa", list1.get(1));
72         List<String> list2 = (List<String>) map.get("rbi");
73         assertEquals(2, list2.size());
74         assertEquals("Sammy Sosa", list2.get(0));
75         assertEquals("Ken Griffey", list2.get(1));
76     }
77 
78     @SuppressWarnings("unchecked")
testExample_2_10()79     public void testExample_2_10() {
80         YamlDocument document = new YamlDocument("example2_10.yaml");
81         Map<String, Object> map = (Map<String, Object>) document.getNativeData();
82         assertEquals("Examples 2.9 and 2.10 must be identical.",
83                 new YamlDocument("example2_9.yaml").getNativeData(), map);
84     }
85 
86     @SuppressWarnings("unchecked")
testExample_2_11()87     public void testExample_2_11() {
88         YamlDocument document = new YamlDocument("example2_11.yaml");
89         Map<Object, Object> map = (Map<Object, Object>) document.getNativeData();
90         assertEquals(2, map.size());
91         for (Object key : map.keySet()) {
92             List<String> list = (List<String>) key;
93             assertEquals(2, list.size());
94         }
95     }
96 
testExample_2_12()97     public void testExample_2_12() {
98         YamlDocument document = new YamlDocument("example2_12.yaml");
99         @SuppressWarnings("unchecked")
100         List<Map<Object, Object>> list = (List<Map<Object, Object>>) document.getNativeData();
101         assertEquals(3, list.size());
102         Map<Object, Object> map1 = (Map<Object, Object>) list.get(0);
103         assertEquals(2, map1.size());
104         assertEquals("Super Hoop", map1.get("item"));
105         Map<Object, Object> map2 = (Map<Object, Object>) list.get(1);
106         assertEquals(2, map2.size());
107         assertEquals("Basketball", map2.get("item"));
108         Map<Object, Object> map3 = (Map<Object, Object>) list.get(2);
109         assertEquals(2, map3.size());
110         assertEquals("Big Shoes", map3.get("item"));
111     }
112 }
113