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.representer;
17  
18  import junit.framework.TestCase;
19  
20  import org.yaml.snakeyaml.DumperOptions;
21  import org.yaml.snakeyaml.Util;
22  import org.yaml.snakeyaml.Yaml;
23  
24  public class DumpStackTraceTest extends TestCase {
25  
26      public void testJavaStackTrace() {
27          Yaml yaml = new Yaml();
28          String input = Util.getLocalResource("representer/stacktrace1.txt");
29          String result = yaml.dump(input);
30          // System.out.println(result);
31          assertEquals(result, yaml.dump(yaml.load(result)));
32      }
33  
34      public void testJavaStackTraceWithNoSpecialCharacters() {
35          DumperOptions options = new DumperOptions();
36          options.setWidth(50);
37          Yaml yaml = new Yaml(options);
38          String input = Util.getLocalResource("representer/stacktrace2.txt");
39          assertEquals(-1, input.indexOf(':'));
40          assertEquals(-1, input.indexOf('\t'));
41          String result = yaml.dump(input);
42          // System.out.println(result);
43          assertEquals(result, yaml.dump(yaml.load(result)));
44      }
45  
46      public void testJavaStackTraceWithTabs() {
47          Yaml yaml = new Yaml();
48          String input = Util.getLocalResource("representer/stacktrace3.txt");
49          assertEquals(-1, input.indexOf(':'));
50          assertTrue("Tabs must be used.", input.indexOf('\t') > 0);
51          String result = yaml.dump(input);
52          // System.out.println(result);
53          assertEquals(result, yaml.dump(yaml.load(result)));
54      }
55  
56      public void testJavaStackTraceWithoutTabs() {
57          Yaml yaml = new Yaml();
58          String input = Util.getLocalResource("representer/stacktrace1.txt");
59          String result = (String) yaml.dump(input);
60          // System.out.println(result);
61          String etalon = Util.getLocalResource("representer/stacktrace1.yaml");
62          // http://code.google.com/p/snakeyaml/issues/detail?id=66
63          assertEquals(etalon, result);
64      }
65  }