View Javadoc

1   /**
2    * Copyright (c) 2008-2011, 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  
17  package org.yaml.snakeyaml.types;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.yaml.snakeyaml.Yaml;
26  import org.yaml.snakeyaml.YamlDocument;
27  
28  /**
29   * @see http://yaml.org/type/value.html
30   */
31  public class ValueTagTest extends AbstractTest {
32  
33      /**
34       * The 'value' tag does not work as defined in the specification but exactly
35       * as in PyYAML
36       */
37      @SuppressWarnings("unchecked")
38      public void testValue() throws IOException {
39          InputStream input = YamlDocument.class.getClassLoader().getResourceAsStream(
40                  YamlDocument.ROOT + "types/value.yaml");
41          Yaml yaml = new Yaml();
42          Iterator<Object> iter = (Iterator<Object>) yaml.loadAll(input).iterator();
43          Map<String, List<String>> oldSchema = (Map<String, List<String>>) iter.next();
44          assertEquals(1, oldSchema.size());
45          List<String> list = oldSchema.get("link with");
46          assertEquals(2, list.size());
47          assertEquals("library1.dll", list.get(0));
48          assertEquals("library2.dll", list.get(1));
49          //
50          Map<String, List<Map<String, String>>> newSchema = (Map<String, List<Map<String, String>>>) iter
51                  .next();
52          assertEquals(1, newSchema.size());
53          //
54          List<Map<String, String>> list2 = newSchema.get("link with");
55          assertEquals(2, list2.size());
56          Map<String, String> map1 = list2.get(0);
57          assertEquals(2, map1.size());
58          assertEquals("library1.dll", map1.get("="));
59          assertEquals(new Double(1.2), map1.get("version"));
60          assertFalse(iter.hasNext());
61      }
62  }