package com.cflint;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.cflint.config.ConfigRuntime;
import com.cflint.plugins.core.VarScoper;

import cfml.parsing.reporting.ParseException;

public class TestCFBugs_ParseError {

	private CFLint cfBugs;

	@Before
	public void setUp() {
		final ConfigRuntime conf = new ConfigRuntime();
		cfBugs = new CFLint(conf, new VarScoper());
		cfBugs.setLogError(true);
	}
	
	@Test
	public void testSimpleCFSET() throws ParseException, IOException{
		final String cfcSrc = "<cfcomponent>\r\n" +
				"<cffunction name=\"test\">\r\n" +
				"	<cfset var x={}/>\r\n" +
				"	<cfset var x.y=123/>\r\n" +
				"</cffunction>\r\n" +
				"</cfcomponent>";
		cfBugs.process(cfcSrc,"test");
		List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
		System.out.println(result);
		assertEquals(1,result.size());
		assertEquals("PARSE_ERROR",result.get(0).getMessageCode());
		assertEquals(4,result.get(0).getLine());
	}
	
	@Test
	@Ignore
	//Parsing error fixed!
	public void testLookBackError() throws ParseException, IOException{
		final String cfcSrc = "<cfcomponent>\r\n" +
				"<cffunction name=\"test\">\r\n" +
				"	<cfset var user = userservice[\"getuser\"]();/>\r\n" +
				"</cffunction>\r\n" +
				"</cfcomponent>";
		cfBugs.process(cfcSrc,"test");
		List<BugInfo> result = cfBugs.getBugs().getFlatBugList();
		System.out.println(result.get(0));
		assertEquals(1,result.size());
		assertEquals("PARSE_ERROR",result.get(0).getMessageCode());
		assertEquals(3,result.get(0).getLine());
	}
}

@@ -889,16 +889,20 @@
 gs().get
+Flat
 BugList(
@@ -906,35 +906,8 @@
 st()
-.values().iterator().next()
 ;%0A%09%09
@@ -941,33 +941,33 @@
 %0A%09%09assertEquals(
-1
+0
 ,result.size());
@@ -971,113 +971,8 @@
 ));%0A
-%09%09assertEquals(%22PARSE_ERROR%22,result.get(0).getMessageCode());%0A%09%09assertEquals(4,result.get(0).getLine());%0A
 %09%7D%0A%09

fix test that was expecting 'var somevar.somevar=something' to be a parse error, since it isn't anymore