package org.mones.chartjsgenj;

import static org.junit.Assert.*;

import org.junit.Test;
import org.mones.chartjsgenj.Colour;
import org.mones.chartjsgenj.JSON;
import org.mones.chartjsgenj.Options;

public class OptionsTest {

	@Test
	public void testAddJSON() {
		Options o = new Options();
		assertNotNull(o);
		StringBuilder sb = new StringBuilder();
		o.addJSON(sb);
		assertEquals(JSON.OBJ_BEGIN.length() + JSON.OBJ_END.length(),
			sb.length());
		StringBuilder sb2 = new StringBuilder();
		o.scaleFontColor = new Colour();
		o.addJSON(sb2);
		assertEquals(JSON.OBJ_BEGIN.length() + "scaleFontColor".length()
			+ JSON.FV_SEP.length() + "\"rgba(0, 0, 0, 1.0)\"".length()
			+ JSON.OBJ_END.length(), sb2.length());
	}

	@Test
	public void testJsOptionsVar() {
		Options o = new Options();
		assertNotNull(o);
		String options = o.jsOptionsVar("options");
		assertEquals("var options = {  };", options);
		o.scaleFontSize = 10;
		String jsoptions = o.jsOptionsVar("options");
		assertEquals("var options = { scaleFontSize : 10 };", jsoptions);
		o.scaleFontColor = new Colour();
		String jsoptions2 = o.jsOptionsVar("options2");
		assertEquals("var options2 = { scaleFontSize : 10,"
				+ " scaleFontColor : \"rgba(0, 0, 0, 1.0)\" };", jsoptions2);
	}

}

@@ -1248,14 +1248,327 @@
 ions2);%0A
+%09%09o.scaleLabel =%0A%09%09%09%09new JavaScript(%22function(i) %7B return %5C%22 %5C%22 + i.value; %7D%22);%0A%09%09String jsoptions3 = o.jsOptionsVar(%22options3%22);%0A%09%09assertEquals(%22var options3 = %7B scaleLabel : function(i) %7B%22%0A%09%09%09%09+ %22 return %5C%22 %5C%22 + i.value; %7D, scaleFontSize : 10,%22%0A%09%09%09%09+ %22 scaleFontColor : %5C%22rgba(0, 0, 0, 1.0)%5C%22 %7D;%22, jsoptions3);%0A
 %09%7D%0A%0A%7D%0A

Check also raw JS options