/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.operator;

import static org.animotron.Expression.*;

import org.animotron.ATest;
import org.animotron.Expression;
import org.animotron.operator.query.ANY;
import org.animotron.operator.query.GET;
import org.animotron.operator.relation.HAVE;
import org.animotron.operator.relation.IS;
import org.animotron.operator.relation.USE;
import org.junit.Test;

/**
 * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
 *
 */
public class ContextTests extends ATest {
	
	@Test
	public void getFromPFlow() throws Exception {
        System.out.println("Test empty 'get' ...");
        
    	new Expression(
			_(THE._, "A")
		);
    	new Expression(
			_(THE._, "B")
		);
    	new Expression(
			_(THE._, "C", _(HAVE._, "A", text(".")), _(IC._, "B", _(GET._, "A")))
		);
    	Expression D = new Expression(
			_(THE._, "D", _(GET._, "B", _(AN._, "C")))
		);
    	
        //System.out.println("get:Z an:B");
        assertAnimo(D, "<the:D><have:B>.<have:B></the:D>");

        //System.out.println("done.");
	}
	
	@Test
	public void anyWithUse() throws Exception {
        System.out.println("Test 'get' ...");
        
    	new Expression(
			_(THE._, "A")
		);
    	new Expression(
			_(THE._, "B", _(IS._, "A"))
		);
    	new Expression(
			_(THE._, "C", _(IS._, "B"))
		);
    	new Expression(
			_(THE._, "D", _(ANY._, "A"))
		);
    	new Expression(
			_(THE._, "E", _(AN._, "D", _(USE._, "B")))
		);
    	new Expression(
			_(THE._, "F", _(AN._, "D", _(USE._, "C")))
		);
    	new Expression(
			_(THE._, "G", _(AN._, "E", _(USE._, "A")))
		);
    	
        //System.out.println("any:A");
        //assertEquals("D", "<the:D><the:A></the:A><the:B></the:B><the:C></the:C></the:D>");

        //System.out.println("an:D use:B");
//        assertAnimo(E, "<the:E><the:D><the:B></the:B><the:C></the:C></the:D></the:E>");

        //System.out.println("done.");
	}
}

@@ -1602,16 +1602,20 @@
 );%0A    %09
+new 
 Expressi
@@ -1620,10 +1620,77 @@
 sion
- D
+(%0A%09%09%09_(THE._, %22D%22, _(HAVE._, %22A%22, text(%22:%22)))%0A%09%09);%0A%0A    %09Expression E
  = n
@@ -1713,25 +1713,25 @@
 %09%09_(THE._, %22
-D
+E
 %22, _(GET._, 
@@ -1747,32 +1747,119 @@
 ._, %22C%22)))%0A%09%09);%0A
+    %09Expression F = new Expression(%0A%09%09%09_(THE._, %22F%22, _(GET._, %22B%22, _(AN._, %22D%22)))%0A%09%09);%0A
     %09%0A        //
@@ -1886,14 +1886,14 @@
 get:
-Z
+B
  an:
-B
+C
 %22);%0A
@@ -1916,17 +1916,17 @@
 imo(
-D
+E
 , %22%3Cthe:
 D%3E%3Ch
@@ -1921,17 +1921,17 @@
 , %22%3Cthe:
-D
+E
 %3E%3Chave:B
@@ -1942,25 +1942,130 @@
 ave:B%3E%3C/the:
-D
+E%3E%22);%0A%0A        //System.out.println(%22get:B an:D%22);%0A        assertAnimo(F, %22%3Cthe:F%3E%3Chave:B%3E:%3Chave:B%3E%3C/the:F
 %3E%22);%0A%0A      

empty get on is topology