<!DOCTYPE html>
<html>
<head>
<script src="../../svg/dynamic-updates/resources/SVGTestCase.js"></script>
<script src="../../resources/js-test-pre.js"></script>
<style>
* {
    font-family: 'Ahem';
    font-size: 16px;
}
</style>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test scientific numbers on <length> values for SVG presentation attributes.")
if (window.testRunner)
    testRunner.dumpAsText();
createSVGTestCase();

var text = createSVGElement("text");
text.setAttribute("id", "text");
text.setAttribute("x", "100px");
text.setAttribute("y", "100px");
rootSVGElement.appendChild(text);

function test(valueString, expectedValue, tolerance) {
	// Reset baseline-shift to baseline.
	text.setAttribute("baseline-shift", "baseline");
	shouldBeEqualToString("getComputedStyle(text).baselineShift", "baseline");

	// Run test
	text.setAttribute("baseline-shift", valueString);
    if (tolerance)
        shouldBeCloseTo("parseFloat(getComputedStyle(text).baselineShift)", parseFloat(expectedValue), tolerance);
    else
        shouldBeEqualToString("getComputedStyle(text).baselineShift", expectedValue);
}

debug("");
debug("Test positive exponent values with 'e'");
test(".5e2", "50px");
test("5e1", "50px");
test("0.5e2", "50px");
test("+.5e2", "50px");
test("+5e1", "50px");
test("+0.5e2", "50px");
test(".5e+2", "50px");
test("5e+1", "50px");
test("0.5e+2", "50px");

debug("");
debug("Test positive exponent values with 'E'");
test(".5E2", "50px");
test("5E1", "50px");
test("0.5E2", "50px");
test("+.5E2", "50px");
test("+5E1", "50px");
test("+0.5E2", "50px");
test(".5E+2", "50px");
test("5E+1", "50px");
test("0.5E+2", "50px");

debug("");
debug("Test negative exponent values with 'e'");
test("5000e-2", "50px");
test("500e-1", "50px");
test("+5000e-2", "50px");
test("+500e-1", "50px");
test("+5000e-2px", "50px");
test("+500e-1px", "50px");

debug("");
debug("Test negative exponent values with 'E'");
test("5000E-2", "50px");
test("500E-1", "50px");
test("+5000E-2", "50px");
test("+500E-1", "50px");
test("+5000.00E-2px", "50px");
test("+500E-1px", "50px");

debug("");
debug("Test negative numbers with exponents");
test("-.5e2px", "-50px");
test("-0.5e2px", "-50px");
test("-500e-1px", "-50px");

debug("");
debug("Test if value and 'em' still works");
test("50em", "800px");

debug("");
debug("Test if value and 'ex' still works");
test("50ex", "640px", 0.01);

debug("");
debug("Trailing and leading whitespaces");
test("       5e1", "50px");
test("5e1      ", "50px");

debug("");
debug("Test behavior on overflow");
test("2E+500", "baseline");
test("-2E+500", "baseline");

debug("");
debug("Invalid values");
test("50e0.0", "baseline");
test("50 e0", "baseline");
test("50e 0", "baseline");
test("50.e0", "baseline");

var successfullyParsed = true;

completeTest();</script>
</body>
</html>