/**
 * Copyright (c) 2008-2012, http://www.snakeyaml.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.yaml.snakeyaml.issues.issue149;

import junit.framework.TestCase;

import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Util;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.nodes.Tag;

public class GlobalDirectivesTest extends TestCase {
    public void testOneDocument() {
        String input = Util.getLocalResource("issues/issue149-one-document.yaml");
        // System.out.println(input);
        Constructor constr = new Constructor();
        TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
                "tag:ualberta.ca,2012:" + 29));
        constr.addTypeDescription(description);
        Yaml yaml = new Yaml(constr);
        Iterable<Object> parsed = yaml.loadAll(input);
        for (Object obj : parsed) {
            System.out.println(obj);
        }
    }

    public void testDirectives() {
        String input = Util.getLocalResource("issues/issue149-losing-directives.yaml");
        // System.out.println(input);
        Constructor constr = new Constructor();
        TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
                "tag:ualberta.ca,2012:" + 29));
        constr.addTypeDescription(description);
        Yaml yaml = new Yaml(constr);
        // Iterable<Object> parsed = yaml.loadAll(input);
        // for (Object obj : parsed) {
        // System.out.println(obj);
        // }
    }
}
@@ -657,16 +657,44 @@
 ue149;%0A%0A
+import java.util.Iterator;%0A%0A
 import j
@@ -718,16 +718,16 @@
 stCase;%0A
-
 %0Aimport 
@@ -1404,27 +1404,27 @@
        Itera
-ble
+tor
 %3CObject%3E par
@@ -1452,92 +1452,215 @@
 put)
-;%0A        for (Object obj : parsed) %7B%0A            System.out.println(obj);%0A        %7D
+.iterator();%0A        ComponentBean bean = (ComponentBean) parsed.next();%0A        assertEquals(0, bean.getProperty1());%0A        assertEquals(%22aaa%22, bean.getProperty2());%0A        assertFalse(parsed.hasNext());
 %0A   
@@ -2048,32 +2048,50 @@
 n(description);%0A
+        try %7B%0A    
         Yaml yam
@@ -2120,18 +2120,19 @@
         
-//
+   
  Iterabl
@@ -2179,18 +2179,19 @@
         
-//
+   
  for (Ob
@@ -2223,46 +2223,337 @@
     
-// System.out.println(obj);%0A        //
+        ComponentBean bean = (ComponentBean) obj;%0A                System.out.println(bean.getProperty1());%0A            %7D%0A            fail(%22149 must be fixed.%22);%0A        %7D catch (Exception e) %7B%0A            assertTrue(e.getMessage().startsWith(%0A                    %22while parsing a node; found undefined tag handle !u!;%22));%0A       
  %7D%0A 

Update test for issue 149