/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.test;

import java.io.PrintStream;

import org.joda.time.DateTime;

import divconq.io.OutputWrapper;
import divconq.lang.Memory;
import divconq.struct.CompositeParser;
import divconq.struct.builder.YamlStreamBuilder;

public class TestYaml {
	public static void main(String[] args) {
		Memory ydest = new Memory();
		OutputWrapper os = new OutputWrapper(ydest);
		YamlStreamBuilder sb = new YamlStreamBuilder(new PrintStream(os));
		
		try {
			sb.startList();
			
			sb.startList();

			sb.startList();
			sb.scalar("a");
			sb.scalar("b");
			sb.endList();

			sb.scalar();
			sb.scalar(22);
			sb.scalar(2.2);
			
			sb.startList();
			sb.scalar(2.2);
			sb.scalar();
			sb.scalar(22);
			sb.endList();

			sb.endList();
			
			
			sb.startRecord();
			sb.field("Name", "ted");
			sb.field("Age", 7);
			sb.field("DOB", new DateTime(1998, 8, 3, 17, 12));
			sb.field("Sex", "m");
			sb.field("Software");
			sb.startList();
			sb.scalar("Afterstep <& or \"");
			sb.scalar("CTWM this is an abcdefghijklmnopqrstuvwxy is an abcdefghijklmnopqrstuvwxy is /> an abcdefghijklmnopqrstuvwxy is \nan abcdefghijklmnopqrstuvwxy is \tan abcdefghijklmnopqrstuvwxy");
			sb.scalar("Oroborus");
			sb.endList();
			sb.field("Friends");
			sb.startList();
			
			sb.startRecord();
			sb.field("Name", "macy");
			sb.field("Age", 6);
			sb.field("Sex", "f");
			sb.endRecord();
			
			sb.startRecord();
			sb.field("Name", "rich");
			sb.field("Age", 7);
			sb.field("Sex", "m");
			sb.field("Foods");
			sb.startList();
			sb.scalar("Apple");
			sb.scalar("Cookie");
			sb.endList();
			sb.endRecord();
			
			sb.endList();
			sb.endRecord();
			
			sb.startRecord();
			sb.field("Name", "kathy");
			sb.field("Father");
			sb.startRecord();
			sb.field("Name", "Ted");
			sb.field("Age", 29);
			sb.endRecord();
			sb.field("Age");
			sb.field("DOB", new DateTime(1994, 3, 13, 8, 55));
			sb.field("Sex", "f");
			sb.endRecord();
			
			sb.endList();
		}
		catch (Exception x) {
			System.out.println("builder error: " + sb);
		}

		System.out.println("built:\n" + ydest);
		
		//String yaml = "---\nboolean: !!bool \"true\"\ninteger: !!int \"3\"\nfloat: !!float \"3.14\"\nnull: !!null\nstr: !!str \"abc\"\n"
		//		+ "---\n- Afterstep\n- CTWM\n- Oroborus";

		//String yaml = "datetime: !!timestamp 2009-12-09T08:35:45.000Z\nboolean: !!bool \"true\"\ninteger: !!int \"3\"\nfloat: !!float \"3.14\"\nnull: !!null\nstr: !!str \"abc\"\n";

		ydest.setPosition(0);
		
		System.out.println();
		
		System.out.println(CompositeParser.parseYaml(ydest).toString());
		
		System.exit(0);
	}
}
