package net.minidev.json.test;

import junit.framework.TestCase;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;

public class TestFloat extends TestCase {
	public static String[] TRUE_NUMBERS = new String[] { "1.0", "123.456", "1.0E1", "123.456E12", "1.0E+1",
			"123.456E+12", "1.0E-1", "123.456E-12", "1.0e1", "123.456e12", "1.0e+1", "123.456e+12", "1.0e-1",
			"123.456e-12" };

	public static String[] FALSE_NUMBERS = new String[] { "1.0%", "123.45.6", "1.0E", "++123.456E12", "+-01",
			"1.0E+1.2" };

	public void testFloat() throws Exception {
		JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
		for (String s : TRUE_NUMBERS) {
			String json = "{v:" + s + "}";
			Double val = Double.valueOf(s.trim());
			JSONObject obj = (JSONObject) p.parse(json);
			Object value = obj.get("v");
			assertEquals("Should be parse as double", val, value);
		}
	}

	public void testNonFloat() throws Exception {
		JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
		for (String s : FALSE_NUMBERS) {
			String json = "{v:" + s + "}";
			JSONObject obj = (JSONObject) p.parse(json);
			assertEquals("Should be parse as string", s, obj.get("v"));

			String correct = "{\"v\":\"" + s + "\"}";
			assertEquals("Should be re serialized as", correct, obj.toJSONString());
		}
	}
}

@@ -94,16 +94,51 @@
 Object;%0A
+import net.minidev.json.JSONStyle;%0A
 import n
@@ -1344,11 +1344,306 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09/**%0A%09 * Error reported in issue 44%0A%09 */%0A%09public void testUUID() %7B%0A%09%09String UUID = %2258860611416142319131902418361e88%22;%0A%09%09JSONObject obj = new JSONObject();%0A%09%09obj.put(%22uuid%22, UUID);%0A%09%09String compressed = obj.toJSONString(JSONStyle.MAX_COMPRESS);%0A%09%09assertTrue(compressed.contains(%22uuid:%5C%22%22));%0A%09%7D
 %0A%7D%0A

add junit test for issue 44