package test.java.latexee.docast;

import static org.junit.Assert.*;

import main.java.latexee.declareast.MacroDeclaration;
import main.java.latexee.declareast.OperatorDeclaration;
import main.java.latexee.exceptions.DeclarationInitialisationException;
import main.java.latexee.parsers.DeclarationParser;

import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.Test;

public class DeclarationTest {

	@Test
	public void test1() throws DeclarationInitialisationException {
		ParseTree pt = DeclarationParser.parseDeclaration("{syntax={infix,7,\"*\",l}, meaning=arith1.times}");
		OperatorDeclaration od = new OperatorDeclaration(pt,0);		
		assertEquals("infix", od.getType());
		assertEquals("*", od.getOperator());
		assertEquals("l", od.getAssociativity());
		assertEquals("7", ""+od.getPriority());
		assertEquals("arith1", od.getContentDictionary());
		assertEquals("times", od.getMeaning());
		assertEquals("{}", ""+od.getMiscellaneous());
	}
	
	@Test(expected=DeclarationInitialisationException.class)
	public void test2() throws DeclarationInitialisationException {
		ParseTree decTree = DeclarationParser.parseDeclaration("{syntax={prefix,100,\"\\%\"}, meaning=arith1.remainder, misc=\"some misc info\"}");
		new OperatorDeclaration(decTree,0);
	}
	
	@Test
	public void test3() throws DeclarationInitialisationException {
		ParseTree pt = DeclarationParser.parseDeclaration("{macro=\\frac, meaning=arith1.divide, argspec=[2], code={...}}");
		MacroDeclaration md = new MacroDeclaration(pt,0);		
		assertEquals("frac", md.getMacroName());
		assertEquals("arith1", md.getContentDictionary());
		assertEquals("divide", md.getMeaning());
		assertEquals("false", ""+md.hasOptionalArgument());
		assertEquals("{code={...}}", ""+md.getMiscellaneous());
	}
	
	@Test
	public void test4() throws DeclarationInitialisationException {
		ParseTree pt = DeclarationParser.parseDeclaration("{macro=\\tuple, meaning=ecc.Tuple, argspec=[2], code={#1, \\ldots, #2}}");
		MacroDeclaration md = new MacroDeclaration(pt,0);		
		assertEquals("tuple", md.getMacroName());
		assertEquals("ecc", md.getContentDictionary());
		assertEquals("Tuple", md.getMeaning());
		assertEquals("false", ""+md.hasOptionalArgument());
		assertEquals("{code={#1, \\ldots, #2}}", ""+md.getMiscellaneous());
	}

}

@@ -1648,35 +1648,22 @@
 %09%09assert
-Equals(%22false%22, %22%22+
+False(
 md.hasOp
@@ -2146,27 +2146,14 @@
 sert
-Equals(%22false%22, %22%22+
+False(
 md.h
@@ -2248,11 +2248,577 @@
 ());%0A%09%7D%0A
+%09%0A%09%0A%09@Test%0A%09public void test5() throws DeclarationInitialisationException %7B%0A%09%09ParseTree pt = DeclarationParser.parseDeclaration(%22%7Bmacro=%5C%5Cfrac, meaning=arith1.divide, argspec=%5B2%5D%5B1%5D, meaningOpt=arith1.plus, code=%7B...%7D%7D%22);%0A%09%09MacroDeclaration md = new MacroDeclaration(pt,0);%09%09%0A%09%09assertEquals(%22frac%22, md.getMacroName());%0A%09%09assertEquals(%22arith1%22, md.getContentDictionary());%0A%09%09assertEquals(%22divide%22, md.getMeaning());%0A%09%09assertTrue(md.hasOptionalArgument());%0A%09%09assertEquals(%22plus%22, md.getOptionalMeaning());%0A%09%09assertEquals(%22%7Bcode=%7B...%7D%7D%22, %22%22+md.getMiscellaneous());%0A%09%7D%0A%09
 %0A%7D%0A

Revert "Revert "Added optional meaning test""