package examples;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import org.yaml.snakeyaml.Yaml;

public class LoadExampleTest extends TestCase {
    @SuppressWarnings("unchecked")
    public void testLoad() {
        Yaml yaml = new Yaml();
        String document = "\n- Hesperiidae\n- Papilionidae\n- Apatelodidae\n- Epiplemidae";
        System.out.println(document);
        List<String> list = (List<String>) yaml.load(document);
        System.out.println(list);
        assertEquals("[Hesperiidae, Papilionidae, Apatelodidae, Epiplemidae]", list.toString());
    }

    @SuppressWarnings("unchecked")
    public void testLoadFromString() {
        Yaml yaml = new Yaml();
        String document = "hello: 25";
        Map map = (Map) yaml.load(document);
        assertEquals("{hello=25}", map.toString());
        assertEquals(new Long(25), map.get("hello"));
    }

    public void testLoadFromStream() throws FileNotFoundException {
        InputStream input = new FileInputStream(new File("src/test/resources/reader/utf-8.txt"));
        Yaml yaml = new Yaml();
        Object data = yaml.load(input);
        assertEquals("test", data);
        //
        data = yaml.load(new ByteArrayInputStream("test2".getBytes()));
        assertEquals("test2", data);
    }
}

@@ -1502,12 +1502,443 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    public void testLoadManyDocuments() throws FileNotFoundException %7B%0D%0A        InputStream input = new FileInputStream(new File(%0D%0A                %22src/test/resources/specification/example2_28.yaml%22));%0D%0A        Yaml yaml = new Yaml();%0D%0A        int counter = 0;%0D%0A        for (Object data : yaml.loadAll(input)) %7B%0D%0A            System.out.println(data);%0D%0A            counter++;%0D%0A        %7D%0D%0A        assertEquals(3, counter);%0D%0A    %7D%0D
 %0A%7D%0D%0A

add testLoadManyDocuments() test