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