forked from oliver-moran/toSource.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
75 lines (60 loc) · 2.85 KB
/
test.html
File metadata and controls
75 lines (60 loc) · 2.85 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
<script src="toSource.min.js"></script>
<script>
//, Object, Date, RegExp
test( "Number", function() {
ok( (42).toSource() == "(new Number(42))", "Natural" );
ok( (-42).toSource() == "(new Number(-42))", "Negative" );
ok( (4.2).toSource() == "(new Number(4.2))", "Float" );
ok( (4e2).toSource() == "(new Number(400))", "Exponent" );
});
test( "Boolean", function() {
ok( (true).toSource() == "(new Boolean(true))", "true" );
ok( (false).toSource() == "(new Boolean(false))", "false" );
ok( (true == false).toSource() == "(new Boolean(false))", "Comparasion" );
});
test( "String", function() {
ok( ("Hello World").toSource() == "(new String(\"Hello World\"))", "Simple" );
ok( ("Hello \"World\"").toSource() == "(new String(\"Hello \\\"World\\\"\"))", "Quotes" );
});
test( "Function", function() {
function hello(world) {
return "Hello, " + world + "!";
}
ok( hello.toSource() == hello.toString(), "toString()" );
});
test( "Array", function() {
ok( ([1, "2", false, {a: 1, b: 2}]).toSource() == "[1, \"2\", false, {a:1, b:2}]", "Mixed Array" );
var arr = [1, "2", false, {a: 1, b: 2}];
arr.push(arr);
ok( (arr).toSource() == "[1, \"2\", false, {a:1, b:2}, []]", "Cicular Array" );
});
test( "Object", function() {
ok( ({foo: "bar"}).toSource() == "({foo:\"bar\"})", "Valid ID" );
ok( ({"foo:bar": "baz"}).toSource() == "({'foo:bar':\"baz\"})", "Invalid ID" );
ok( ({"foo:bar": "baz", qux: "quux"}).toSource() == "({'foo:bar':\"baz\", qux:\"quux\"})", "Mixed IDs" );
ok( ({"foo": "bar", baz:{ qux: "quux"}}).toSource() == "({foo:\"bar\", baz:{qux:\"quux\"}})", "Nested Objects" );
var obj = {"foo": "bar", baz:{ qux: "quux"}};
obj.baz.obj = obj;
ok( (obj).toSource() == "({foo:\"bar\", baz:{qux:\"quux\", obj:{}}})", "Circular Object" );
});
test( "Date", function() {
var d = new Date();
ok( (d).toSource() == "(new Date(" + d.getTime() + "))", "Current Date()" );
});
test( "RegExp", function() {
ok( (/foo,bar/).toSource() == "/foo,bar/", "/foo,bar/" );
});
</script>
</body>
</html>