package ch.hsr.ifs.pystructure.tests.utils;

import org.python.pydev.parser.jython.ParseException;
import org.python.pydev.parser.jython.ast.Attribute;
import org.python.pydev.parser.jython.ast.Call;
import org.python.pydev.parser.jython.ast.Expr;
import org.python.pydev.parser.jython.ast.Module;

import ch.hsr.ifs.pystructure.parser.Parser;
import ch.hsr.ifs.pystructure.typeinference.model.base.NodeUtils;
import junit.framework.TestCase;

public class NodeUtilsTest extends TestCase {
	
	public void testGetId() throws ParseException {
		Module module = Parser.parse("module.func");
		Expr expr = (Expr) module.body[0];
		Attribute attribute = (Attribute) expr.value;
		assertEquals("func", NodeUtils.getId(attribute.attr));
	}
	
	public void testGetCallForFunc() throws ParseException {
		Module module = Parser.parse("module.func(arg)");
		Expr expr = (Expr) module.body[0];
		Call call = (Call) expr.value;
		call.func.parent = call;
		
		assertEquals(call, NodeUtils.getCallForFunc(call.func));
	}
	
}

@@ -92,16 +92,66 @@
 eption;%0A
+import org.python.pydev.parser.jython.ast.Assign;%0A
 import o
@@ -1052,10 +1052,538 @@
 );%0A%09%7D%0A%09%0A
+%09public void testGetPrettyPrinted() throws ParseException %7B%0A%09%09Module module = Parser.parse(%22x = 42%22);%0A%09%09Assign assign = (Assign) module.body%5B0%5D;%0A%09%09String expected =%0A%09%09%09%09%22Assign%5Cn%22 +%0A%09%09%09%09%22%7C   targets = %5Cn%22 +%0A%09%09%09%09%22%7C   %7C   Name%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   %7C   id = x,%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   %7C   ctx = Store%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   %5Cn%22 +%0A%09%09%09%09%22%7C   ,%5Cn%22 +%0A%09%09%09%09%22%7C   value = Num%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   n = 42,%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   type = Int,%5Cn%22 +%0A%09%09%09%09%22%7C   %7C   num = 42%5Cn%22 +%0A%09%09%09%09%22%7C   %5Cn%22 +%0A%09%09%09%09%22%22;%0A%09%09assertEquals(expected, NodeUtils.getPrettyPrinted(assign));%0A%09%7D%0A%09%0A
 %7D%0A

Test for getPrettyPrinted.