1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Form input type=number</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/#password-state-(type=number)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var numbers = [
{value: "", expected: "", testname: "empty value"},
{value: "11", expected: "11", testname: "value = 11"},
{value: "11.12", expected: "11.12", testname: "value = 11.12"},
{value: "-11111", expected: "-11111", testname: "value = -11111"},
{value: "-11111.123", expected: "-11111.123", testname: "value = -11111.123"},
{value: "1e2", expected: "1e2", testname: "value = 1e2"},
{value: "1E2", expected: "1E2", testname: "value = 1E2"},
{value: "1e+2", expected: "1e+2", testname: "value = 1e+2"},
{value: "1e-2", expected: "1e-2", testname: "value = 1e-2"},
{value: "1d+2", expected: "", testname: "value is not a valid floating-point number: 1d+2"},
{value: "foobar", expected: "", testname: "value not a valid floating-point number: random string"},
{value: "11", attributes: { min: "10" }, expected: "11", testname: "Value >= min attribute"},
{value: "9", attributes: { min: "10" }, expected: "9", testname: "Value < min attribute"},
{value: "19", attributes: { max: "20" }, expected: "19", testname: "Value <= max attribute"},
{value: "21", attributes: { max: "20" }, expected: "21", testname: "Value > max attribute"},
{value: ".1", expected: ".1", testname: "value with a leading '.'"},
{value: "1.", expected: "", testname: "value ending with '.'"},
{value: "-0", expected: "-0", testname: "value = -0"},
{value: "Infinity", expected: "", testname: " value = Infinity"},
{value: "-Infinity", expected: "", testname: "value = -Infinity"},
{value: "NaN", expected: "", testname: "value = NaN"},
{value: "9007199254740993", expected: "9007199254740992", testname: "value = 2^53+1"},
{value: "2e308", expected: "", testname: "value >= Number.MAX_VALUE"},
{value: "1e", expected: "", testname: "value = 1e"},
{value: "+1", expected: "1", testname: "value = +1"},
{value: "+", expected: "", testname: "value = '+'"},
{value: "-", expected: "", testname: "value = '-'"},
{value: " 1", expected: "1", testname: "value with a leading whitespace"},
{value: "1trailing junk", expected: "1", testname: "value = 1trailing junk"}
];
for (var i = 0; i < numbers.length; i++) {
var w = numbers[i];
test(function() {
var input = document.createElement("input");
input.type = "number";
input.value = w.value;
for(var attr in w.attributes) {
input[attr] = w.attributes[attr];
}
assert_equals(input.value, w.expected);
}, w.testname);
}
</script>
|