View Javadoc

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