• 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.Date;
19 import java.util.List;
20 import java.util.Map;
21 
22 import junit.framework.TestCase;
23 
24 /**
25  * Test Chapter 2.5 from the YAML specification
26  *
27  * @see <a href="http://yaml.org/spec/1.1/"></a>
28  */
29 public class Chapter2_5Test extends TestCase {
30 
31     @SuppressWarnings("unchecked")
testExample_2_28()32     public void testExample_2_28() {
33         YamlStream resource = new YamlStream("example2_28.yaml");
34         List<Object> list = (List<Object>) resource.getNativeData();
35         assertEquals(3, list.size());
36         Map<String, Object> data0 = (Map<String, Object>) list.get(0);
37         Date date = (Date) data0.get("Time");
38         assertEquals("Date: " + date, 1006545702000L, date.getTime());
39         assertEquals("ed", data0.get("User"));
40         assertEquals("This is an error message for the log file", data0.get("Warning"));
41         //
42         Map<String, Object> data1 = (Map<String, Object>) list.get(1);
43         Date date1 = (Date) data1.get("Time");
44         assertTrue("Date: " + date1, date1.after(date));
45         assertEquals("ed", data1.get("User"));
46         assertEquals("A slightly different error message.", data1.get("Warning"));
47         //
48         Map<String, Object> data3 = (Map<String, Object>) list.get(2);
49         Date date3 = (Date) data3.get("Date");
50         assertTrue("Date: " + date3, date3.after(date1));
51         assertEquals("ed", data3.get("User"));
52         assertEquals("Unknown variable \"bar\"", data3.get("Fatal"));
53         List<Map<String, String>> list3 = (List<Map<String, String>>) data3.get("Stack");
54         Map<String, String> map1 = list3.get(0);
55         assertEquals("TopClass.py", map1.get("file"));
56         assertEquals(new Integer(23), map1.get("line"));
57         assertEquals("x = MoreObject(\"345\\n\")\n", map1.get("code"));
58         Map<String, String> map2 = list3.get(1);
59         assertEquals("MoreClass.py", map2.get("file"));
60         assertEquals(new Integer(58), map2.get("line"));
61         assertEquals("foo = bar", map2.get("code"));
62     }
63 }
64