Kernel-Tests.st 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. Smalltalk current createPackage: 'Kernel-Tests' properties: #{}!
  2. TestCase subclass: #BlockClosureTest
  3. instanceVariableNames: ''
  4. package: 'Kernel-Tests'!
  5. !BlockClosureTest methodsFor: 'tests'!
  6. testCanClearInterval
  7. self shouldnt: [([Error new signal] valueWithInterval: 0) clearInterval] raise: Error
  8. !
  9. testCanClearTimeout
  10. self shouldnt: [([Error new signal] valueWithTimeout: 0) clearTimeout] raise: Error
  11. !
  12. testCompiledSource
  13. self assert: ([1+1] compiledSource includesSubString: 'function')
  14. !
  15. testEnsure
  16. self assert: 3 equals: ([3] ensure: [4])
  17. !
  18. testEnsureRaises
  19. self should: [[Error new signal] ensure: [true]] raise: Error
  20. !
  21. testNumArgs
  22. self assert: [] numArgs equals: 0.
  23. self assert: [:a :b | ] numArgs equals: 2
  24. !
  25. testOnDo
  26. self assert: ([Error new signal] on: Error do: [:ex | true])
  27. !
  28. testValue
  29. self assert: ([1+1] value) equals: 2.
  30. self assert: ([:x | x +1] value: 2) equals: 3.
  31. self assert: ([:x :y | x*y] value: 2 value: 4) equals: 8.
  32. "Arguments are optional in Amber. This isn't ANSI compliant."
  33. self assert: ([:a :b :c | 1] value) equals: 1
  34. !
  35. testValueWithPossibleArguments
  36. self assert: ([1] valueWithPossibleArguments: #(3 4)) equals: 1.
  37. self assert: ([:a | a + 4] valueWithPossibleArguments: #(3 4)) equals: 7.
  38. self assert: ([:a :b | a + b] valueWithPossibleArguments: #(3 4 5)) equals: 7.
  39. !
  40. testWhileFalse
  41. | i |
  42. i := 0.
  43. [i > 5] whileFalse: [i := i + 1].
  44. self assert: i equals: 6.
  45. i := 0.
  46. [i := i + 1. i > 5] whileFalse.
  47. self assert: i equals: 6
  48. !
  49. testWhileTrue
  50. | i |
  51. i := 0.
  52. [i < 5] whileTrue: [i := i + 1].
  53. self assert: i equals: 5.
  54. i := 0.
  55. [i := i + 1. i < 5] whileTrue.
  56. self assert: i equals: 5
  57. ! !
  58. TestCase subclass: #BooleanTest
  59. instanceVariableNames: ''
  60. package: 'Kernel-Tests'!
  61. !BooleanTest methodsFor: 'tests'!
  62. testEquality
  63. "We're on top of JS...just be sure to check the basics!!"
  64. self deny: 0 = false.
  65. self deny: false = 0.
  66. self deny: '' = false.
  67. self deny: false = ''.
  68. self assert: true = true.
  69. self deny: false = true.
  70. self deny: true = false.
  71. self assert: false = false.
  72. "JS may do some type coercing after sending a message"
  73. self assert: true yourself = true.
  74. self assert: true yourself = true yourself
  75. !
  76. testIdentity
  77. "We're on top of JS...just be sure to check the basics!!"
  78. self deny: 0 == false.
  79. self deny: false == 0.
  80. self deny: '' == false.
  81. self deny: false == ''.
  82. self assert: true == true.
  83. self deny: false == true.
  84. self deny: true == false.
  85. self assert: false == false.
  86. "JS may do some type coercing after sending a message"
  87. self assert: true yourself == true.
  88. self assert: true yourself == true yourself
  89. !
  90. testIfTrueIfFalse
  91. self assert: (true ifTrue: ['alternative block']) = 'alternative block'.
  92. self assert: (true ifFalse: ['alternative block']) = nil.
  93. self assert: (false ifTrue: ['alternative block']) = nil.
  94. self assert: (false ifFalse: ['alternative block']) = 'alternative block'.
  95. self assert: (false ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
  96. self assert: (false ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
  97. self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
  98. self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
  99. !
  100. testIfTrueIfFalseWithBoxing
  101. self assert: (true yourself ifTrue: ['alternative block']) = 'alternative block'.
  102. self assert: (true yourself ifFalse: ['alternative block']) = nil.
  103. self assert: (false yourself ifTrue: ['alternative block']) = nil.
  104. self assert: (false yourself ifFalse: ['alternative block']) = 'alternative block'.
  105. self assert: (false yourself ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
  106. self assert: (false yourself ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
  107. self assert: (true yourself ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
  108. self assert: (true yourself ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
  109. !
  110. testLogic
  111. "Trivial logic table"
  112. self assert: (true & true); deny: (true & false); deny: (false & true); deny: (false & false).
  113. self assert: (true | true); assert: (true | false); assert: (false | true); deny: (false | false).
  114. "Checking that expressions work fine too"
  115. self assert: (true & (1 > 0)); deny: ((1 > 0) & false); deny: ((1 > 0) & (1 > 2)).
  116. self assert: (false | (1 > 0)); assert: ((1 > 0) | false); assert: ((1 > 0) | (1 > 2))
  117. !
  118. testLogicKeywords
  119. "Trivial logic table"
  120. self
  121. assert: (true and: [ true]);
  122. deny: (true and: [ false ]);
  123. deny: (false and: [ true ]);
  124. deny: (false and: [ false ]).
  125. self
  126. assert: (true or: [ true ]);
  127. assert: (true or: [ false ]);
  128. assert: (false or: [ true ]);
  129. deny: (false or: [ false ]).
  130. "Checking that expressions work fine too"
  131. self
  132. assert: (true and: [ 1 > 0 ]);
  133. deny: ((1 > 0) and: [ false ]);
  134. deny: ((1 > 0) and: [ 1 > 2 ]).
  135. self
  136. assert: (false or: [ 1 > 0 ]);
  137. assert: ((1 > 0) or: [ false ]);
  138. assert: ((1 > 0) or: [ 1 > 2 ])
  139. !
  140. testNonBooleanError
  141. self should: [ '' ifTrue: [] ifFalse: [] ] raise: NonBooleanReceiver
  142. ! !
  143. TestCase subclass: #ClassBuilderTest
  144. instanceVariableNames: 'builder theClass'
  145. package: 'Kernel-Tests'!
  146. !ClassBuilderTest methodsFor: 'running'!
  147. setUp
  148. builder := ClassBuilder new
  149. !
  150. tearDown
  151. theClass ifNotNil: [Smalltalk current removeClass: theClass. theClass := nil]
  152. !
  153. testClassCopy
  154. theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  155. self assert: theClass superclass == ObjectMock superclass.
  156. self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
  157. self assert: theClass name equals: 'ObjectMock2'.
  158. self assert: theClass package == ObjectMock package.
  159. self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
  160. !
  161. testClassMigration
  162. | instance oldClass |
  163. oldClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  164. instance := (Smalltalk current at: 'ObjectMock2') new.
  165. "Change the superclass of ObjectMock2"
  166. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  167. instanceVariableNames: ''
  168. package: 'Kernel-Tests'.
  169. self deny: oldClass == ObjectMock2.
  170. self assert: ObjectMock2 superclass == ObjectMock.
  171. self assert: ObjectMock2 instanceVariableNames isEmpty.
  172. self assert: ObjectMock2 selectors equals: oldClass selectors.
  173. self assert: ObjectMock2 comment equals: oldClass comment.
  174. self assert: ObjectMock2 package name equals: 'Kernel-Tests'.
  175. self deny: instance class == ObjectMock2.
  176. self assert: instance class name equals: 'OldObjectMock2'.
  177. self assert: (Smalltalk current at: 'OldObjectMock2') isNil.
  178. Smalltalk current removeClass: ObjectMock2
  179. !
  180. testClassMigrationWithClassInstanceVariables
  181. builder copyClass: ObjectMock named: 'ObjectMock2'.
  182. ObjectMock2 class instanceVariableNames: 'foo bar'.
  183. "Change the superclass of ObjectMock2"
  184. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  185. instanceVariableNames: ''
  186. package: 'Kernel-Tests'.
  187. self assert: ObjectMock2 class instanceVariableNames equals: #('foo' 'bar').
  188. Smalltalk current removeClass: ObjectMock2
  189. !
  190. testClassMigrationWithSubclasses
  191. builder copyClass: ObjectMock named: 'ObjectMock2'.
  192. ObjectMock2 subclass: 'ObjectMock3' instanceVariableNames: '' package: 'Kernel-Tests'.
  193. ObjectMock3 subclass: 'ObjectMock4' instanceVariableNames: '' package: 'Kernel-Tests'.
  194. "Change the superclass of ObjectMock2"
  195. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  196. instanceVariableNames: ''
  197. package: 'Kernel-Tests'.
  198. self assert: (ObjectMock subclasses includes: ObjectMock2).
  199. self assert: (ObjectMock2 subclasses includes: ObjectMock3).
  200. self assert: (ObjectMock3 subclasses includes: ObjectMock4).
  201. ObjectMock allSubclasses do: [ :each | Smalltalk current removeClass: each ]
  202. !
  203. testInstanceVariableNames
  204. self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
  205. ! !
  206. TestCase subclass: #CollectionTest
  207. instanceVariableNames: ''
  208. package: 'Kernel-Tests'!
  209. !CollectionTest methodsFor: 'accessing'!
  210. collection
  211. ^ self collectionClass withAll: self defaultValues
  212. !
  213. collectionClass
  214. ^ self class collectionClass
  215. !
  216. collectionWithDuplicates
  217. ^ self collectionClass withAll: #('a' 'b' 'c' 1 2 1 'a')
  218. !
  219. defaultValues
  220. ^ #(1 2 3 -4)
  221. ! !
  222. !CollectionTest methodsFor: 'convenience'!
  223. assertSameContents: aCollection as: anotherCollection
  224. self assert: aCollection size = anotherCollection size.
  225. aCollection do: [ :each |
  226. self assert: (aCollection occurrencesOf: each) = (anotherCollection occurrencesOf: each) ]
  227. ! !
  228. !CollectionTest methodsFor: 'testing'!
  229. isCollectionReadOnly
  230. ^ false
  231. ! !
  232. !CollectionTest methodsFor: 'tests'!
  233. testAsArray
  234. self
  235. assertSameContents: self collection
  236. as: self collection asArray
  237. !
  238. testAsOrderedCollection
  239. self
  240. assertSameContents: self collection
  241. as: self collection asOrderedCollection
  242. !
  243. testAsSet
  244. | c set |
  245. c := self collectionWithDuplicates.
  246. set := c asSet.
  247. self assert: set size = 5.
  248. c do: [ :each |
  249. self assert: (set includes: each) ]
  250. !
  251. testCollect
  252. | newCollection |
  253. newCollection := #(1 2 3 4).
  254. self
  255. assertSameContents: (self collection collect: [ :each |
  256. each abs ])
  257. as: newCollection
  258. !
  259. testDetect
  260. self assert: (self collection detect: [ :each | each < 0 ]) = -4.
  261. self
  262. should: [ self collection detect: [ :each | each = 6 ] ]
  263. raise: Error
  264. !
  265. testDo
  266. | newCollection |
  267. newCollection := OrderedCollection new.
  268. self collection do: [ :each |
  269. newCollection add: each ].
  270. self
  271. assertSameContents: self collection
  272. as: newCollection
  273. !
  274. testIsEmpty
  275. self assert: self collectionClass new isEmpty.
  276. self deny: self collection isEmpty
  277. !
  278. testSelect
  279. | newCollection |
  280. newCollection := #(2 -4).
  281. self
  282. assertSameContents: (self collection select: [ :each |
  283. each even ])
  284. as: newCollection
  285. !
  286. testSize
  287. self assert: self collectionClass new size = 0.
  288. self assert: self collection size = 4
  289. ! !
  290. !CollectionTest class methodsFor: 'accessing'!
  291. collectionClass
  292. ^ nil
  293. ! !
  294. !CollectionTest class methodsFor: 'testing'!
  295. isAbstract
  296. ^ self collectionClass isNil
  297. ! !
  298. CollectionTest subclass: #HashedCollectionTest
  299. instanceVariableNames: ''
  300. package: 'Kernel-Tests'!
  301. !HashedCollectionTest methodsFor: 'accessing'!
  302. collection
  303. ^ #{ 'a' -> 1. 'b' -> 2. 'c' -> 3. 'd' -> -4 }
  304. !
  305. collectionWithDuplicates
  306. ^ #{ 'a' -> 1. 'b' -> 2. 'c' -> 3. 'd' -> -4. 'e' -> 1. 'f' -> 2. 'g' -> 10 }
  307. ! !
  308. !HashedCollectionTest class methodsFor: 'accessing'!
  309. collectionClass
  310. ^ HashedCollection
  311. ! !
  312. HashedCollectionTest subclass: #DictionaryTest
  313. instanceVariableNames: ''
  314. package: 'Kernel-Tests'!
  315. !DictionaryTest methodsFor: 'accessing'!
  316. collection
  317. ^ Dictionary new
  318. at: 1 put: 1;
  319. at: 'a' put: 2;
  320. at: true put: 3;
  321. at: 4 put: -4;
  322. yourself
  323. !
  324. collectionWithDuplicates
  325. ^ Dictionary new
  326. at: 1 put: 1;
  327. at: 'a' put: 2;
  328. at: true put: 3;
  329. at: 4 put: -4;
  330. at: 'b' put: 1;
  331. at: 3 put: 3;
  332. at: false put: 12;
  333. yourself
  334. ! !
  335. !DictionaryTest methodsFor: 'tests'!
  336. testAccessing
  337. | d |
  338. d := Dictionary new.
  339. d at: 'hello' put: 'world'.
  340. self assert: (d at: 'hello') = 'world'.
  341. self assert: (d at: 'hello' ifAbsent: [nil]) = 'world'.
  342. self deny: (d at: 'foo' ifAbsent: [nil]) = 'world'.
  343. d at: 1 put: 2.
  344. self assert: (d at: 1) = 2.
  345. d at: 1@3 put: 3.
  346. self assert: (d at: 1@3) = 3
  347. !
  348. testDynamicDictionaries
  349. self assert: #{'hello' -> 1} asDictionary = (Dictionary with: 'hello' -> 1)
  350. !
  351. testEquality
  352. | d1 d2 |
  353. self assert: Dictionary new = Dictionary new.
  354. d1 := Dictionary new at: 1 put: 2; yourself.
  355. d2 := Dictionary new at: 1 put: 2; yourself.
  356. self assert: d1 = d2.
  357. d2 := Dictionary new at: 1 put: 3; yourself.
  358. self deny: d1 = d2.
  359. d2 := Dictionary new at: 2 put: 2; yourself.
  360. self deny: d1 = d2.
  361. d2 := Dictionary new at: 1 put: 2; at: 3 put: 4; yourself.
  362. self deny: d1 = d2.
  363. !
  364. testIfAbsent
  365. | d visited |
  366. visited := false.
  367. d := Dictionary new.
  368. d at: 'hello' ifAbsent: [ visited := true ].
  369. self assert: visited.
  370. !
  371. testIfPresent
  372. | d visited absent |
  373. visited := false.
  374. d := Dictionary new.
  375. d at: 'hello' put: 'world'.
  376. d at: 'hello' ifPresent: [ :value | visited := value ].
  377. self assert: visited = 'world'.
  378. absent := d at: 'bye' ifPresent: [ :value | visited := value ].
  379. self assert: absent isNil.
  380. !
  381. testIfPresentIfAbsent
  382. | d visited |
  383. visited := false.
  384. d := Dictionary new.
  385. d at: 'hello' put: 'world'.
  386. d at: 'hello' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  387. self assert: visited = 'world'.
  388. d at: 'buy' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  389. self assert: visited.
  390. !
  391. testKeys
  392. | d |
  393. d := Dictionary new.
  394. d at: 1 put: 2.
  395. d at: 2 put: 3.
  396. d at: 3 put: 4.
  397. self assert: d keys = #(1 2 3)
  398. !
  399. testPrintString
  400. self
  401. assert: 'a Dictionary(''firstname''->''James'' , ''lastname''->''Bond'')'
  402. equals: (Dictionary new
  403. at:'firstname' put: 'James';
  404. at:'lastname' put: 'Bond';
  405. printString)
  406. !
  407. testRemoveKey
  408. | d key |
  409. d := Dictionary new.
  410. d at: 1 put: 2.
  411. d at: 2 put: 3.
  412. d at: 3 put: 4.
  413. key := 2.
  414. self assert: d keys = #(1 2 3).
  415. d removeKey: key.
  416. self assert: d keys = #(1 3).
  417. self assert: d values = #(2 4).
  418. self deny: (d includesKey: 2)
  419. !
  420. testRemoveKeyIfAbsent
  421. | d key |
  422. d := Dictionary new.
  423. d at: 1 put: 2.
  424. d at: 2 put: 3.
  425. d at: 3 put: 4.
  426. key := 2.
  427. self assert: (d removeKey: key) = 3.
  428. key := 3.
  429. self assert: (d removeKey: key ifAbsent: [42]) = 4.
  430. key := 'why'.
  431. self assert: (d removeKey: key ifAbsent: [42] ) = 42.
  432. !
  433. testSize
  434. | d |
  435. d := Dictionary new.
  436. self assert: d size = 0.
  437. d at: 1 put: 2.
  438. self assert: d size = 1.
  439. d at: 2 put: 3.
  440. self assert: d size = 2.
  441. !
  442. testValues
  443. | d |
  444. d := Dictionary new.
  445. d at: 1 put: 2.
  446. d at: 2 put: 3.
  447. d at: 3 put: 4.
  448. self assert: d values = #(2 3 4)
  449. ! !
  450. !DictionaryTest class methodsFor: 'accessing'!
  451. collectionClass
  452. ^ Dictionary
  453. ! !
  454. CollectionTest subclass: #SequenceableCollectionTest
  455. instanceVariableNames: ''
  456. package: 'Kernel-Tests'!
  457. !SequenceableCollectionTest methodsFor: 'tests'!
  458. testAt
  459. self assert: (self collection at: 4) = -4.
  460. self should: [ self collection at: 5 ] raise: Error
  461. !
  462. testAtIfAbsent
  463. self assert: (self collection at: (self collection size + 1) ifAbsent: [ 'none' ]) = 'none'
  464. ! !
  465. SequenceableCollectionTest subclass: #ArrayTest
  466. instanceVariableNames: ''
  467. package: 'Kernel-Tests'!
  468. !ArrayTest methodsFor: 'testing'!
  469. testAtIfAbsent
  470. | array |
  471. array := #('hello' 'world').
  472. self assert: (array at: 1) equals: 'hello'.
  473. self assert: (array at: 2) equals: 'world'.
  474. self assert: (array at: 2 ifAbsent: ['not found']) equals: 'world'.
  475. self assert: (array at: 0 ifAbsent: ['not found']) equals: 'not found'.
  476. self assert: (array at: -10 ifAbsent: ['not found']) equals: 'not found'.
  477. self assert: (array at: 3 ifAbsent: ['not found']) equals: 'not found'.
  478. !
  479. testFirstN
  480. self assert: {1. 2. 3} equals: ({1. 2. 3. 4. 5} first: 3).
  481. !
  482. testIfEmpty
  483. self assert: 'zork' equals: ( '' ifEmpty: ['zork'] )
  484. !
  485. testPrintString
  486. | array |
  487. array := Array new.
  488. self assert: 'a Array ()' equals: ( array printString ).
  489. array add: 1; add: 3.
  490. self assert: 'a Array (1 3)' equals: ( array printString ).
  491. array add: 'foo'.
  492. self assert: 'a Array (1 3 ''foo'')' equals: ( array printString ).
  493. array remove: 1; remove: 3.
  494. self assert: 'a Array (''foo'')' equals: ( array printString ).
  495. array addLast: 3.
  496. self assert: 'a Array (''foo'' 3)' equals: ( array printString ).
  497. array addLast: 3.
  498. self assert: 'a Array (''foo'' 3 3)' equals: ( array printString ).
  499. ! !
  500. !ArrayTest class methodsFor: 'accessing'!
  501. collectionClass
  502. ^ Array
  503. ! !
  504. SequenceableCollectionTest subclass: #StringTest
  505. instanceVariableNames: ''
  506. package: 'Kernel-Tests'!
  507. !StringTest methodsFor: 'accessing'!
  508. collection
  509. ^'hello'
  510. !
  511. collectionWithDuplicates
  512. ^ 'abbaerte'
  513. ! !
  514. !StringTest methodsFor: 'tests'!
  515. testAddRemove
  516. self should: ['hello' add: 'a'] raise: Error.
  517. self should: ['hello' remove: 'h'] raise: Error
  518. !
  519. testAsArray
  520. self assert: 'hello' asArray = #('h' 'e' 'l' 'l' 'o').
  521. !
  522. testAt
  523. self assert: ('hello' at: 1) = 'h'.
  524. self assert: ('hello' at: 5) = 'o'.
  525. self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
  526. !
  527. testAtPut
  528. "String instances are read-only"
  529. self should: ['hello' at: 1 put: 'a'] raise: Error
  530. !
  531. testCollect
  532. | newCollection |
  533. newCollection := 'hheelllloo'.
  534. self
  535. assertSameContents: (self collection collect: [ :each |
  536. each, each ])
  537. as: newCollection
  538. !
  539. testCopyWithoutAll
  540. self
  541. assert: 'hello world'
  542. equals: ('*hello* *world*' copyWithoutAll: '*')
  543. !
  544. testDetect
  545. self assert: (self collection detect: [ :each | each = 'h' ]) = 'h'.
  546. self
  547. should: [ self collection detect: [ :each | each = 6 ] ]
  548. raise: Error
  549. !
  550. testEquality
  551. self assert: 'hello' = 'hello'.
  552. self deny: 'hello' = 'world'.
  553. self assert: 'hello' = 'hello' yourself.
  554. self assert: 'hello' yourself = 'hello'.
  555. "test JS falsy value"
  556. self deny: '' = 0
  557. !
  558. testIdentity
  559. self assert: 'hello' == 'hello'.
  560. self deny: 'hello' == 'world'.
  561. self assert: 'hello' == 'hello' yourself.
  562. self assert: 'hello' yourself == 'hello'.
  563. "test JS falsy value"
  564. self deny: '' == 0
  565. !
  566. testIncludesSubString
  567. self assert: ('amber' includesSubString: 'ber').
  568. self deny: ('amber' includesSubString: 'zork').
  569. !
  570. testJoin
  571. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  572. !
  573. testSelect
  574. | newCollection |
  575. newCollection := 'o'.
  576. self
  577. assertSameContents: (self collection select: [ :each |
  578. each = 'o' ])
  579. as: newCollection
  580. !
  581. testSize
  582. self assert: 'smalltalk' size equals: 9.
  583. self assert: '' size equals: 0
  584. !
  585. testStreamContents
  586. self
  587. assert: 'hello world'
  588. equals: (String streamContents: [ :aStream |
  589. aStream
  590. nextPutAll: 'hello'; space;
  591. nextPutAll: 'world' ])
  592. ! !
  593. !StringTest class methodsFor: 'accessing'!
  594. collectionClass
  595. ^ String
  596. ! !
  597. SequenceableCollectionTest subclass: #SymbolTest
  598. instanceVariableNames: ''
  599. package: 'Kernel-Tests'!
  600. !SymbolTest methodsFor: 'accessing'!
  601. collection
  602. ^ #hello
  603. !
  604. collectionWithDuplicates
  605. ^ #phhaaarorra
  606. ! !
  607. !SymbolTest methodsFor: 'tests'!
  608. testAsString
  609. self assert: #hello asString equals: 'hello'
  610. !
  611. testAsSymbol
  612. self assert: #hello == #hello asSymbol
  613. !
  614. testAt
  615. self assert: (#hello at: 1) = 'h'.
  616. self assert: (#hello at: 5) = 'o'.
  617. self assert: (#hello at: 6 ifAbsent: [nil]) = nil
  618. !
  619. testAtPut
  620. "Symbol instances are read-only"
  621. self should: ['hello' at: 1 put: 'a'] raise: Error
  622. !
  623. testCollect
  624. | newCollection |
  625. newCollection := #hheelllloo.
  626. self
  627. assertSameContents: (self collection collect: [ :each |
  628. each, each ])
  629. as: newCollection
  630. !
  631. testComparing
  632. self assert: #ab > #aa.
  633. self deny: #ab > #ba.
  634. self assert: #ab < #ba.
  635. self deny: #bb < #ba.
  636. self assert: #ab >= #aa.
  637. self deny: #ab >= #ba.
  638. self assert: #ab <= #ba.
  639. self deny: #bb <= #ba
  640. !
  641. testCopying
  642. self assert: #hello copy == #hello.
  643. self assert: #hello deepCopy == #hello
  644. !
  645. testDetect
  646. self assert: (self collection detect: [ :each | each = 'h' ]) = 'h'.
  647. self
  648. should: [ self collection detect: [ :each | each = 'z' ] ]
  649. raise: Error
  650. !
  651. testEquality
  652. self assert: #hello = #hello.
  653. self deny: #hello = #world.
  654. self assert: #hello = #hello yourself.
  655. self assert: #hello yourself = #hello.
  656. self deny: #hello = 'hello'.
  657. self deny: 'hello' = #hello.
  658. !
  659. testIdentity
  660. self assert: #hello == #hello.
  661. self deny: #hello == #world.
  662. self assert: #hello = #hello yourself.
  663. self assert: #hello yourself = #hello asString asSymbol
  664. !
  665. testIsEmpty
  666. self deny: self collection isEmpty.
  667. self assert: '' asSymbol isEmpty
  668. !
  669. testIsSymbolIsString
  670. self assert: #hello isSymbol.
  671. self deny: 'hello' isSymbol.
  672. self deny: #hello isString.
  673. self assert: 'hello' isString
  674. !
  675. testSelect
  676. | newCollection |
  677. newCollection := 'o'.
  678. self
  679. assertSameContents: (self collection select: [ :each |
  680. each = 'o' ])
  681. as: newCollection
  682. !
  683. testSize
  684. self assert: #a size equals: 1.
  685. self assert: #aaaaa size equals: 5
  686. ! !
  687. !SymbolTest class methodsFor: 'accessing'!
  688. collectionClass
  689. ^ Symbol
  690. ! !
  691. TestCase subclass: #JSObjectProxyTest
  692. instanceVariableNames: ''
  693. package: 'Kernel-Tests'!
  694. !JSObjectProxyTest methodsFor: 'accessing'!
  695. jsObject
  696. <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null}>
  697. ! !
  698. !JSObjectProxyTest methodsFor: 'tests'!
  699. testDNU
  700. self should: [self jsObject foo] raise: MessageNotUnderstood
  701. !
  702. testMessageSend
  703. self assert: self jsObject a equals: 1.
  704. self assert: self jsObject b equals: 2.
  705. self assert: (self jsObject c: 3) equals: 3
  706. !
  707. testMethodWithArguments
  708. self assert: (self jsObject c: 1) equals: 1
  709. !
  710. testPrinting
  711. self assert: self jsObject printString = '[object Object]'
  712. !
  713. testPropertyThatReturnsEmptyString
  714. | object |
  715. object := self jsObject.
  716. self assert: '' equals: object d.
  717. object d: 'hello'.
  718. self assert: 'hello' equals: object d
  719. !
  720. testPropertyThatReturnsUndefined
  721. | object |
  722. object := self jsObject.
  723. self shouldnt: [ object e ] raise: MessageNotUnderstood.
  724. self assert: object e isNil
  725. !
  726. testYourself
  727. | object |
  728. object := self jsObject
  729. d: 'test';
  730. yourself.
  731. self assert: object d equals: 'test'
  732. ! !
  733. TestCase subclass: #NumberTest
  734. instanceVariableNames: ''
  735. package: 'Kernel-Tests'!
  736. !NumberTest methodsFor: 'tests'!
  737. testAbs
  738. self assert: 4 abs = 4.
  739. self assert: -4 abs = 4
  740. !
  741. testArithmetic
  742. "We rely on JS here, so we won't test complex behavior, just check if
  743. message sends are corrects"
  744. self assert: 1.5 + 1 = 2.5.
  745. self assert: 2 - 1 = 1.
  746. self assert: -2 - 1 = -3.
  747. self assert: 12 / 2 = 6.
  748. self assert: 3 * 4 = 12.
  749. "Simple parenthesis and execution order"
  750. self assert: 1 + 2 * 3 = 9.
  751. self assert: 1 + (2 * 3) = 7
  752. !
  753. testComparison
  754. self assert: 3 > 2.
  755. self assert: 2 < 3.
  756. self deny: 3 < 2.
  757. self deny: 2 > 3.
  758. self assert: 3 >= 3.
  759. self assert: 3.1 >= 3.
  760. self assert: 3 <= 3.
  761. self assert: 3 <= 3.1
  762. !
  763. testCopying
  764. self assert: 1 copy == 1.
  765. self assert: 1 deepCopy == 1
  766. !
  767. testEquality
  768. self assert: 1 = 1.
  769. self assert: 0 = 0.
  770. self deny: 1 = 0.
  771. self assert: 1 yourself = 1.
  772. self assert: 1 = 1 yourself.
  773. self assert: 1 yourself = 1 yourself.
  774. self deny: 0 = false.
  775. self deny: false = 0.
  776. self deny: '' = 0.
  777. self deny: 0 = ''
  778. !
  779. testHexNumbers
  780. self assert: 16r9 = 9.
  781. self assert: 16rA truncated = 10.
  782. self assert: 16rB truncated = 11.
  783. self assert: 16rC truncated = 12.
  784. self assert: 16rD truncated = 13.
  785. self assert: 16rE truncated = 14.
  786. self assert: 16rF truncated = 15
  787. !
  788. testIdentity
  789. self assert: 1 == 1.
  790. self assert: 0 == 0.
  791. self deny: 1 == 0.
  792. self assert: 1 yourself == 1.
  793. self assert: 1 == 1 yourself.
  794. self assert: 1 yourself == 1 yourself.
  795. self deny: 1 == 2
  796. !
  797. testInvalidHexNumbers
  798. self should: [16rG] raise: MessageNotUnderstood.
  799. self should: [16rg] raise: MessageNotUnderstood.
  800. self should: [16rH] raise: MessageNotUnderstood.
  801. self should: [16rh] raise: MessageNotUnderstood.
  802. self should: [16rI] raise: MessageNotUnderstood.
  803. self should: [16ri] raise: MessageNotUnderstood.
  804. self should: [16rJ] raise: MessageNotUnderstood.
  805. self should: [16rj] raise: MessageNotUnderstood.
  806. self should: [16rK] raise: MessageNotUnderstood.
  807. self should: [16rk] raise: MessageNotUnderstood.
  808. self should: [16rL] raise: MessageNotUnderstood.
  809. self should: [16rl] raise: MessageNotUnderstood.
  810. self should: [16rM] raise: MessageNotUnderstood.
  811. self should: [16rm] raise: MessageNotUnderstood.
  812. self should: [16rN] raise: MessageNotUnderstood.
  813. self should: [16rn] raise: MessageNotUnderstood.
  814. self should: [16rO] raise: MessageNotUnderstood.
  815. self should: [16ro] raise: MessageNotUnderstood.
  816. self should: [16rP] raise: MessageNotUnderstood.
  817. self should: [16rp] raise: MessageNotUnderstood.
  818. self should: [16rQ] raise: MessageNotUnderstood.
  819. self should: [16rq] raise: MessageNotUnderstood.
  820. self should: [16rR] raise: MessageNotUnderstood.
  821. self should: [16rr] raise: MessageNotUnderstood.
  822. self should: [16rS] raise: MessageNotUnderstood.
  823. self should: [16rs] raise: MessageNotUnderstood.
  824. self should: [16rT] raise: MessageNotUnderstood.
  825. self should: [16rt] raise: MessageNotUnderstood.
  826. self should: [16rU] raise: MessageNotUnderstood.
  827. self should: [16ru] raise: MessageNotUnderstood.
  828. self should: [16rV] raise: MessageNotUnderstood.
  829. self should: [16rv] raise: MessageNotUnderstood.
  830. self should: [16rW] raise: MessageNotUnderstood.
  831. self should: [16rw] raise: MessageNotUnderstood.
  832. self should: [16rX] raise: MessageNotUnderstood.
  833. self should: [16rx] raise: MessageNotUnderstood.
  834. self should: [16rY] raise: MessageNotUnderstood.
  835. self should: [16ry] raise: MessageNotUnderstood.
  836. self should: [16rZ] raise: MessageNotUnderstood.
  837. self should: [16rz] raise: MessageNotUnderstood.
  838. self should: [16rABcdEfZ] raise: MessageNotUnderstood.
  839. !
  840. testMinMax
  841. self assert: (2 max: 5) equals: 5.
  842. self assert: (2 min: 5) equals: 2
  843. !
  844. testNegated
  845. self assert: 3 negated = -3.
  846. self assert: -3 negated = 3
  847. !
  848. testPrintShowingDecimalPlaces
  849. self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
  850. self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
  851. self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
  852. self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
  853. self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
  854. self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
  855. self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
  856. self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
  857. self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
  858. self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
  859. self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
  860. self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
  861. self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
  862. !
  863. testRounded
  864. self assert: 3 rounded = 3.
  865. self assert: 3.212 rounded = 3.
  866. self assert: 3.51 rounded = 4
  867. !
  868. testSqrt
  869. self assert: 4 sqrt = 2.
  870. self assert: 16 sqrt = 4
  871. !
  872. testSquared
  873. self assert: 4 squared = 16
  874. !
  875. testTimesRepeat
  876. | i |
  877. i := 0.
  878. 0 timesRepeat: [i := i + 1].
  879. self assert: i equals: 0.
  880. 5 timesRepeat: [i := i + 1].
  881. self assert: i equals: 5
  882. !
  883. testTo
  884. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  885. !
  886. testToBy
  887. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  888. self should: [1 to: 4 by: 0] raise: Error
  889. !
  890. testTruncated
  891. self assert: 3 truncated = 3.
  892. self assert: 3.212 truncated = 3.
  893. self assert: 3.51 truncated = 3
  894. ! !
  895. Object subclass: #ObjectMock
  896. instanceVariableNames: 'foo bar'
  897. package: 'Kernel-Tests'!
  898. !ObjectMock commentStamp!
  899. ObjectMock is there only to perform tests on classes.!
  900. !ObjectMock methodsFor: 'not yet classified'!
  901. foo
  902. ^foo
  903. !
  904. foo: anObject
  905. foo := anObject
  906. ! !
  907. TestCase subclass: #ObjectTest
  908. instanceVariableNames: ''
  909. package: 'Kernel-Tests'!
  910. !ObjectTest methodsFor: 'tests'!
  911. notDefined
  912. <return undefined;>
  913. !
  914. testBasicAccess
  915. | o |
  916. o := Object new.
  917. o basicAt: 'a' put: 1.
  918. self assert: (o basicAt: 'a') equals: 1.
  919. self assert: (o basicAt: 'b') equals: nil
  920. !
  921. testBasicPerform
  922. | o |
  923. o := Object new.
  924. o basicAt: 'func' put: ['hello'].
  925. o basicAt: 'func2' put: [:a | a + 1].
  926. self assert: (o basicPerform: 'func') equals: 'hello'.
  927. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  928. !
  929. testDNU
  930. self should: [Object new foo] raise: MessageNotUnderstood
  931. !
  932. testEquality
  933. | o |
  934. o := Object new.
  935. self deny: o = Object new.
  936. self assert: o = o.
  937. self assert: o yourself = o.
  938. self assert: o = o yourself
  939. !
  940. testHalt
  941. self should: [Object new halt] raise: Error
  942. !
  943. testIdentity
  944. | o |
  945. o := Object new.
  946. self deny: o == Object new.
  947. self assert: o == o.
  948. self assert: o yourself == o.
  949. self assert: o == o yourself
  950. !
  951. testIfNil
  952. self deny: Object new isNil.
  953. self deny: (Object new ifNil: [true]) = true.
  954. self assert: (Object new ifNotNil: [true]) = true.
  955. self assert: (Object new ifNil: [false] ifNotNil: [true]) = true.
  956. self assert: (Object new ifNotNil: [true] ifNil: [false]) = true
  957. !
  958. testInstVars
  959. | o |
  960. o := ObjectMock new.
  961. self assert: (o instVarAt: #foo) equals: nil.
  962. o instVarAt: #foo put: 1.
  963. self assert: (o instVarAt: #foo) equals: 1.
  964. self assert: (o instVarAt: 'foo') equals: 1
  965. !
  966. testNilUndefined
  967. "nil in Smalltalk is the undefined object in JS"
  968. self assert: nil = self notDefined
  969. !
  970. testYourself
  971. | o |
  972. o := ObjectMock new.
  973. self assert: o yourself == o
  974. !
  975. testidentityHash
  976. | o1 o2 |
  977. o1 := Object new.
  978. o2 := Object new.
  979. self assert: o1 identityHash == o1 identityHash.
  980. self deny: o1 identityHash == o2 identityHash
  981. ! !
  982. TestCase subclass: #PackageTest
  983. instanceVariableNames: 'zorkPackage grulPackage backUpCommitPathJs backUpCommitPathSt'
  984. package: 'Kernel-Tests'!
  985. !PackageTest methodsFor: 'running'!
  986. setUp
  987. backUpCommitPathJs := Package defaultCommitPathJs.
  988. backUpCommitPathSt := Package defaultCommitPathSt.
  989. Package resetCommitPaths.
  990. zorkPackage := Package new name: 'Zork'.
  991. grulPackage := Package new
  992. name: 'Grul';
  993. commitPathJs: 'server/grul/js';
  994. commitPathSt: 'grul/st';
  995. yourself
  996. !
  997. tearDown
  998. Package
  999. defaultCommitPathJs: backUpCommitPathJs;
  1000. defaultCommitPathSt: backUpCommitPathSt
  1001. ! !
  1002. !PackageTest methodsFor: 'tests'!
  1003. testGrulCommitPathJsShouldBeServerGrulJs
  1004. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  1005. !
  1006. testGrulCommitPathStShouldBeGrulSt
  1007. self assert: 'grul/st' equals: grulPackage commitPathSt
  1008. !
  1009. testZorkCommitPathJsShouldBeJs
  1010. self assert: 'js' equals: zorkPackage commitPathJs
  1011. !
  1012. testZorkCommitPathStShouldBeSt
  1013. self assert: 'st' equals: zorkPackage commitPathSt
  1014. ! !
  1015. PackageTest subclass: #PackageWithDefaultCommitPathChangedTest
  1016. instanceVariableNames: ''
  1017. package: 'Kernel-Tests'!
  1018. !PackageWithDefaultCommitPathChangedTest methodsFor: 'running'!
  1019. setUp
  1020. super setUp.
  1021. Package
  1022. defaultCommitPathJs: 'javascripts/';
  1023. defaultCommitPathSt: 'smalltalk/'.
  1024. ! !
  1025. !PackageWithDefaultCommitPathChangedTest methodsFor: 'tests'!
  1026. testGrulCommitPathJsShouldBeServerGrulJs
  1027. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  1028. !
  1029. testGrulCommitPathStShouldBeGrulSt
  1030. self assert: 'grul/st' equals: grulPackage commitPathSt
  1031. !
  1032. testZorkCommitPathJsShouldBeJavascript
  1033. self assert: 'javascripts/' equals: zorkPackage commitPathJs
  1034. !
  1035. testZorkCommitPathStShouldBeSmalltalk
  1036. self assert: 'smalltalk/' equals: zorkPackage commitPathSt
  1037. ! !
  1038. !PackageWithDefaultCommitPathChangedTest class methodsFor: 'accessing'!
  1039. shouldInheritSelectors
  1040. ^ false
  1041. ! !
  1042. TestCase subclass: #PointTest
  1043. instanceVariableNames: ''
  1044. package: 'Kernel-Tests'!
  1045. !PointTest methodsFor: 'tests'!
  1046. testAccessing
  1047. self assert: (Point x: 3 y: 4) x equals: 3.
  1048. self assert: (Point x: 3 y: 4) y equals: 4.
  1049. self assert: (Point new x: 3) x equals: 3.
  1050. self assert: (Point new y: 4) y equals: 4
  1051. !
  1052. testArithmetic
  1053. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  1054. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  1055. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  1056. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  1057. !
  1058. testAt
  1059. self assert: 3@4 equals: (Point x: 3 y: 4)
  1060. !
  1061. testEgality
  1062. self assert: 3@4 = (3@4).
  1063. self deny: 3@5 = (3@6)
  1064. !
  1065. testTranslateBy
  1066. self assert: 3@4 equals: (3@3 translateBy: 0@1).
  1067. self assert: 3@2 equals: (3@3 translateBy: 0@1 negated).
  1068. self assert: 5@6 equals: (3@3 translateBy: 2@3).
  1069. self assert: 0@3 equals: (3@3 translateBy: 3 negated @0).
  1070. ! !
  1071. TestCase subclass: #RandomTest
  1072. instanceVariableNames: ''
  1073. package: 'Kernel-Tests'!
  1074. !RandomTest methodsFor: 'tests'!
  1075. textNext
  1076. 10000 timesRepeat: [
  1077. | current next |
  1078. next := Random new next.
  1079. self assert: (next >= 0).
  1080. self assert: (next < 1).
  1081. self deny: current = next.
  1082. next = current]
  1083. ! !
  1084. TestCase subclass: #SetTest
  1085. instanceVariableNames: ''
  1086. package: 'Kernel-Tests'!
  1087. !SetTest methodsFor: 'tests'!
  1088. testAddRemove
  1089. | set |
  1090. set := Set new.
  1091. self assert: set isEmpty.
  1092. set add: 3.
  1093. self assert: (set includes: 3).
  1094. set add: 5.
  1095. self assert: (set includes: 5).
  1096. set remove: 3.
  1097. self deny: (set includes: 3)
  1098. !
  1099. testAt
  1100. self should: [Set new at: 1 put: 2] raise: Error
  1101. !
  1102. testPrintString
  1103. | set |
  1104. set := Set new.
  1105. self assert: 'a Set ()' equals: ( set printString ).
  1106. set add: 1; add: 3.
  1107. self assert: 'a Set (1 3)' equals: ( set printString ).
  1108. set add: 'foo'.
  1109. self assert: 'a Set (1 3 ''foo'')' equals: ( set printString ).
  1110. set remove: 1; remove: 3.
  1111. self assert: 'a Set (''foo'')' equals: ( set printString ).
  1112. set add: 3.
  1113. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  1114. set add: 3.
  1115. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  1116. !
  1117. testSize
  1118. self assert: Set new size equals: 0.
  1119. self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
  1120. self assert: (Set withAll: #(1 1 1 1)) size equals: 1
  1121. !
  1122. testUnicity
  1123. | set |
  1124. set := Set new.
  1125. set add: 21.
  1126. set add: 'hello'.
  1127. set add: 21.
  1128. self assert: set size = 2.
  1129. set add: 'hello'.
  1130. self assert: set size = 2.
  1131. self assert: set asArray equals: #(21 'hello')
  1132. ! !
  1133. TestCase subclass: #UndefinedTest
  1134. instanceVariableNames: ''
  1135. package: 'Kernel-Tests'!
  1136. !UndefinedTest methodsFor: 'tests'!
  1137. testCopying
  1138. self assert: nil copy equals: nil
  1139. !
  1140. testDeepCopy
  1141. self assert: nil deepCopy = nil
  1142. !
  1143. testIfNil
  1144. self assert: (nil ifNil: [true]) equals: true.
  1145. self deny: (nil ifNotNil: [true]) = true.
  1146. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  1147. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  1148. !
  1149. testIsNil
  1150. self assert: nil isNil.
  1151. self deny: nil notNil.
  1152. ! !