resin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/README.markdown +52 -0
  2. data/amber/css/amber.css +519 -0
  3. data/amber/css/documentation.css +84 -0
  4. data/amber/css/profstef.css +75 -0
  5. data/amber/css/style.css +313 -0
  6. data/amber/images/amber.png +0 -0
  7. data/amber/images/amber_small.png +0 -0
  8. data/amber/images/off.png +0 -0
  9. data/amber/images/offHover.png +0 -0
  10. data/amber/images/presentation.png +0 -0
  11. data/amber/images/profstef.png +0 -0
  12. data/amber/images/sprite.png +0 -0
  13. data/amber/images/tinylogo.png +0 -0
  14. data/amber/images/twitterwall.png +0 -0
  15. data/amber/js/Additional-Examples.deploy.js +15 -0
  16. data/amber/js/Additional-Examples.js +21 -0
  17. data/amber/js/Benchfib.deploy.js +132 -0
  18. data/amber/js/Benchfib.js +167 -0
  19. data/amber/js/Canvas.deploy.js +1304 -0
  20. data/amber/js/Canvas.js +1885 -0
  21. data/amber/js/Compiler.deploy.js +1871 -0
  22. data/amber/js/Compiler.js +2616 -0
  23. data/amber/js/Documentation.deploy.js +961 -0
  24. data/amber/js/Documentation.js +1376 -0
  25. data/amber/js/Examples.deploy.js +53 -0
  26. data/amber/js/Examples.js +73 -0
  27. data/amber/js/IDE.deploy.js +3468 -0
  28. data/amber/js/IDE.js +4883 -0
  29. data/amber/js/Kernel-Announcements.deploy.js +107 -0
  30. data/amber/js/Kernel-Announcements.js +152 -0
  31. data/amber/js/Kernel-Classes.deploy.js +675 -0
  32. data/amber/js/Kernel-Classes.js +956 -0
  33. data/amber/js/Kernel-Collections.deploy.js +3273 -0
  34. data/amber/js/Kernel-Collections.js +4644 -0
  35. data/amber/js/Kernel-Exceptions.deploy.js +244 -0
  36. data/amber/js/Kernel-Exceptions.js +349 -0
  37. data/amber/js/Kernel-Methods.deploy.js +510 -0
  38. data/amber/js/Kernel-Methods.js +739 -0
  39. data/amber/js/Kernel-Objects.deploy.js +2698 -0
  40. data/amber/js/Kernel-Objects.js +3858 -0
  41. data/amber/js/Kernel-Tests.deploy.js +1419 -0
  42. data/amber/js/Kernel-Tests.js +1929 -0
  43. data/amber/js/Kernel-Transcript.deploy.js +142 -0
  44. data/amber/js/Kernel-Transcript.js +202 -0
  45. data/amber/js/SUnit.deploy.js +351 -0
  46. data/amber/js/SUnit.js +501 -0
  47. data/amber/js/amber.js +250 -0
  48. data/amber/js/boot.js +587 -0
  49. data/amber/js/compat.js +22 -0
  50. data/amber/js/init.js +8 -0
  51. data/amber/js/lib/CodeMirror/LICENSE +19 -0
  52. data/amber/js/lib/CodeMirror/amber.css +21 -0
  53. data/amber/js/lib/CodeMirror/codemirror.css +67 -0
  54. data/amber/js/lib/CodeMirror/codemirror.js +2144 -0
  55. data/amber/js/lib/CodeMirror/smalltalk.js +134 -0
  56. data/amber/js/lib/jQuery/jquery-1.4.4.min.js +167 -0
  57. data/amber/js/lib/jQuery/jquery-1.6.4.min.js +4 -0
  58. data/amber/js/lib/jQuery/jquery-ui-1.8.16.custom.min.js +791 -0
  59. data/amber/js/lib/jQuery/jquery.textarea.js +267 -0
  60. data/amber/js/lib/peg-0.6.2.min.js +2 -0
  61. data/amber/js/lib/showdown.js +419 -0
  62. data/amber/js/parser.js +4005 -0
  63. data/amber/js/parser.pegjs +220 -0
  64. data/amber/st/Benchfib.st +124 -0
  65. data/amber/st/Canvas.st +556 -0
  66. data/amber/st/Compiler.st +1425 -0
  67. data/amber/st/Documentation.st +758 -0
  68. data/amber/st/Examples.st +38 -0
  69. data/amber/st/IDE.st +2336 -0
  70. data/amber/st/Kernel-Announcements.st +61 -0
  71. data/amber/st/Kernel-Classes.st +403 -0
  72. data/amber/st/Kernel-Collections.st +1673 -0
  73. data/amber/st/Kernel-Exceptions.st +124 -0
  74. data/amber/st/Kernel-Methods.st +287 -0
  75. data/amber/st/Kernel-Objects.st +1489 -0
  76. data/amber/st/Kernel-Tests.st +892 -0
  77. data/amber/st/Kernel-Transcript.st +70 -0
  78. data/amber/st/SUnit.st +172 -0
  79. data/bin/runresin +12 -0
  80. data/lib/resin.rb +0 -0
  81. data/lib/resin/app/app.rb +121 -0
  82. data/lib/resin/app/views/index.haml +10 -0
  83. metadata +216 -0
@@ -0,0 +1,892 @@
1
+ Smalltalk current createPackage: 'Kernel-Tests' properties: #{}!
2
+ TestCase subclass: #StringTest
3
+ instanceVariableNames: ''
4
+ category: 'Kernel-Tests'!
5
+
6
+ !StringTest methodsFor: 'tests'!
7
+
8
+ testJoin
9
+ self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
10
+ !
11
+
12
+ testStreamContents
13
+ self
14
+ assert: 'hello world'
15
+ equals: (String streamContents: [:aStream| aStream
16
+ nextPutAll: 'hello'; space;
17
+ nextPutAll: 'world'])
18
+ !
19
+
20
+ testIncludesSubString
21
+ self assert: ('amber' includesSubString: 'ber').
22
+ self deny: ('amber' includesSubString: 'zork').
23
+ !
24
+
25
+ testEquality
26
+ self assert: 'hello' = 'hello'.
27
+ self deny: 'hello' = 'world'.
28
+
29
+ self assert: 'hello' = 'hello' yourself.
30
+ self assert: 'hello' yourself = 'hello'.
31
+
32
+ "test JS falsy value"
33
+ self deny: '' = 0
34
+ !
35
+
36
+ testCopyWithoutAll
37
+ self
38
+ assert: 'hello world'
39
+ equals: ('*hello* *world*' copyWithoutAll: '*')
40
+ !
41
+
42
+ testAt
43
+ self assert: ('hello' at: 1) = 'h'.
44
+ self assert: ('hello' at: 5) = 'o'.
45
+ self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
46
+ !
47
+
48
+ testAtPut
49
+ "String instances are read-only"
50
+ self should: ['hello' at: 1 put: 'a'] raise: Error
51
+ !
52
+
53
+ testSize
54
+ self assert: 'smalltalk' size equals: 9.
55
+ self assert: '' size equals: 0
56
+ !
57
+
58
+ testAddRemove
59
+ self should: ['hello' add: 'a'] raise: Error.
60
+ self should: ['hello' remove: 'h'] raise: Error
61
+ ! !
62
+
63
+ TestCase subclass: #DictionaryTest
64
+ instanceVariableNames: ''
65
+ category: 'Kernel-Tests'!
66
+
67
+ !DictionaryTest methodsFor: 'tests'!
68
+
69
+ testPrintString
70
+ self
71
+ assert: 'a Dictionary(''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
72
+ equals: (Dictionary new
73
+ at:'firstname' put: 'James';
74
+ at:'lastname' put: 'Bond';
75
+ printString)
76
+ !
77
+
78
+ testEquality
79
+ | d1 d2 |
80
+
81
+ self assert: Dictionary new = Dictionary new.
82
+
83
+ d1 := Dictionary new at: 1 put: 2; yourself.
84
+ d2 := Dictionary new at: 1 put: 2; yourself.
85
+ self assert: d1 = d2.
86
+
87
+ d2 := Dictionary new at: 1 put: 3; yourself.
88
+ self deny: d1 = d2.
89
+
90
+ d2 := Dictionary new at: 2 put: 2; yourself.
91
+ self deny: d1 = d2.
92
+
93
+ d2 := Dictionary new at: 1 put: 2; at: 3 put: 4; yourself.
94
+ self deny: d1 = d2.
95
+ !
96
+
97
+ testDynamicDictionaries
98
+ self assert: #{'hello' -> 1} asDictionary = (Dictionary with: 'hello' -> 1)
99
+ !
100
+
101
+ testAccessing
102
+ | d |
103
+
104
+ d := Dictionary new.
105
+
106
+ d at: 'hello' put: 'world'.
107
+ self assert: (d at: 'hello') = 'world'.
108
+ self assert: (d at: 'hello' ifAbsent: [nil]) = 'world'.
109
+ self deny: (d at: 'foo' ifAbsent: [nil]) = 'world'.
110
+
111
+ d at: 1 put: 2.
112
+ self assert: (d at: 1) = 2.
113
+
114
+ d at: 1@3 put: 3.
115
+ self assert: (d at: 1@3) = 3
116
+ !
117
+
118
+ testSize
119
+ | d |
120
+
121
+ d := Dictionary new.
122
+ self assert: d size = 0.
123
+
124
+ d at: 1 put: 2.
125
+ self assert: d size = 1.
126
+
127
+ d at: 2 put: 3.
128
+ self assert: d size = 2.
129
+ !
130
+
131
+ testValues
132
+ | d |
133
+
134
+ d := Dictionary new.
135
+ d at: 1 put: 2.
136
+ d at: 2 put: 3.
137
+ d at: 3 put: 4.
138
+
139
+ self assert: d values = #(2 3 4)
140
+ !
141
+
142
+ testKeys
143
+ | d |
144
+
145
+ d := Dictionary new.
146
+ d at: 1 put: 2.
147
+ d at: 2 put: 3.
148
+ d at: 3 put: 4.
149
+
150
+ self assert: d keys = #(1 2 3)
151
+ ! !
152
+
153
+ TestCase subclass: #BooleanTest
154
+ instanceVariableNames: ''
155
+ category: 'Kernel-Tests'!
156
+
157
+ !BooleanTest methodsFor: 'tests'!
158
+
159
+ testLogic
160
+
161
+ "Trivial logic table"
162
+ self assert: (true & true); deny: (true & false); deny: (false & true); deny: (false & false).
163
+ self assert: (true | true); assert: (true | false); assert: (false | true); deny: (false | false).
164
+ "Checking that expressions work fine too"
165
+ self assert: (true & (1 > 0)); deny: ((1 > 0) & false); deny: ((1 > 0) & (1 > 2)).
166
+ self assert: (false | (1 > 0)); assert: ((1 > 0) | false); assert: ((1 > 0) | (1 > 2))
167
+ !
168
+
169
+ testEquality
170
+ "We're on top of JS...just be sure to check the basics!!"
171
+
172
+ self deny: 0 = false.
173
+ self deny: false = 0.
174
+ self deny: '' = false.
175
+ self deny: false = ''.
176
+
177
+ self assert: true = true.
178
+ self deny: false = true.
179
+ self deny: true = false.
180
+ self assert: false = false.
181
+
182
+ "JS may do some type coercing after sending a message"
183
+ self assert: true yourself = true.
184
+ self assert: true yourself = true yourself
185
+ !
186
+
187
+ testLogicKeywords
188
+
189
+ "Trivial logic table"
190
+ self
191
+ assert: (true and: [ true]);
192
+ deny: (true and: [ false ]);
193
+ deny: (false and: [ true ]);
194
+ deny: (false and: [ false ]).
195
+ self
196
+ assert: (true or: [ true ]);
197
+ assert: (true or: [ false ]);
198
+ assert: (false or: [ true ]);
199
+ deny: (false or: [ false ]).
200
+
201
+ "Checking that expressions work fine too"
202
+ self
203
+ assert: (true and: [ 1 > 0 ]);
204
+ deny: ((1 > 0) and: [ false ]);
205
+ deny: ((1 > 0) and: [ 1 > 2 ]).
206
+ self
207
+ assert: (false or: [ 1 > 0 ]);
208
+ assert: ((1 > 0) or: [ false ]);
209
+ assert: ((1 > 0) or: [ 1 > 2 ])
210
+ !
211
+
212
+ testIfTrueIfFalse
213
+
214
+ self assert: (true ifTrue: ['alternative block']) = 'alternative block'.
215
+ self assert: (true ifFalse: ['alternative block']) = nil.
216
+
217
+ self assert: (false ifTrue: ['alternative block']) = nil.
218
+ self assert: (false ifFalse: ['alternative block']) = 'alternative block'.
219
+
220
+ self assert: (false ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
221
+ self assert: (false ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
222
+
223
+ self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
224
+ self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
225
+ ! !
226
+
227
+ TestCase subclass: #NumberTest
228
+ instanceVariableNames: ''
229
+ category: 'Kernel-Tests'!
230
+
231
+ !NumberTest methodsFor: 'tests'!
232
+
233
+ testPrintShowingDecimalPlaces
234
+ self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
235
+ self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
236
+ self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
237
+ self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
238
+ self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
239
+ self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
240
+ self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
241
+ self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
242
+ self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
243
+ self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
244
+ self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
245
+ self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
246
+ self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
247
+ !
248
+
249
+ testEquality
250
+ self assert: 1 = 1.
251
+ self assert: 0 = 0.
252
+ self deny: 1 = 0.
253
+
254
+ self assert: 1 yourself = 1.
255
+ self assert: 1 = 1 yourself.
256
+ self assert: 1 yourself = 1 yourself.
257
+
258
+ self deny: 0 = false.
259
+ self deny: false = 0.
260
+ self deny: '' = 0.
261
+ self deny: 0 = ''
262
+ !
263
+
264
+ testArithmetic
265
+
266
+ "We rely on JS here, so we won't test complex behavior, just check if
267
+ message sends are corrects"
268
+
269
+ self assert: 1.5 + 1 = 2.5.
270
+ self assert: 2 - 1 = 1.
271
+ self assert: -2 - 1 = -3.
272
+ self assert: 12 / 2 = 6.
273
+ self assert: 3 * 4 = 12.
274
+
275
+ "Simple parenthesis and execution order"
276
+
277
+ self assert: 1 + 2 * 3 = 9.
278
+ self assert: 1 + (2 * 3) = 7
279
+ !
280
+
281
+ testRounded
282
+
283
+ self assert: 3 rounded = 3.
284
+ self assert: 3.212 rounded = 3.
285
+ self assert: 3.51 rounded = 4
286
+ !
287
+
288
+ testNegated
289
+ self assert: 3 negated = -3.
290
+ self assert: -3 negated = 3
291
+ !
292
+
293
+ testComparison
294
+
295
+ self assert: 3 > 2.
296
+ self assert: 2 < 3.
297
+
298
+ self deny: 3 < 2.
299
+ self deny: 2 > 3.
300
+
301
+ self assert: 3 >= 3.
302
+ self assert: 3.1 >= 3.
303
+ self assert: 3 <= 3.
304
+ self assert: 3 <= 3.1
305
+ !
306
+
307
+ testTruncated
308
+
309
+ self assert: 3 truncated = 3.
310
+ self assert: 3.212 truncated = 3.
311
+ self assert: 3.51 truncated = 3
312
+ !
313
+
314
+ testCopying
315
+ self assert: 1 copy == 1.
316
+ self assert: 1 deepCopy == 1
317
+ !
318
+
319
+ testMinMax
320
+
321
+ self assert: (2 max: 5) equals: 5.
322
+ self assert: (2 min: 5) equals: 2
323
+ !
324
+
325
+ testIdentity
326
+ self assert: 1 == 1.
327
+ self assert: 0 == 0.
328
+ self deny: 1 == 0.
329
+
330
+ self assert: 1 yourself == 1.
331
+ self assert: 1 == 1 yourself.
332
+ self assert: 1 yourself == 1 yourself.
333
+
334
+ self deny: 1 == 2
335
+ !
336
+
337
+ testSqrt
338
+
339
+ self assert: 4 sqrt = 2.
340
+ self assert: 16 sqrt = 4
341
+ !
342
+
343
+ testSquared
344
+
345
+ self assert: 4 squared = 16
346
+ !
347
+
348
+ testTimesRepeat
349
+ | i |
350
+
351
+ i := 0.
352
+ 0 timesRepeat: [i := i + 1].
353
+ self assert: i equals: 0.
354
+
355
+ 5 timesRepeat: [i := i + 1].
356
+ self assert: i equals: 5
357
+ !
358
+
359
+ testTo
360
+ self assert: (1 to: 5) equals: #(1 2 3 4 5)
361
+ !
362
+
363
+ testToBy
364
+ self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
365
+
366
+ self should: [1 to: 4 by: 0] raise: Error
367
+ ! !
368
+
369
+ TestCase subclass: #JSObjectProxyTest
370
+ instanceVariableNames: ''
371
+ category: 'Kernel-Tests'!
372
+
373
+ !JSObjectProxyTest methodsFor: 'accessing'!
374
+
375
+ jsObject
376
+ <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}}>
377
+ ! !
378
+
379
+ !JSObjectProxyTest methodsFor: 'tests'!
380
+
381
+ testMethodWithArguments
382
+ self deny: ('body' asJQuery hasClass: 'amber').
383
+
384
+ 'body' asJQuery addClass: 'amber'.
385
+ self assert: ('body' asJQuery hasClass: 'amber').
386
+
387
+ 'body' asJQuery removeClass: 'amber'.
388
+ self deny: ('body' asJQuery hasClass: 'amber').
389
+ !
390
+
391
+ testYourself
392
+ |body|
393
+ body := 'body' asJQuery
394
+ addClass: 'amber';
395
+ yourself.
396
+
397
+ self assert: (body hasClass: 'amber').
398
+
399
+ body removeClass: 'amber'.
400
+ self deny: (body hasClass: 'amber').
401
+ !
402
+
403
+ testPropertyThatReturnsEmptyString
404
+ <document.location.hash = ''>.
405
+ self assert: '' equals: document location hash.
406
+
407
+ document location hash: 'test'.
408
+ self assert: '#test' equals: document location hash.
409
+ !
410
+
411
+ testDNU
412
+ self should: [self jsObject foo] raise: MessageNotUnderstood
413
+ !
414
+
415
+ testMessageSend
416
+
417
+ self assert: self jsObject a equals: 1.
418
+ self assert: self jsObject b equals: 2.
419
+ self assert: (self jsObject c: 3) equals: 3
420
+ !
421
+
422
+ testPrinting
423
+ self assert: self jsObject printString = '[object Object]'
424
+ ! !
425
+
426
+ TestCase subclass: #PackageTest
427
+ instanceVariableNames: 'zorkPackage grulPackage backUpCommitPathJs backUpCommitPathSt'
428
+ category: 'Kernel-Tests'!
429
+
430
+ !PackageTest methodsFor: 'running'!
431
+
432
+ setUp
433
+ backUpCommitPathJs := Package defaultCommitPathJs.
434
+ backUpCommitPathSt := Package defaultCommitPathSt.
435
+
436
+ Package resetCommitPaths.
437
+
438
+ zorkPackage := Package new name: 'Zork'.
439
+ grulPackage := Package new
440
+ name: 'Grul';
441
+ commitPathJs: 'server/grul/js';
442
+ commitPathSt: 'grul/st';
443
+ yourself
444
+ !
445
+
446
+ tearDown
447
+ Package
448
+ defaultCommitPathJs: backUpCommitPathJs;
449
+ defaultCommitPathSt: backUpCommitPathSt
450
+ ! !
451
+
452
+ !PackageTest methodsFor: 'tests'!
453
+
454
+ testGrulCommitPathStShouldBeGrulSt
455
+ self assert: 'grul/st' equals: grulPackage commitPathSt
456
+ !
457
+
458
+ testZorkCommitPathStShouldBeSt
459
+ self assert: 'st' equals: zorkPackage commitPathSt
460
+ !
461
+
462
+ testZorkCommitPathJsShouldBeJs
463
+ self assert: 'js' equals: zorkPackage commitPathJs
464
+ !
465
+
466
+ testGrulCommitPathJsShouldBeServerGrulJs
467
+ self assert: 'server/grul/js' equals: grulPackage commitPathJs
468
+ ! !
469
+
470
+ PackageTest subclass: #PackageWithDefaultCommitPathChangedTest
471
+ instanceVariableNames: ''
472
+ category: 'Kernel-Tests'!
473
+
474
+ !PackageWithDefaultCommitPathChangedTest methodsFor: 'running'!
475
+
476
+ setUp
477
+ super setUp.
478
+
479
+ Package
480
+ defaultCommitPathJs: 'javascripts/';
481
+ defaultCommitPathSt: 'smalltalk/'.
482
+ ! !
483
+
484
+ !PackageWithDefaultCommitPathChangedTest methodsFor: 'tests'!
485
+
486
+ testGrulCommitPathJsShouldBeServerGrulJs
487
+ self assert: 'server/grul/js' equals: grulPackage commitPathJs
488
+ !
489
+
490
+ testGrulCommitPathStShouldBeGrulSt
491
+ self assert: 'grul/st' equals: grulPackage commitPathSt
492
+ !
493
+
494
+ testZorkCommitPathJsShouldBeJavascript
495
+ self assert: 'javascripts/' equals: zorkPackage commitPathJs
496
+ !
497
+
498
+ testZorkCommitPathStShouldBeSmalltalk
499
+ self assert: 'smalltalk/' equals: zorkPackage commitPathSt
500
+ ! !
501
+
502
+ !PackageWithDefaultCommitPathChangedTest class methodsFor: 'accessing'!
503
+
504
+ shouldInheritSelectors
505
+ ^ false
506
+ ! !
507
+
508
+ TestCase subclass: #BlockClosureTest
509
+ instanceVariableNames: ''
510
+ category: 'Kernel-Tests'!
511
+
512
+ !BlockClosureTest methodsFor: 'tests'!
513
+
514
+ testValue
515
+ self assert: ([1+1] value) equals: 2.
516
+ self assert: ([:x | x +1] value: 2) equals: 3.
517
+ self assert: ([:x :y | x*y] value: 2 value: 4) equals: 8.
518
+
519
+ "Arguments are optional in Amber. This isn't ANSI compliant."
520
+
521
+ self assert: ([:a :b :c | 1] value) equals: 1
522
+ !
523
+
524
+ testOnDo
525
+ self assert: ([Error new signal] on: Error do: [:ex | true])
526
+ !
527
+
528
+ testEnsure
529
+ self assert: ([Error new] ensure: [true])
530
+ !
531
+
532
+ testNumArgs
533
+ self assert: [] numArgs equals: 0.
534
+ self assert: [:a :b | ] numArgs equals: 2
535
+ !
536
+
537
+ testValueWithPossibleArguments
538
+ self assert: ([1] valueWithPossibleArguments: #(3 4)) equals: 1.
539
+ self assert: ([:a | a + 4] valueWithPossibleArguments: #(3 4)) equals: 7.
540
+ self assert: ([:a :b | a + b] valueWithPossibleArguments: #(3 4 5)) equals: 7.
541
+ !
542
+
543
+ testWhileTrue
544
+ | i |
545
+ i := 0.
546
+ [i < 5] whileTrue: [i := i + 1].
547
+ self assert: i equals: 5.
548
+
549
+ i := 0.
550
+ [i := i + 1. i < 5] whileTrue.
551
+ self assert: i equals: 5
552
+ !
553
+
554
+ testWhileFalse
555
+ | i |
556
+ i := 0.
557
+ [i > 5] whileFalse: [i := i + 1].
558
+ self assert: i equals: 6.
559
+
560
+ i := 0.
561
+ [i := i + 1. i > 5] whileFalse.
562
+ self assert: i equals: 6
563
+ !
564
+
565
+ testCompiledSource
566
+ self assert: ([1+1] compiledSource includesSubString: 'function')
567
+ ! !
568
+
569
+ TestCase subclass: #ObjectTest
570
+ instanceVariableNames: ''
571
+ category: 'Kernel-Tests'!
572
+
573
+ !ObjectTest methodsFor: 'tests'!
574
+
575
+ testEquality
576
+ | o |
577
+ o := Object new.
578
+ self deny: o = Object new.
579
+ self assert: o = o.
580
+ self assert: o yourself = o.
581
+ self assert: o = o yourself
582
+ !
583
+
584
+ testIdentity
585
+ | o |
586
+ o := Object new.
587
+ self deny: o == Object new.
588
+ self assert: o == o
589
+ !
590
+
591
+ testHalt
592
+ self should: [Object new halt] raise: Error
593
+ !
594
+
595
+ testBasicAccess
596
+ | o |
597
+ o := Object new.
598
+ o basicAt: 'a' put: 1.
599
+ self assert: (o basicAt: 'a') equals: 1.
600
+ self assert: (o basicAt: 'b') equals: nil
601
+ !
602
+
603
+ testNilUndefined
604
+ "nil in Smalltalk is the undefined object in JS"
605
+
606
+ self assert: nil = undefined
607
+ !
608
+
609
+ testidentityHash
610
+ | o1 o2 |
611
+
612
+ o1 := Object new.
613
+ o2 := Object new.
614
+
615
+ self assert: o1 identityHash == o1 identityHash.
616
+ self deny: o1 identityHash == o2 identityHash
617
+ !
618
+
619
+ testBasicPerform
620
+ | o |
621
+ o := Object new.
622
+ o basicAt: 'func' put: ['hello'].
623
+ o basicAt: 'func2' put: [:a | a + 1].
624
+
625
+ self assert: (o basicPerform: 'func') equals: 'hello'.
626
+ self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
627
+ !
628
+
629
+ testIfNil
630
+ self deny: Object new isNil.
631
+ self deny: (Object new ifNil: [true]) = true.
632
+ self assert: (Object new ifNotNil: [true]) = true.
633
+
634
+ self assert: (Object new ifNil: [false] ifNotNil: [true]) = true.
635
+ self assert: (Object new ifNotNil: [true] ifNil: [false]) = true
636
+ !
637
+
638
+ testInstVars
639
+ | o |
640
+ o := ObjectMock new.
641
+ self assert: (o instVarAt: #foo) equals: nil.
642
+
643
+ o instVarAt: #foo put: 1.
644
+ self assert: (o instVarAt: #foo) equals: 1.
645
+ self assert: (o instVarAt: 'foo') equals: 1
646
+ !
647
+
648
+ testYourself
649
+ | o |
650
+ o := ObjectMock new.
651
+ self assert: o yourself == o
652
+ !
653
+
654
+ testDNU
655
+ self should: [Object new foo] raise: MessageNotUnderstood
656
+ ! !
657
+
658
+ TestCase subclass: #SymbolTest
659
+ instanceVariableNames: ''
660
+ category: 'Kernel-Tests'!
661
+
662
+ !SymbolTest methodsFor: 'tests'!
663
+
664
+ testEquality
665
+ self assert: #hello = #hello.
666
+ self deny: #hello = #world.
667
+
668
+ self assert: #hello = #hello yourself.
669
+ self assert: #hello yourself = #hello.
670
+
671
+ self deny: #hello = 'hello'.
672
+ self deny: 'hello' = #hello.
673
+ !
674
+
675
+ testAt
676
+ self assert: (#hello at: 1) = 'h'.
677
+ self assert: (#hello at: 5) = 'o'.
678
+ self assert: (#hello at: 6 ifAbsent: [nil]) = nil
679
+ !
680
+
681
+ testAtPut
682
+ "Symbol instances are read-only"
683
+ self should: ['hello' at: 1 put: 'a'] raise: Error
684
+ !
685
+
686
+ testIdentity
687
+ self assert: #hello == #hello.
688
+ self deny: #hello == #world.
689
+
690
+ self assert: #hello = #hello yourself.
691
+ self assert: #hello yourself = #hello asString asSymbol
692
+ !
693
+
694
+ testComparing
695
+ self assert: #ab > #aa.
696
+ self deny: #ab > #ba.
697
+
698
+ self assert: #ab < #ba.
699
+ self deny: #bb < #ba.
700
+
701
+ self assert: #ab >= #aa.
702
+ self deny: #ab >= #ba.
703
+
704
+ self assert: #ab <= #ba.
705
+ self deny: #bb <= #ba
706
+ !
707
+
708
+ testSize
709
+ self assert: #a size equals: 1.
710
+ self assert: #aaaaa size equals: 5
711
+ !
712
+
713
+ testAsString
714
+ self assert: #hello asString equals: 'hello'
715
+ !
716
+
717
+ testAsSymbol
718
+ self assert: #hello == #hello asSymbol
719
+ !
720
+
721
+ testCopying
722
+ self assert: #hello copy == #hello.
723
+ self assert: #hello deepCopy == #hello
724
+ !
725
+
726
+ testIsSymbolIsString
727
+ self assert: #hello isSymbol.
728
+ self deny: 'hello' isSymbol.
729
+ self deny: #hello isString.
730
+ self assert: 'hello' isString
731
+ ! !
732
+
733
+ Object subclass: #ObjectMock
734
+ instanceVariableNames: 'foo bar'
735
+ category: 'Kernel-Tests'!
736
+
737
+ !ObjectMock methodsFor: 'not yet classified'!
738
+
739
+ foo
740
+ ^foo
741
+ !
742
+
743
+ foo: anObject
744
+ foo := anObject
745
+ ! !
746
+
747
+ TestCase subclass: #UndefinedTest
748
+ instanceVariableNames: ''
749
+ category: 'Kernel-Tests'!
750
+
751
+ !UndefinedTest methodsFor: 'tests'!
752
+
753
+ testIsNil
754
+ self assert: nil isNil.
755
+ self deny: nil notNil.
756
+ !
757
+
758
+ testIfNil
759
+ self assert: (nil ifNil: [true]) equals: true.
760
+ self deny: (nil ifNotNil: [true]) = true.
761
+ self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
762
+ self deny: (nil ifNotNil: [true] ifNil: [false]) = true
763
+ !
764
+
765
+ testCopying
766
+ self assert: nil copy equals: nil
767
+ !
768
+
769
+ testDeepCopy
770
+ self assert: nil deepCopy = nil
771
+ ! !
772
+
773
+ TestCase subclass: #PointTest
774
+ instanceVariableNames: ''
775
+ category: 'Kernel-Tests'!
776
+
777
+ !PointTest methodsFor: 'tests'!
778
+
779
+ testAccessing
780
+ self assert: (Point x: 3 y: 4) x equals: 3.
781
+ self assert: (Point x: 3 y: 4) y equals: 4.
782
+ self assert: (Point new x: 3) x equals: 3.
783
+ self assert: (Point new y: 4) y equals: 4
784
+ !
785
+
786
+ testAt
787
+ self assert: 3@4 equals: (Point x: 3 y: 4)
788
+ !
789
+
790
+ testEgality
791
+ self assert: 3@4 = (3@4).
792
+ self deny: 3@5 = (3@6)
793
+ !
794
+
795
+ testArithmetic
796
+ self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
797
+ self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
798
+ self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
799
+ self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
800
+ ! !
801
+
802
+ TestCase subclass: #RandomTest
803
+ instanceVariableNames: ''
804
+ category: 'Kernel-Tests'!
805
+
806
+ !RandomTest methodsFor: 'tests'!
807
+
808
+ textNext
809
+
810
+ 10000 timesRepeat: [
811
+ | current next |
812
+ next := Random new next.
813
+ self assert: (next >= 0).
814
+ self assert: (next < 1).
815
+ self deny: current = next.
816
+ next = current]
817
+ ! !
818
+
819
+ TestCase subclass: #ClassBuilderTest
820
+ instanceVariableNames: 'builder theClass'
821
+ category: 'Kernel-Tests'!
822
+
823
+ !ClassBuilderTest methodsFor: 'running'!
824
+
825
+ setUp
826
+ builder := ClassBuilder new
827
+ !
828
+
829
+ tearDown
830
+ theClass ifNotNil: [Smalltalk current removeClass: theClass. theClass := nil]
831
+ !
832
+
833
+ testClassCopy
834
+ theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
835
+ self assert: theClass superclass == ObjectMock superclass.
836
+ self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
837
+ self assert: theClass name equals: 'ObjectMock2'.
838
+ self assert: theClass package == ObjectMock package.
839
+ self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
840
+ !
841
+
842
+ testInstanceVariableNames
843
+ self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
844
+ ! !
845
+
846
+ TestCase subclass: #SetTest
847
+ instanceVariableNames: ''
848
+ category: 'Kernel-Tests'!
849
+
850
+ !SetTest methodsFor: 'tests'!
851
+
852
+ testUnicity
853
+ | set |
854
+ set := Set new.
855
+ set add: 21.
856
+ set add: 'hello'.
857
+
858
+ set add: 21.
859
+ self assert: set size = 2.
860
+
861
+ set add: 'hello'.
862
+ self assert: set size = 2.
863
+
864
+ self assert: set asArray equals: #(21 'hello')
865
+ !
866
+
867
+ testAt
868
+ self should: [Set new at: 1 put: 2] raise: Error
869
+ !
870
+
871
+ testAddRemove
872
+ | set |
873
+ set := Set new.
874
+
875
+ self assert: set isEmpty.
876
+
877
+ set add: 3.
878
+ self assert: (set includes: 3).
879
+
880
+ set add: 5.
881
+ self assert: (set includes: 5).
882
+
883
+ set remove: 3.
884
+ self deny: (set includes: 3)
885
+ !
886
+
887
+ testSize
888
+ self assert: Set new size equals: 0.
889
+ self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
890
+ self assert: (Set withAll: #(1 1 1 1)) size equals: 1
891
+ ! !
892
+