-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.html
103 lines (92 loc) · 3.11 KB
/
test.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html>
<head>
</head>
<body>
<h1>JQuery Regex Mask Test</h1>
<form method="post" action="">
<input type="text" name="test1" id="test1" class="float" />
<input type="text" name="test2" id="test2" class="float" />
</form>
<script language="javascript" src="jquery-1.4.4.js"></script>
<script language="javascript" src="jquery-simulate.js"></script>
<script language="javascript" src="regex-mask-plugin.js"></script>
<script>
$('#test1').val('');
try {
$('#test1').regexMask();
document.write('not ok 1 - fails without the regex arg<br />');
} catch(e) {
document.write('ok 1 - fails without the regex arg<br />');
}
try {
$('#test1').regexMask('unknown');
document.write('not ok 2 - fails with an unknown string<br />');
} catch(e) {
document.write('ok 2 - fails with an unknown string<br />');
}
try {
$('#test1').regexMask(/^((\d{1,3}(\.\d{3})*(((\.\d{0,2}))|((,\d*)?)))|(\d+(,\d*)?))$/);
document.write('ok 3 - accepts a regex arg<br />');
} catch(e) {
document.write('not ok 3 - accepts a regex arg: '+e+'<br />');
}
function simulation_tests(tests, offset, id) {
for (var i = 0; i < tests.length; i++) {
if (tests[i].length > 2) {
$(id)[0].selectionStart = tests[i][2];
$(id)[0].selectionEnd = tests[i][2];
}
$(id).simulate('keypress',{ charCode: String.charCodeAt(tests[i][0]) });
if ($(id).val() == tests[i][1]) {
document.write('ok '+(offset+i)+' - simulate keypress<br />');
} else {
document.write('not ok '+(offset+i)+' - simulate keypress<br />');
}
}
}
var tests = [
[ "1", "1" ],
[ ".", "1." ],
[ "2", "1.2" ],
[ ".", "1.2" ],
[ ",", "1.2" ],
[ ".", "1.2" ],
[ "3", "1.23" ],
[ "4", "1.234" ],
[ ".", "1.234", 3 ],
[ ",", "1.234,", 6 ],
[ "0", "1.234,0" ],
[ ".", "1.234,0" ],
[ ",", "1.234,0" ]
];
simulation_tests(tests, 4, '#test1');
try {
$('#test1').val('');
$('#test1').regexMask('float-ptbr');
document.write('ok 17 - supports named mask<br />');
} catch(e) {
document.write('not ok 17 - fails with a named mask<br />');
}
simulation_tests(tests, 18, '#test1');
try {
$('#test2').val('');
$('#test2').regexMask('float-enus');
document.write('ok 31 - supports named mask<br />');
} catch(e) {
document.write('not ok 31 - fails with a named mask<br />');
}
tests = [
[ "1", "1" ],
[ ",", "1," ],
[ "2", "1,2" ],
[ ".", "1,2" ],
[ ",", "1,2" ],
[ "3", "1,23" ],
[ "4", "1,234" ],
[ ".", "1,234." ],
[ "0", "1,234.0" ],
];
simulation_tests(tests, 32, '#test2');
</script>
</body>
</html>