/**
 * Copyright 2008-2009 DRIVER PROJECT (ICM UW)
 * Original author: Marek Horst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.z3950.zing.cql;

import java.io.IOException;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * CQL converter tester.
 * @author mhorst
 *
 */
public class CqlTest extends TestCase {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testQueries() throws CQLParseException, IOException {
		String inputQuery = null;
		CQLNode cqlNode = null; 
		CQLParser cqlParser = new CQLParser();
		
//		inputQuery = "description = paper and language any rus";
//		ok
//		inputQuery = "description any paper PROX/DISTANCE>3 description any Punjabi";
//		ok
//		inputQuery = "description any paper PROX>3 description any Punjabi";
//		this query is not properly parsed, no modifiers;
//		inputQuery = "dateaccepted within (1999-10-10 2008-10-20)";
//		!this query is not properly parsed, throws exception (bad date format?)
//		inputQuery = "dateaccepted within (1 and 5)";
//		strange parse result
//		inputQuery = "title any 'conflict' and title any 'Punjab'";
//		ok
//		inputQuery = "title any 'conflict' and title any 'Punjab' and author = 'Unknown'";
//		ok, notice that booleans are left joined!
//		inputQuery = "title any 'conflict' or title any 'Punjab' and author = 'Unknown'";
//		bad result?, booleans are left joined
//		inputQuery = "title any 'conflict' or (title any 'Punjab' and author = 'Unknown')";
//		ok
//		inputQuery = "description = paper sortby date";
//		ok
//		inputQuery = "description = paper orderby date";
//		orderby recognized as relation
		
//		examples from cql specification:
//		inputQuery = "dc.title any fish or dc.creator any sanderson";
//		ok
//		inputQuery = "dc.title any fish sortBy dc.date";
//		ok
//		inputQuery = "dc.title any fish or (dc.creator any sanderson and dc.identifier = \"id:1234567\")";
//		" are ommited
//		inputQuery = "dc.title any fish and not (dc.creator any sanderson)";
//		! this query is not properly parsed, seems like not is 'and not'
//		inputQuery = "someIntValue >= 5";
//		ok
//		inputQuery = "not someIntValue = 10";
//		! this query is not properly parsed, seems like not is 'and not'
		
//		examples from wiki page
//		inputQuery = "dinosaur";
//		parsed to index: cql.serverChoice, relation:'=', value: dinosaur;
//		inputQuery = "\"complete dinosaur\"";
//		parsed to index: cql.serverChoice, relation:'=', value: complete dinosaur;
//		inputQuery = "title exact \"the complete dinosaur\"";
//		ok
//		inputQuery = "dinosaur and \"ice age\"";
//		ok, index set to cql.serverChoice in both cases
//		inputQuery = "dinosaur not reptile";
//		not sure if ok, not parsed as relation, seems like not is 'and not'
//		inputQuery = "ribs prox/distance<=5 chevrons";
//		ok
//		inputQuery = "ribs prox/unit=sentence chevrons";
//		ok
//		inputQuery = "ribs prox/distance>0/unit=paragraph chevrons";
//		ok
//		inputQuery = "date within \"2002 2005\"";
//		not sure if ok, within parsed as relation
//		inputQuery = "xxx yyy zzz";
//		yyy is recognized as operator, xxx as index, zzz as value
//		inputQuery = "subject any/relevant \"fish frog\"";
//		ok
		
//		examples from http://zing.z3950.org/cql/intro.html
//		inputQuery = "(((a and b) or (c not d) not (e or f and g)) and h not i) or j";
//		ok, seems like not is 'and not'
//		inputQuery = "(((((foo))) and (((((((((((((bar)))))))))))) or (baz))))";
//		ok
//		inputQuery = "dinosaur* man?raptor*";
//		throws an exception
//		inputQuery = "\"dinosaur* man?raptor*\"";
//		ok, index parsed as cql.serverChoice
		inputQuery = "char\\*";
//		ok, index parsed as cql.serverChoice
//		inputQuery = "";
//		
//		inputQuery = "";
		System.out.println(inputQuery);
		cqlNode = cqlParser.parse(inputQuery);
		assertNotNull(cqlNode);
	}
}
