package ca.ubc.ece.salt.sdjsb.test.analysis;

import java.util.LinkedList;
import java.util.List;

import org.junit.Test;

import ca.ubc.ece.salt.sdjsb.analysis.argumentorder.ArgumentOrderAnalysis;
import ca.ubc.ece.salt.sdjsb.analysis.classify.ClassifierDataSet;
import ca.ubc.ece.salt.sdjsb.batch.AnalysisMetaInformation;
import ca.ubc.ece.salt.sdjsb.classify.alert.ArgumentOrderAlert;
import ca.ubc.ece.salt.sdjsb.classify.alert.ClassifierAlert;

public class TestArgumentOrder extends TestAnalysis {

	private final AnalysisMetaInformation AMI = new AnalysisMetaInformation(0, 0, "test", "homepage", "src file",
			"dst file", "src commit", "dst commit", "src code", "dst code");

	private void runTest(String[] args, List<ClassifierAlert> expectedAlerts, boolean printAlerts) throws Exception {
		ClassifierDataSet dataSet = new ClassifierDataSet(null, null);
		ArgumentOrderAnalysis analysis = new ArgumentOrderAnalysis(dataSet, AMI);
		super.runTest(args, expectedAlerts, printAlerts, analysis, dataSet);
	}

	/*
	 * Simplest scenario. Inserting if block.
	 */
	@Test
	public void testPM2() throws Exception {
		String src = "./test/input/argument_order/pm2_old.js";
		String dst = "./test/input/argument_order/pm2_new.js";

		List<ClassifierAlert> expectedAlerts = new LinkedList<ClassifierAlert>();
		expectedAlerts.add(new ArgumentOrderAlert(AMI, "~anonymous~", "TODO"));

		this.runTest(new String[] { src, dst }, expectedAlerts, true);
	}

	/*
	 * Also a simple scenario
	 */
	@Test
	public void testNewwww() throws Exception {
		String src = "./test/input/argument_order/newww_old.js";
		String dst = "./test/input/argument_order/newww_new.js";

		List<ClassifierAlert> expectedAlerts = new LinkedList<ClassifierAlert>();
		expectedAlerts.add(new ArgumentOrderAlert(AMI, "~anonymous~", "TODO"));

		this.runTest(new String[] { src, dst }, expectedAlerts, true);
	}

	/*
	 * TODO: Should this pass? To remove false positives, we could check if
	 * there are at least two parameters on the function
	 */
	@Test
	public void testNodeMysql() throws Exception {
		String src = "./test/input/argument_order/node-mysql_old.js";
		String dst = "./test/input/argument_order/node-mysql_new.js";

		List<ClassifierAlert> expectedAlerts = new LinkedList<ClassifierAlert>();
		expectedAlerts.add(new ArgumentOrderAlert(AMI, "PoolConfig", "TODO"));

		this.runTest(new String[] { src, dst }, expectedAlerts, true);
	}
}
@@ -1457,30 +1457,99 @@
 %09 * 
-Also a simple scenario
+No alerts expected because opt is not an argument, so the pattern%0A%09 * criteria is not match
 %0A%09 *
@@ -1791,32 +1791,35 @@
 fierAlert%3E();%0A%09%09
+// 
 expectedAlerts.a
@@ -1956,130 +1956,95 @@
 %09 * 
-TODO: Should this pass? To remove false positives, we could check if%0A%09 * there are at least two parameters on the function
+No alerts expected because there is only one argument. Which order are we%0A%09 * changing?
 %0A%09 *
@@ -2299,32 +2299,35 @@
 fierAlert%3E();%0A%09%09
+// 
 expectedAlerts.a

Update ArgumentOrder tests