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;
17  
18  import java.io.StringReader;
19  
20  import junit.framework.TestCase;
21  
22  import org.yaml.snakeyaml.events.Event;
23  import org.yaml.snakeyaml.events.StreamEndEvent;
24  import org.yaml.snakeyaml.events.StreamStartEvent;
25  
26  public class YamlParseTest extends TestCase {
27  
28      public void testParse() {
29          Yaml yaml = new Yaml();
30          Event e = null;
31          int counter = 0;
32          for (Event event : yaml.parse(new StringReader("abc: 56"))) {
33              if (e == null) {
34                  assertTrue(event instanceof StreamStartEvent);
35              }
36              e = event;
37              counter++;
38          }
39          assertTrue(e instanceof StreamEndEvent);
40          assertEquals(8, counter);
41      }
42  
43      public void testParseManyDocuments() {
44          Yaml yaml = new Yaml();
45          Event e = null;
46          int counter = 0;
47          for (Event event : yaml.parse(new StringReader("abc: 56\n---\n4\n---\nqwe\n"))) {
48              if (e == null) {
49                  assertTrue(event instanceof StreamStartEvent);
50              }
51              e = event;
52              counter++;
53          }
54          assertTrue(e instanceof StreamEndEvent);
55          assertEquals(14, counter);
56      }
57  }