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