package eu.dnetlib.utils.cql;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class CqlQueryTest {

	@Test
	public void testContains() throws CqlException {
		CqlQuery query1 = Cql.parse("field = value");
		CqlQuery query2 = Cql.parse("field = value and foo");
		
		assertTrue(query1.contains(query2));
		assertFalse(query2.contains(query1));
	}

	@Test
	public void testFreeKeywordsContains() throws CqlException {
		CqlQuery query1 = Cql.parse("foo and bar");
		CqlQuery query2 = Cql.parse("bolek and lolek");
		
		assertFalse(query1.contains(query2));
		assertFalse(query2.contains(query1));

		query1 = Cql.parse("foo and f=v");
		query2 = Cql.parse("bar and f=v");
		
		assertFalse(query1.contains(query2));
		assertFalse(query2.contains(query1));

		query1 = Cql.parse("foo and f=v");
		query2 = Cql.parse("f=v");
		
		assertFalse(query1.contains(query2));
		assertTrue(query2.contains(query1));
	}
	
	@Test
	public void testCommutative() throws CqlException {
		CqlQuery query1 = Cql.parse("a and b and c and d");
		CqlQuery query2 = Cql.parse("a and c and b and d");
		
		assertTrue(query1.contains(query2));
		assertTrue(query2.contains(query1));
	}
	
	@Test
	public void testParenthesis() throws CqlException{
		CqlQuery query1 = Cql.parse("a and (b or c)");
		System.out.println(query1);
		
		CqlQuery query2 = Cql.parse("a = \"b = c\"  and ( (f1=b) or (f2=c))");
		System.out.println(query2);
		
	/*	CqlQuery query3 = Cql.parse("a = b  and ( (c and f1=b) or (f2=c))");
		System.out.println(query3);
		
		CqlQuery query4 = Cql.parse("data and collection = 10-0358d07e-e81e" +
				"-48c3-a6a7-8dc5575255ad_Q29sbGVjdGlvbkRTUmVzb3VyY2VzL0NvbGxlY3" +
				"Rpb25EU1Jlc291cmNlVHlwZQ==");
		System.out.println(query4);
		
		query4 = Cql.parse("data and ((collection = 10-0358d07e-e81e" +
				"-48c3-a6a7-8dc5575255ad_Q29sbGVjdGlvbkRTUmVzb3VyY2VzL0NvbGxlY3" +
				"Rpb25EU1Jlc291cmNlVHlwZQ==) or (collection = 10-0358d07e-e81e" +
				"-48c3-a6a7-8dc5575255ad_Q29sbGVjdGlvbkRTUmVzb3VyY2VzL0NvbGxlY3==))");
		
		System.out.println(query4); */
	}
}
