xref: /aosp_15_r20/external/snakeyaml/src/test/java/examples/CollectionStyleTest.java (revision ac2a7c1bf4e14d82f3bd566dcc2d76d5b42faf34)
1 /**
2  * Copyright (c) 2008, SnakeYAML
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package examples;
15 
16 import junit.framework.TestCase;
17 import org.yaml.snakeyaml.DumperOptions;
18 import org.yaml.snakeyaml.Yaml;
19 
20 public class CollectionStyleTest extends TestCase {
21 
testNestedStyle()22   public void testNestedStyle() {
23     Yaml yaml = new Yaml();
24     String document = "  a: 1\n  b:\n    c: 3\n    d: 4\n";
25     assertEquals("a: 1\nb: {c: 3, d: 4}\n", yaml.dump(yaml.load(document)));
26   }
27 
testNestedStyle2()28   public void testNestedStyle2() {
29     DumperOptions options = new DumperOptions();
30     options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
31     Yaml yaml = new Yaml(options);
32     String document = "  a: 1\n  b:\n    c: 3\n    d: 4\n";
33     assertEquals("a: 1\nb:\n  c: 3\n  d: 4\n", yaml.dump(yaml.load(document)));
34   }
35 }
36