-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
161 lines (131 loc) · 4.57 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<title>Tests for undo-manager</title>
<script type="text/javascript" src="build/build.js"></script>
<script type="text/javascript">
var UndoManager = require("undo-manager");
var manager = new UndoManager;
var obj = {
_foo: 0,
get foo()
{
return this._foo;
},
set foo(foo)
{
manager.registerPropertyUndo(this, "foo", this._foo);
this._foo = foo;
},
setFoo: function(foo)
{
manager.registerMethodUndo(this, this.setFoo, this._foo);
this._foo = foo;
}
};
function test(name, pass)
{
if (pass)
console.log("\tPASS:", name);
else
console.error("\tFAIL:", name);
}
function increment(times)
{
while(times--)
obj.foo++;
}
console.clear();
setTimeout(function() {
console.log("Increment obj.foo 5 times");
increment(5);
test("obj.foo === 5", obj.foo === 5);
console.log("Undo 4 times");
manager.undo();
manager.undo();
manager.undo();
manager.undo();
test("obj.foo === 1", obj.foo === 1);
console.log("Redo 3 times");
manager.redo();
manager.redo();
manager.redo();
test("obj.foo === 4", obj.foo === 4);
console.log("Undo 2 times");
manager.undo();
manager.undo();
test("obj.foo === 2", obj.foo === 2);
console.log("Set obj.foo = 6 to trash redo stack");
obj.foo = 6;
test("obj.foo === 6", obj.foo === 6);
test("manager.canRedo === false", !manager.canRedo);
console.log("Undo once");
manager.undo();
test("obj.foo === 2", obj.foo === 2);
test("manager.canRedo === true", manager.canRedo);
console.log("Redo once");
manager.redo();
test("obj.foo === 6", obj.foo === 6);
test("manager.canRedo === false", !manager.canRedo);
console.log("Increment once")
increment(1);
test("obj.foo === 7", obj.foo === 7);
console.log("Undo once");
manager.undo();
test("obj.foo === 6", obj.foo === 6);
console.log("Redo once");
manager.redo();
test("obj.foo === 7", obj.foo === 7);
console.log("Increment obj.foo 4 times within two nested groups");
manager.beginGroup();
increment(1);
manager.beginGroup();
increment(2);
manager.endGroup();
increment(1);
manager.endGroup();
test("obj.foo === 11", obj.foo === 11);
console.log("Undo once");
manager.undo();
test("obj.foo === 7", obj.foo === 7);
console.log("Redo once");
manager.redo();
test("obj.foo === 11", obj.foo === 11);
console.log("Increment once")
increment(1);
test("obj.foo === 12", obj.foo === 12);
console.log("Undo 4 times");
manager.undo();
manager.undo();
manager.undo();
manager.undo();
test("obj.foo === 2", obj.foo === 2);
console.log("obj.setFoo(20)");
obj.setFoo(20);
test("obj.foo === 20", obj.foo === 20);
console.log("Undo once");
manager.undo();
test("obj.foo === 2", obj.foo === 2);
console.log("Redo once");
manager.redo();
test("obj.foo === 20", obj.foo === 20);
console.log("Increment obj.foo 4 times within two unclosed nested groups");
manager.beginGroup();
increment(2);
manager.beginGroup();
increment(2);
test("obj.foo === 24", obj.foo === 24);
console.log("Undo twice");
manager.undo();
manager.undo();
test("obj.foo === 2", obj.foo === 2);
console.log("Redo twice");
manager.redo();
manager.redo();
test("obj.foo === 24", obj.foo === 24);
});
</script>
</head>
<body>
</body>
</html>