package dyvil.tests;

import dyvil.collection.Map;
import dyvil.collection.mutable.TreeMap;
import dyvil.tools.dpf.ast.Expandable;
import dyvil.tools.dpf.ast.RootNode;
import dyvil.tools.dpf.converter.flatmapper.FlatMapConverter;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class DPFTests
{
	private static final String TEST_FILE = "\nnode1\n" + "{\n" + "\tintProperty = 10\n" + "\tstringProperty = \"abc\"\n"
			+ "\tlistProperty = [ 1, \"a\", true ]\n" + "\tmapProperty = {\n" + "\t\t1 : \"a\",\n" + "\t\t2 : \"b\"\n"
			+ "\t}\n" + "}\n" + "\n" + "node2.subNode\n" + "{\n" + "\tsubProperty1 = 42\n" + "\t\n" + "\tsubNode2\n"
			+ "\t{\n" + "\t\tsubProperty2 = 13\n" + "\t}\n" + "}\n";

	@Test
	public void testParser()
	{
		RootNode rootNode = RootNode.parse(TEST_FILE);

		System.out.println(rootNode);

		assertEquals(rootNode.toString(), TEST_FILE);
	}

	@Test
	public void testMap()
	{
		Map<String, Object> map = FlatMapConverter.parse(TEST_FILE);

		map.forEach(System.out::println);
	}

	@Test
	public void testExpand()
	{
		// Parse as a Map
		Map<String, Object> baseMap = new TreeMap<>();
		FlatMapConverter.parse(TEST_FILE, baseMap);

		// Parse as a Node structure
		RootNode testNode = RootNode.parse(TEST_FILE);

		// Expand the Node structure
		RootNode expandedNode = testNode.expand(baseMap, false);

		// Convert the Node structure to a Map
		Map<String, Object> nodeMap = new TreeMap<>();
		expandedNode.accept(new FlatMapConverter(nodeMap));

		Map<String, Object> expandedMap = (Map<String, Object>) Expandable.expandMap(baseMap, baseMap, false);

		assertEquals(nodeMap, expandedMap);
	}
}

@@ -361,16 +361,21 @@
 LE = %22%5Cn
+%22 + %22
 node1%5Cn%22
@@ -407,17 +407,20 @@
  = 10%5Cn%22
- 
+%0A%09%09%09
 + %22%5Ctstr
@@ -440,24 +440,146 @@
  %5C%22abc%5C%22%5Cn%22%0A
+%09%09%09+ %22%5CtstringProperty2 = %5C%22String Interpolation: %5C%5C(node1.stringProperty) where intProperty = %5C%5C(node1.intProperty)%5C%22%5Cn%22%0A
 %09%09%09+ %22%5Ctlist

Update DPFTests