Kernel-Tests.st 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713
  1. Smalltalk createPackage: 'Kernel-Tests'!
  2. TestCase subclass: #AnnouncementSubscriptionTest
  3. instanceVariableNames: ''
  4. package: 'Kernel-Tests'!
  5. !AnnouncementSubscriptionTest methodsFor: 'tests'!
  6. testAddExtensionMethod
  7. | method dirty |
  8. dirty := self class package isDirty.
  9. self class package beClean.
  10. method := self class compile: 'doNothing' protocol: '**not-a-package'.
  11. self deny: self class package isDirty.
  12. self class removeCompiledMethod: method.
  13. dirty ifTrue: [ self class package beDirty ]
  14. !
  15. testHandlesAnnouncement
  16. | subscription announcementClass1 announcementClass2 classBuilder |
  17. classBuilder := ClassBuilder new.
  18. announcementClass1 := classBuilder basicAddSubclassOf: SystemAnnouncement named: 'TestAnnouncement1' instanceVariableNames: #() package: 'Kernel-Tests'.
  19. subscription := AnnouncementSubscription new announcementClass: SystemAnnouncement.
  20. "Test whether the same class triggers the announcement"
  21. self assert: (subscription handlesAnnouncement: SystemAnnouncement) equals: true.
  22. "Test whether a subclass triggers the announcement"
  23. self assert: (subscription handlesAnnouncement: announcementClass1) equals: true.
  24. "Test whether an unrelated class does not trigger the announcement"
  25. self assert: (subscription handlesAnnouncement: Object) equals: false.
  26. classBuilder basicRemoveClass: announcementClass1.
  27. ! !
  28. TestCase subclass: #AnnouncerTest
  29. instanceVariableNames: ''
  30. package: 'Kernel-Tests'!
  31. !AnnouncerTest methodsFor: 'tests'!
  32. testOnDo
  33. | counter announcer |
  34. counter := 0.
  35. announcer := Announcer new.
  36. announcer on: SystemAnnouncement do: [ counter := counter + 1 ].
  37. announcer announce: (SystemAnnouncement new).
  38. self assert: counter equals: 1.
  39. announcer announce: (SystemAnnouncement new).
  40. self assert: counter equals: 2.
  41. !
  42. testOnDoFor
  43. | counter announcer |
  44. counter := 0.
  45. announcer := Announcer new.
  46. announcer on: SystemAnnouncement do: [ counter := counter + 1 ] for: self.
  47. announcer announce: (SystemAnnouncement new).
  48. self assert: counter equals: 1.
  49. announcer announce: (SystemAnnouncement new).
  50. self assert: counter equals: 2.
  51. announcer unsubscribe: self.
  52. announcer announce: (SystemAnnouncement new).
  53. self assert: counter equals: 2.
  54. !
  55. testOnDoOnce
  56. | counter announcer |
  57. counter := 0.
  58. announcer := Announcer new.
  59. announcer on: SystemAnnouncement doOnce: [ counter := counter + 1 ].
  60. announcer announce: (SystemAnnouncement new).
  61. self assert: counter equals: 1.
  62. announcer announce: (SystemAnnouncement new).
  63. self assert: counter equals: 1.
  64. ! !
  65. TestCase subclass: #BlockClosureTest
  66. instanceVariableNames: ''
  67. package: 'Kernel-Tests'!
  68. !BlockClosureTest methodsFor: 'tests'!
  69. testCanClearInterval
  70. self shouldnt: [ ([ Error new signal ] valueWithInterval: 0) clearInterval ] raise: Error
  71. !
  72. testCanClearTimeout
  73. self shouldnt: [ ([ Error new signal ] valueWithTimeout: 0) clearTimeout ] raise: Error
  74. !
  75. testCompiledSource
  76. self assert: ([ 1+1 ] compiledSource includesSubString: 'function')
  77. !
  78. testCurrySelf
  79. | curriedMethod array |
  80. curriedMethod := [ :selfarg :x | selfarg at: x ] currySelf asCompiledMethod: 'foo:'.
  81. array := #(3 1 4).
  82. ClassBuilder new installMethod: curriedMethod forClass: Array protocol: '**test helper'.
  83. [ self assert: (array foo: 2) equals: 1 ]
  84. ensure: [ Array removeCompiledMethod: curriedMethod ]
  85. !
  86. testEnsure
  87. self assert: ([ 3 ] ensure: [ 4 ]) equals: 3
  88. !
  89. testEnsureRaises
  90. self should: [ [Error new signal ] ensure: [ true ]] raise: Error
  91. !
  92. testExceptionSemantics
  93. "See https://github.com/NicolasPetton/amber/issues/314"
  94. self timeout: 100.
  95. (self async: [
  96. [
  97. self assert: true.
  98. Error signal.
  99. "The following should *not* be run"
  100. self deny: true.
  101. self finished.
  102. ] on: Error do: [ :ex | self finished ]
  103. ]) valueWithTimeout: 0
  104. !
  105. testNewWithValues
  106. <
  107. function TestConstructor(arg1, arg2, arg3) {}
  108. TestConstructor.prototype.name = 'theTestPrototype';
  109. var wrappedConstructor = $recv(TestConstructor);
  110. var result = wrappedConstructor._newWithValues_([1, 2, 3 ]);
  111. self._assert_(result instanceof TestConstructor);
  112. self._assert_equals_(result.name, 'theTestPrototype');
  113. "newWithValues: cannot help if the argument list is wrong, and should warn that a mistake was made."
  114. self._should_raise_(function () {wrappedConstructor._newWithValues_('single argument');}, $globals.Error);
  115. >
  116. !
  117. testNumArgs
  118. self assert: [] numArgs equals: 0.
  119. self assert: [ :a :b | ] numArgs equals: 2
  120. !
  121. testOnDo
  122. self assert: ([ Error new signal ] on: Error do: [ :ex | true ])
  123. !
  124. testValue
  125. self assert: ([ 1+1 ] value) equals: 2.
  126. self assert: ([ :x | x +1 ] value: 2) equals: 3.
  127. self assert: ([ :x :y | x*y ] value: 2 value: 4) equals: 8.
  128. "Arguments are optional in Amber. This isn't ANSI compliant."
  129. self assert: ([ :a :b :c | 1 ] value) equals: 1
  130. !
  131. testValueWithPossibleArguments
  132. self assert: ([ 1 ] valueWithPossibleArguments: #(3 4)) equals: 1.
  133. self assert: ([ :a | a + 4 ] valueWithPossibleArguments: #(3 4)) equals: 7.
  134. self assert: ([ :a :b | a + b ] valueWithPossibleArguments: #(3 4 5)) equals: 7.
  135. !
  136. testWhileFalse
  137. | i |
  138. i := 0.
  139. [ i > 5 ] whileFalse: [ i := i + 1 ].
  140. self assert: i equals: 6.
  141. i := 0.
  142. [ i := i + 1. i > 5 ] whileFalse.
  143. self assert: i equals: 6
  144. !
  145. testWhileTrue
  146. | i |
  147. i := 0.
  148. [ i < 5 ] whileTrue: [ i := i + 1 ].
  149. self assert: i equals: 5.
  150. i := 0.
  151. [ i := i + 1. i < 5 ] whileTrue.
  152. self assert: i equals: 5
  153. ! !
  154. TestCase subclass: #BooleanTest
  155. instanceVariableNames: ''
  156. package: 'Kernel-Tests'!
  157. !BooleanTest methodsFor: 'tests'!
  158. testEquality
  159. "We're on top of JS...just be sure to check the basics!!"
  160. self deny: 0 = false.
  161. self deny: false = 0.
  162. self deny: '' = false.
  163. self deny: false = ''.
  164. self assert: (true = true).
  165. self deny: false = true.
  166. self deny: true = false.
  167. self assert: (false = false).
  168. "JS may do some type coercing after sending a message"
  169. self assert: (true yourself = true).
  170. self assert: (true yourself = true yourself)
  171. !
  172. testIdentity
  173. "We're on top of JS...just be sure to check the basics!!"
  174. self deny: 0 == false.
  175. self deny: false == 0.
  176. self deny: '' == false.
  177. self deny: false == ''.
  178. self assert: true == true.
  179. self deny: false == true.
  180. self deny: true == false.
  181. self assert: false == false.
  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. testIfTrueIfFalse
  187. self assert: (true ifTrue: [ 'alternative block' ]) equals: 'alternative block'.
  188. self assert: (true ifFalse: [ 'alternative block' ]) equals: nil.
  189. self assert: (false ifTrue: [ 'alternative block' ]) equals: nil.
  190. self assert: (false ifFalse: [ 'alternative block' ]) equals: 'alternative block'.
  191. self assert: (false ifTrue: [ 'alternative block' ] ifFalse: [ 'alternative block2' ]) equals: 'alternative block2'.
  192. self assert: (false ifFalse: [ 'alternative block' ] ifTrue: [ 'alternative block2' ]) equals: 'alternative block'.
  193. self assert: (true ifTrue: [ 'alternative block' ] ifFalse: [ 'alternative block2' ]) equals: 'alternative block'.
  194. self assert: (true ifFalse: [ 'alternative block' ] ifTrue: [ 'alternative block2' ]) equals: 'alternative block2'.
  195. !
  196. testIfTrueIfFalseWithBoxing
  197. self assert: (true yourself ifTrue: [ 'alternative block' ]) equals: 'alternative block'.
  198. self assert: (true yourself ifFalse: [ 'alternative block' ]) equals: nil.
  199. self assert: (false yourself ifTrue: [ 'alternative block' ]) equals: nil.
  200. self assert: (false yourself ifFalse: [ 'alternative block' ]) equals: 'alternative block'.
  201. self assert: (false yourself ifTrue: [ 'alternative block' ] ifFalse: [ 'alternative block2' ]) equals: 'alternative block2'.
  202. self assert: (false yourself ifFalse: [ 'alternative block' ] ifTrue: [ 'alternative block2' ]) equals: 'alternative block'.
  203. self assert: (true yourself ifTrue: [ 'alternative block' ] ifFalse: [ 'alternative block2' ]) equals: 'alternative block'.
  204. self assert: (true yourself ifFalse: [ 'alternative block' ] ifTrue: [ 'alternative block2' ]) equals: 'alternative block2'.
  205. !
  206. testLogic
  207. "Trivial logic table"
  208. self assert: (true & true);
  209. deny: (true & false);
  210. deny: (false & true);
  211. deny: (false & false).
  212. self assert: (true | true);
  213. assert: (true | false);
  214. assert: (false | true);
  215. deny: (false | false).
  216. "Checking that expressions work fine too"
  217. self assert: (true & (1 > 0));
  218. deny: ((1 > 0) & false);
  219. deny: ((1 > 0) & (1 > 2)).
  220. self assert: (false | (1 > 0));
  221. assert: ((1 > 0) | false);
  222. assert: ((1 > 0) | (1 > 2))
  223. !
  224. testLogicKeywords
  225. "Trivial logic table"
  226. self
  227. assert: (true and: [ true ]);
  228. deny: (true and: [ false ]);
  229. deny: (false and: [ true ]);
  230. deny: (false and: [ false ]).
  231. self
  232. assert: (true or: [ true ]);
  233. assert: (true or: [ false ]);
  234. assert: (false or: [ true ]);
  235. deny: (false or: [ false ]).
  236. "Checking that expressions work fine too"
  237. self
  238. assert: (true and: [ 1 > 0 ]);
  239. deny: ((1 > 0) and: [ false ]);
  240. deny: ((1 > 0) and: [ 1 > 2 ]).
  241. self
  242. assert: (false or: [ 1 > 0 ]);
  243. assert: ((1 > 0) or: [ false ]);
  244. assert: ((1 > 0) or: [ 1 > 2 ])
  245. !
  246. testNonBooleanError
  247. self should: [ '' ifTrue: [] ifFalse: [] ] raise: NonBooleanReceiver
  248. ! !
  249. TestCase subclass: #ClassBuilderTest
  250. instanceVariableNames: 'builder theClass'
  251. package: 'Kernel-Tests'!
  252. !ClassBuilderTest methodsFor: 'running'!
  253. setUp
  254. builder := ClassBuilder new
  255. !
  256. tearDown
  257. theClass ifNotNil: [ Smalltalk removeClass: theClass. theClass := nil ]
  258. ! !
  259. !ClassBuilderTest methodsFor: 'tests'!
  260. testClassCopy
  261. theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  262. self assert: theClass superclass == ObjectMock superclass.
  263. self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
  264. self assert: theClass name equals: 'ObjectMock2'.
  265. self assert: theClass package == ObjectMock package.
  266. self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
  267. !
  268. testClassMigration
  269. | instance oldClass |
  270. oldClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  271. instance := (Smalltalk globals at: 'ObjectMock2') new.
  272. "Change the superclass of ObjectMock2"
  273. ObjectMock subclass: (Smalltalk globals at: 'ObjectMock2')
  274. instanceVariableNames: ''
  275. package: 'Kernel-Tests'.
  276. self deny: oldClass == ObjectMock2.
  277. self assert: ObjectMock2 superclass == ObjectMock.
  278. self assert: ObjectMock2 instanceVariableNames isEmpty.
  279. self assert: ObjectMock2 selectors equals: oldClass selectors.
  280. self assert: ObjectMock2 comment equals: oldClass comment.
  281. self assert: ObjectMock2 package name equals: 'Kernel-Tests'.
  282. self deny: instance class == ObjectMock2.
  283. "Commeting this out. Tests implementation detail."
  284. "self assert: instance class name equals: 'OldObjectMock2'."
  285. self assert: (Smalltalk globals at: instance class name) isNil.
  286. Smalltalk removeClass: ObjectMock2
  287. !
  288. testClassMigrationWithClassInstanceVariables
  289. builder copyClass: ObjectMock named: 'ObjectMock2'.
  290. ObjectMock2 class instanceVariableNames: 'foo bar'.
  291. "Change the superclass of ObjectMock2"
  292. ObjectMock subclass: (Smalltalk globals at: 'ObjectMock2')
  293. instanceVariableNames: ''
  294. package: 'Kernel-Tests'.
  295. self assert: ObjectMock2 class instanceVariableNames equals: #('foo' 'bar').
  296. Smalltalk removeClass: ObjectMock2
  297. !
  298. testClassMigrationWithSubclasses
  299. builder copyClass: ObjectMock named: 'ObjectMock2'.
  300. ObjectMock2 subclass: 'ObjectMock3' instanceVariableNames: '' package: 'Kernel-Tests'.
  301. ObjectMock3 subclass: 'ObjectMock4' instanceVariableNames: '' package: 'Kernel-Tests'.
  302. "Change the superclass of ObjectMock2"
  303. ObjectMock subclass: (Smalltalk globals at: 'ObjectMock2')
  304. instanceVariableNames: ''
  305. package: 'Kernel-Tests'.
  306. self assert: (ObjectMock subclasses includes: ObjectMock2).
  307. self assert: (ObjectMock2 subclasses includes: ObjectMock3).
  308. self assert: (ObjectMock3 subclasses includes: ObjectMock4).
  309. ObjectMock allSubclasses do: [ :each | Smalltalk removeClass: each ]
  310. !
  311. testInstanceVariableNames
  312. self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
  313. ! !
  314. TestCase subclass: #CollectionTest
  315. instanceVariableNames: ''
  316. package: 'Kernel-Tests'!
  317. !CollectionTest methodsFor: 'convenience'!
  318. assertSameContents: aCollection as: anotherCollection
  319. self assert: (aCollection size = anotherCollection size).
  320. aCollection do: [ :each |
  321. self assert: ((aCollection occurrencesOf: each) = (anotherCollection occurrencesOf: each)) ]
  322. ! !
  323. !CollectionTest methodsFor: 'fixture'!
  324. collection
  325. "Answers pre-filled collection of type tested."
  326. self subclassResponsibility
  327. !
  328. collectionClass
  329. "Answers class of collection type tested"
  330. ^ self class collectionClass
  331. !
  332. collectionOfPrintStrings
  333. "Answers self collection but with values
  334. changed to their printStrings"
  335. self subclassResponsibility
  336. !
  337. collectionSize
  338. "Answers size of self collection."
  339. self subclassResponsibility
  340. !
  341. collectionWithDuplicates
  342. "Answers pre-filled collection of type tested,
  343. with exactly five distinct elements,
  344. some of them appearing multiple times, if possible."
  345. self subclassResponsibility
  346. !
  347. collectionWithNewValue
  348. "Answers a collection which shows how
  349. self collection would look after adding
  350. self sampleNewValue"
  351. self subclassResponsibility
  352. !
  353. sampleNewValue
  354. "Answers a value that is not yet there
  355. and can be put into a tested collection"
  356. ^ 'N'
  357. !
  358. sampleNewValueAsCollection
  359. "Answers self sampleNewValue
  360. wrapped in single element collection
  361. of tested type"
  362. ^ self collectionClass with: self sampleNewValue
  363. ! !
  364. !CollectionTest methodsFor: 'testing'!
  365. isCollectionReadOnly
  366. ^ false
  367. ! !
  368. !CollectionTest methodsFor: 'tests'!
  369. testAddAll
  370. self assert: (self collection addAll: self collectionClass new; yourself) equals: self collection.
  371. self assert: (self collectionClass new addAll: self collection; yourself) equals: self collection.
  372. self assert: (self collectionClass new addAll: self collectionClass new; yourself) equals: self collectionClass new.
  373. self assert: (self collection addAll: self sampleNewValueAsCollection; yourself) equals: self collectionWithNewValue.
  374. self assertSameContents: (self sampleNewValueAsCollection addAll: self collection; yourself) as: self collectionWithNewValue
  375. !
  376. testAllSatisfy
  377. | collection anyOne |
  378. collection := self collection.
  379. anyOne := collection anyOne.
  380. self assert: (collection allSatisfy: [ :each | collection includes: each ]).
  381. self deny: (collection allSatisfy: [ :each | each ~= anyOne ])
  382. !
  383. testAnyOne
  384. self should: [ self collectionClass new anyOne ] raise: Error.
  385. self assert: (self collection includes: self collection anyOne)
  386. !
  387. testAnySatisfy
  388. | anyOne |
  389. anyOne := self collection anyOne.
  390. self assert: (self collection anySatisfy: [ :each | each = anyOne ]).
  391. self deny: (self collection anySatisfy: [ :each | each = Object new ])
  392. !
  393. testAsArray
  394. self
  395. assertSameContents: self collection
  396. as: self collection asArray
  397. !
  398. testAsOrderedCollection
  399. self
  400. assertSameContents: self collection
  401. as: self collection asOrderedCollection
  402. !
  403. testAsSet
  404. | c set |
  405. c := self collectionWithDuplicates.
  406. set := c asSet.
  407. self assert: set size equals: 5.
  408. c do: [ :each |
  409. self assert: (set includes: each) ]
  410. !
  411. testCollect
  412. self assert: (self collection collect: [ :each | each ]) equals: self collection.
  413. self assert: (self collectionWithNewValue collect: [ :each | each ]) equals: self collectionWithNewValue.
  414. self assert: (self collectionClass new collect: [ :each | each printString ]) equals: self collectionClass new.
  415. self assert: ((self collection collect: [ self sampleNewValue ]) detect: [ true ]) equals: self sampleNewValue.
  416. self assert: (self collection collect: [ :each | each printString ]) equals: self collectionOfPrintStrings
  417. !
  418. testComma
  419. self assert: self collection, self collectionClass new equals: self collection.
  420. self assert: self collectionClass new, self collection equals: self collection.
  421. self assert: self collectionClass new, self collectionClass new equals: self collectionClass new.
  422. self assert: self collection, self sampleNewValueAsCollection equals: self collectionWithNewValue.
  423. self assertSameContents: self sampleNewValueAsCollection, self collection as: self collectionWithNewValue
  424. !
  425. testDetect
  426. self
  427. shouldnt: [ self collection detect: [ true ] ]
  428. raise: Error.
  429. self
  430. should: [ self collection detect: [ false ] ]
  431. raise: Error.
  432. self assert: (self sampleNewValueAsCollection detect: [ true ]) equals: self sampleNewValue.
  433. self assert: (self collectionWithNewValue detect: [ :each | each = self sampleNewValue ]) equals: self sampleNewValue.
  434. self
  435. should: [ self collection detect: [ :each | each = self sampleNewValue ] ]
  436. raise: Error
  437. !
  438. testDetectIfNone
  439. | sentinel |
  440. sentinel := Object new.
  441. self assert: (self collection detect: [ true ] ifNone: [ sentinel ]) ~= sentinel.
  442. self assert: (self collection detect: [ false ] ifNone: [ sentinel ]) equals: sentinel.
  443. self assert: (self sampleNewValueAsCollection detect: [ true ] ifNone: [ sentinel ]) equals: self sampleNewValue.
  444. self assert: (self collectionWithNewValue detect: [ :each | each = self sampleNewValue ] ifNone: [ sentinel ]) equals: self sampleNewValue.
  445. self assert: (self collection detect: [ :each | each = self sampleNewValue ] ifNone: [ sentinel ]) equals: sentinel
  446. !
  447. testDo
  448. | newCollection |
  449. newCollection := OrderedCollection new.
  450. self collection do: [ :each |
  451. newCollection add: each ].
  452. self
  453. assertSameContents: self collection
  454. as: newCollection.
  455. newCollection := OrderedCollection new.
  456. self collectionWithDuplicates do: [ :each |
  457. newCollection add: each ].
  458. self
  459. assertSameContents: self collectionWithDuplicates
  460. as: newCollection
  461. !
  462. testIfEmptyFamily
  463. self assert: (self collectionClass new ifEmpty: [ 42 ]) equals: 42.
  464. self assert: (self collection ifEmpty: [ 42 ]) equals: self collection.
  465. self assert: (self collectionClass new ifNotEmpty: [ 42 ]) equals: self collectionClass new.
  466. self assert: (self collection ifNotEmpty: [ 42 ]) equals: 42.
  467. self assert: (self collection ifNotEmpty: [ :col | col ]) equals: self collection.
  468. self assert: (self collectionClass new ifEmpty: [ 42 ] ifNotEmpty: [ 999 ]) equals: 42.
  469. self assert: (self collection ifEmpty: [ 42 ] ifNotEmpty: [ 999 ]) equals: 999.
  470. self assert: (self collection ifEmpty: [ 42 ] ifNotEmpty: [ :col | col ]) equals: self collection.
  471. self assert: (self collectionClass new ifNotEmpty: [ 42 ] ifEmpty: [ 999 ]) equals: 999.
  472. self assert: (self collection ifNotEmpty: [ 42 ] ifEmpty: [ 999 ]) equals: 42.
  473. self assert: (self collection ifNotEmpty: [ :col | col ] ifEmpty: [ 999 ]) equals: self collection.
  474. !
  475. testIsEmpty
  476. self assert: self collectionClass new isEmpty.
  477. self deny: self collection isEmpty
  478. !
  479. testNoneSatisfy
  480. | anyOne |
  481. anyOne := self collection anyOne.
  482. self deny: (self collection noneSatisfy: [ :each | each = anyOne ]).
  483. self assert: (self collection noneSatisfy: [ :each | each = Object new ])
  484. !
  485. testRemoveAll
  486. self assert: (self collection removeAll; yourself) equals: self collectionClass new
  487. !
  488. testSelect
  489. self assert: (self collection select: [ false ]) equals: self collectionClass new.
  490. self assert: (self collection select: [ true ]) equals: self collection.
  491. self assert: (self collectionWithNewValue select: [ :each | each = self sampleNewValue ]) equals: self sampleNewValueAsCollection.
  492. self assert: (self collectionWithNewValue select: [ :each | each ~= self sampleNewValue ]) equals: self collection.
  493. self assert: (self collection select: [ :each | each = self sampleNewValue ]) equals: self collectionClass new.
  494. self assert: (self collectionWithNewValue select: [ :each | each ~= self sampleNewValue ]) equals: self collection
  495. !
  496. testSize
  497. self assert: self collectionClass new size equals: 0.
  498. self assert: self sampleNewValueAsCollection size equals: 1.
  499. self assert: self collection size equals: self collectionSize
  500. ! !
  501. !CollectionTest class methodsFor: 'fixture'!
  502. collectionClass
  503. "Answers class of collection type tested,
  504. or nil if test is abstract"
  505. ^ nil
  506. ! !
  507. !CollectionTest class methodsFor: 'testing'!
  508. isAbstract
  509. ^ self collectionClass isNil
  510. ! !
  511. CollectionTest subclass: #IndexableCollectionTest
  512. instanceVariableNames: ''
  513. package: 'Kernel-Tests'!
  514. !IndexableCollectionTest methodsFor: 'fixture'!
  515. collectionWithNewValue
  516. "Answers a collection which shows how
  517. self collection would look after adding
  518. self sampleNewValue at self sampleNewIndex"
  519. self subclassResponsibility
  520. !
  521. sampleNewIndex
  522. "Answers a value that can be used as index in at:put: or at:ifAbsentPut:"
  523. self subclassResponsibility
  524. !
  525. sampleNonIndexesDo: aBlock
  526. "Executes block a few times,
  527. each time passing value that is known
  528. not to be an index, as the first parameter"
  529. self subclassResponsibility
  530. !
  531. samplesDo: aBlock
  532. "Executes block a few times,
  533. each time passing known index and value stored
  534. under that index as the parameters"
  535. self subclassResponsibility
  536. ! !
  537. !IndexableCollectionTest methodsFor: 'tests'!
  538. testAt
  539. self nonIndexesDo: [ :each |
  540. self should: [ self collection at: each ] raise: Error ].
  541. self samplesDo: [ :index :value |
  542. self assert: (self collection at: index) equals: value ]
  543. !
  544. testAtIfAbsent
  545. self nonIndexesDo: [ :each |
  546. self assert: (self collection at: each ifAbsent: [ self sampleNewValue ]) equals: self sampleNewValue ].
  547. self samplesDo: [ :index :value |
  548. self assert: (self collection at: index ifAbsent: [ self sampleNewValue ]) equals: value ].
  549. !
  550. testAtIfAbsentPut
  551. | newCollection |
  552. newCollection := self collection.
  553. self samplesDo: [ :index :value |
  554. self assert: (newCollection at: index ifAbsentPut: [ self sampleNewValue ]) equals: value ].
  555. self assert: newCollection equals: self collection.
  556. self assert: (newCollection at: self sampleNewIndex ifAbsentPut: [ self sampleNewValue ]) equals: self sampleNewValue.
  557. self assert: newCollection equals: self collectionWithNewValue
  558. !
  559. testAtIfPresent
  560. | visited sentinel |
  561. sentinel := Object new.
  562. self nonIndexesDo: [ :each |
  563. visited := nil.
  564. self assert: (self collection at: each ifPresent: [ :value1 | visited := value1. sentinel ]) equals: nil.
  565. self assert: visited isNil ].
  566. self samplesDo: [ :index :value |
  567. visited := nil.
  568. self assert: (self collection at: index ifPresent: [ :value2 | visited := value2. sentinel ]) equals: sentinel.
  569. self assert: visited equals: (self collection at: index) ]
  570. !
  571. testAtIfPresentIfAbsent
  572. | visited sentinel |
  573. sentinel := Object new.
  574. self nonIndexesDo: [ :each |
  575. visited := nil.
  576. self assert: (self collection at: each ifPresent: [ :value1 | visited := value1. sentinel ] ifAbsent: [ self sampleNewValue ] ) equals: self sampleNewValue.
  577. self assert: visited isNil ].
  578. self samplesDo: [ :index :value |
  579. visited := nil.
  580. self assert: (self collection at: index ifPresent: [ :value2 | visited := value2. sentinel ] ifAbsent: [ self sampleNewValue ]) equals: sentinel.
  581. self assert: visited equals: (self collection at: index) ]
  582. !
  583. testAtPut
  584. | newCollection |
  585. newCollection := self collection.
  586. self samplesDo: [ :index :value |
  587. newCollection at: index put: value ].
  588. self assert: newCollection equals: self collection.
  589. newCollection at: self sampleNewIndex put: self sampleNewValue.
  590. self assert: newCollection equals: self collectionWithNewValue
  591. !
  592. testEquality
  593. self assert: self collectionClass new equals: self collectionClass new.
  594. self assert: self collection equals: self collection.
  595. self assert: self collectionWithNewValue equals: self collectionWithNewValue.
  596. self deny: self collectionClass new = self collection.
  597. self deny: self collection = self collectionClass new
  598. !
  599. testIndexOf
  600. self should: [ self collection indexOf: self sampleNewValue ] raise: Error.
  601. self samplesDo: [ :index :value |
  602. self assert: (self collection indexOf: value) equals: index ]
  603. !
  604. testIndexOfWithNull
  605. | jsNull |
  606. jsNull := JSON parse: 'null'.
  607. self samplesDo: [ :index :value |
  608. self assert: (self collection at: index put: jsNull; indexOf: jsNull) equals: index ]
  609. !
  610. testWithIndexDo
  611. | collection |
  612. collection := self collection.
  613. self collection withIndexDo: [ :each :index |
  614. self assert: (collection at: index) equals: each ]
  615. ! !
  616. IndexableCollectionTest subclass: #AssociativeCollectionTest
  617. instanceVariableNames: ''
  618. package: 'Kernel-Tests'!
  619. !AssociativeCollectionTest methodsFor: 'fixture'!
  620. collectionKeys
  621. self subclassResponsibility
  622. !
  623. collectionValues
  624. self subclassResponsibility
  625. !
  626. nonIndexesDo: aBlock
  627. aBlock value: 5.
  628. aBlock value: 'z'
  629. !
  630. sampleNewIndex
  631. ^ 'new'
  632. !
  633. samplesDo: aBlock
  634. aBlock value: 'a' value: 2
  635. ! !
  636. !AssociativeCollectionTest methodsFor: 'tests'!
  637. testAddAll
  638. super testAddAll.
  639. self assert: (self collection addAll: self collection; yourself) equals: self collection.
  640. self assert: (self collection addAll: self collectionWithNewValue; yourself) equals: self collectionWithNewValue.
  641. self assert: (self collectionWithNewValue addAll: self collection; yourself) equals: self collectionWithNewValue
  642. !
  643. testAsDictionary
  644. self assert: ( self collectionClass new asDictionary isMemberOf: Dictionary ).
  645. !
  646. testAsHashedCollection
  647. self assert: ( self collectionClass new asHashedCollection isMemberOf: HashedCollection ).
  648. !
  649. testComma
  650. super testComma.
  651. self assert: self collection, self collection equals: self collection.
  652. self assert: self collection, self collectionWithNewValue equals: self collectionWithNewValue.
  653. self assert: self collectionWithNewValue, self collection equals: self collectionWithNewValue
  654. !
  655. testFrom
  656. "Accept a collection of associations."
  657. | associations |
  658. associations := { 'a' -> 1. 'b' -> 2 }.
  659. self assertSameContents: ( self class collectionClass from: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.
  660. !
  661. testKeys
  662. self assert:self collectionClass new keys isEmpty.
  663. self assertSameContents:self collection keys as: self collectionKeys.
  664. self assertSameContents:self collectionWithNewValue keys as: self collectionKeys, { self sampleNewIndex }
  665. !
  666. testNewFromPairs
  667. "Accept an array in which all odd indexes are keys and evens are values."
  668. | flattenedAssociations |
  669. flattenedAssociations := { 'a'. 1. 'b'. 2 }.
  670. self assertSameContents: ( self class collectionClass newFromPairs: flattenedAssociations ) as: #{ 'a' -> 1. 'b' -> 2 }.
  671. !
  672. testPrintString
  673. self
  674. assert: (self collectionClass new
  675. at:'firstname' put: 'James';
  676. at:'lastname' put: 'Bond';
  677. printString)
  678. equals: 'a ', self collectionClass name, ' (''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  679. !
  680. testRemoveKey
  681. self nonIndexesDo: [ :each |
  682. | collection |
  683. collection := self collection.
  684. self should: [ collection removeKey: each ] raise: Error.
  685. self assert: collection equals: self collection ].
  686. self samplesDo: [ :index :value |
  687. | collection |
  688. collection := self collection.
  689. self assert: (collection removeKey: index) equals: value.
  690. self deny: collection = self collection ].
  691. self
  692. assert: (self collectionWithNewValue removeKey: self sampleNewIndex; yourself)
  693. equals: self collection
  694. !
  695. testRemoveKeyIfAbsent
  696. self nonIndexesDo: [ :each |
  697. | collection |
  698. collection := self collection.
  699. self assert: (collection removeKey: each ifAbsent: [ self sampleNewValue ]) equals: self sampleNewValue.
  700. self assert: collection equals: self collection ].
  701. self samplesDo: [ :index :value |
  702. | collection |
  703. collection := self collection.
  704. self assert: (collection removeKey: index ifAbsent: [ self sampleNewValue ]) equals: value.
  705. self deny: collection = self collection ].
  706. self
  707. assert: (self collectionWithNewValue removeKey: self sampleNewIndex ifAbsent: [ self assert: false ]; yourself)
  708. equals: self collection
  709. !
  710. testValues
  711. self assert:self collectionClass new values isEmpty.
  712. self assertSameContents:self collection values as: self collectionValues.
  713. self assertSameContents:self collectionWithNewValue values as: self collectionValues, { self sampleNewValue }
  714. ! !
  715. AssociativeCollectionTest subclass: #DictionaryTest
  716. instanceVariableNames: ''
  717. package: 'Kernel-Tests'!
  718. !DictionaryTest methodsFor: 'fixture'!
  719. collection
  720. ^ Dictionary new
  721. at: 1 put: 1;
  722. at: 'a' put: 2;
  723. at: true put: 3;
  724. at: 1@3 put: -4;
  725. yourself
  726. !
  727. collectionKeys
  728. ^ {1. 'a'. true. 1@3}
  729. !
  730. collectionOfPrintStrings
  731. ^ Dictionary new
  732. at: 1 put: '1';
  733. at: 'a' put: '2';
  734. at: true put: '3';
  735. at: 1@3 put: '-4';
  736. yourself
  737. !
  738. collectionSize
  739. ^ 4
  740. !
  741. collectionValues
  742. ^ {1. 2. 3. -4}
  743. !
  744. collectionWithDuplicates
  745. ^ Dictionary new
  746. at: 1 put: 1;
  747. at: 'a' put: 2;
  748. at: true put: 3;
  749. at: 4 put: -4;
  750. at: 'b' put: 1;
  751. at: 3 put: 3;
  752. at: false put: 12;
  753. yourself
  754. !
  755. collectionWithNewValue
  756. ^ Dictionary new
  757. at: 1 put: 1;
  758. at: 'a' put: 2;
  759. at: true put: 3;
  760. at: 1@3 put: -4;
  761. at: 'new' put: 'N';
  762. yourself
  763. !
  764. sampleNewValueAsCollection
  765. ^ Dictionary new
  766. at: 'new' put: 'N';
  767. yourself
  768. !
  769. samplesDo: aBlock
  770. super samplesDo: aBlock.
  771. aBlock value: true value: 3.
  772. aBlock value: 1@3 value: -4
  773. ! !
  774. !DictionaryTest methodsFor: 'tests'!
  775. testAccessing
  776. | d |
  777. d := Dictionary new.
  778. d at: 'hello' put: 'world'.
  779. self assert: (d at: 'hello') equals: 'world'.
  780. self assert: (d at: 'hello' ifAbsent: [ nil ]) equals: 'world'.
  781. self deny: (d at: 'foo' ifAbsent: [ nil ]) = 'world'.
  782. self assert: (d includesKey: 'hello').
  783. self deny: (d includesKey: 'foo').
  784. d at: 1 put: 2.
  785. self assert: (d at: 1) equals: 2.
  786. d at: 1@3 put: 3.
  787. self assert: (d at: 1@3) equals: 3.
  788. self assert: (d includesKey: 1@3).
  789. self deny: (d includesKey: 3@1)
  790. !
  791. testDynamicDictionaries
  792. self assert: #{'hello' -> 1} asDictionary equals: (Dictionary with: 'hello' -> 1)
  793. ! !
  794. !DictionaryTest class methodsFor: 'fixture'!
  795. collectionClass
  796. ^ Dictionary
  797. ! !
  798. AssociativeCollectionTest subclass: #HashedCollectionTest
  799. instanceVariableNames: ''
  800. package: 'Kernel-Tests'!
  801. !HashedCollectionTest methodsFor: 'fixture'!
  802. collection
  803. ^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4 }
  804. !
  805. collectionKeys
  806. ^ { 'b'. 'a'. 'c'. 'd' }
  807. !
  808. collectionOfPrintStrings
  809. ^ #{ 'b' -> '1'. 'a' -> '2'. 'c' -> '3'. 'd' -> '-4' }
  810. !
  811. collectionSize
  812. ^ 4
  813. !
  814. collectionValues
  815. ^ { 1. 2. 3. -4 }
  816. !
  817. collectionWithDuplicates
  818. ^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4. 'e' -> 1. 'f' -> 2. 'g' -> 10 }
  819. !
  820. collectionWithNewValue
  821. ^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4. 'new' -> 'N' }
  822. !
  823. sampleNewValueAsCollection
  824. ^ #{ 'new' -> 'N' }
  825. ! !
  826. !HashedCollectionTest methodsFor: 'tests'!
  827. testDynamicDictionaries
  828. self assert: #{'hello' -> 1} asHashedCollection equals: (HashedCollection with: 'hello' -> 1)
  829. ! !
  830. !HashedCollectionTest class methodsFor: 'fixture'!
  831. collectionClass
  832. ^ HashedCollection
  833. ! !
  834. IndexableCollectionTest subclass: #SequenceableCollectionTest
  835. instanceVariableNames: ''
  836. package: 'Kernel-Tests'!
  837. !SequenceableCollectionTest methodsFor: 'fixture'!
  838. collectionFirst
  839. self subclassResponsibility
  840. !
  841. collectionFirstTwo
  842. self subclassResponsibility
  843. !
  844. collectionLast
  845. self subclassResponsibility
  846. !
  847. collectionLastTwo
  848. self subclassResponsibility
  849. !
  850. nonIndexesDo: aBlock
  851. aBlock value: 0.
  852. aBlock value: self collectionSize + 1.
  853. aBlock value: 'z'
  854. !
  855. samplesDo: aBlock
  856. aBlock value: 1 value: self collectionFirst.
  857. aBlock value: self collectionSize value: self collectionLast
  858. ! !
  859. !SequenceableCollectionTest methodsFor: 'tests'!
  860. testBeginsWith
  861. self assert: (self collection beginsWith: self collectionClass new).
  862. self assert: (self collection beginsWith: self collection).
  863. self assert: (self collection beginsWith: self collectionFirstTwo).
  864. self deny: (self collection beginsWith: self collectionLastTwo)
  865. !
  866. testEndsWith
  867. self assert: (self collection endsWith: self collectionClass new).
  868. self assert: (self collection endsWith: self collection).
  869. self assert: (self collection endsWith: self collectionLastTwo).
  870. self deny: (self collection endsWith: self collectionFirstTwo)
  871. !
  872. testFirst
  873. self assert: self collection first equals: self collectionFirst
  874. !
  875. testFirstN
  876. self
  877. assert: (self collection first: 2)
  878. equals: self collectionFirstTwo.
  879. self
  880. assert: (self collection first: 0)
  881. equals: self collectionClass new.
  882. self
  883. assert: (self collection first: self collectionSize)
  884. equals: self collection.
  885. self should: [ self collection first: 33 ] raise: Error
  886. !
  887. testFourth
  888. self assert: (self collection fourth) equals: (self collection at: 4)
  889. !
  890. testIndexOfStartingAt
  891. | jsNull |
  892. jsNull := JSON parse: 'null'.
  893. self samplesDo: [ :index :value |
  894. self assert: (self collection indexOf: value startingAt: 1) equals: index.
  895. self assert: (self collection indexOf: value startingAt: index) equals: index.
  896. self assert: (self collection indexOf: value startingAt: index+1) equals: 0 ]
  897. !
  898. testIndexOfStartingAtWithNull
  899. | jsNull |
  900. jsNull := JSON parse: 'null'.
  901. self samplesDo: [ :index :value | | collection |
  902. collection := self collection.
  903. collection at: index put: jsNull.
  904. self assert: (collection indexOf: jsNull startingAt: 1) equals: index.
  905. self assert: (collection indexOf: jsNull startingAt: index) equals: index.
  906. self assert: (collection indexOf: jsNull startingAt: index+1) equals: 0 ]
  907. !
  908. testLast
  909. self assert: self collection last equals: self collectionLast
  910. !
  911. testLastN
  912. self
  913. assert: (self collection last: 2)
  914. equals: self collectionLastTwo.
  915. self
  916. assert: (self collection last: 0)
  917. equals: self collectionClass new.
  918. self
  919. assert: (self collection last: self collectionSize)
  920. equals: self collection.
  921. self should: [ self collection last: 33 ] raise: Error
  922. !
  923. testSecond
  924. self assert: (self collection second) equals: (self collection at: 2)
  925. !
  926. testThird
  927. self assert: (self collection third) equals: (self collection at: 3)
  928. ! !
  929. SequenceableCollectionTest subclass: #ArrayTest
  930. instanceVariableNames: ''
  931. package: 'Kernel-Tests'!
  932. !ArrayTest methodsFor: 'fixture'!
  933. collection
  934. ^ #(1 2 3 -4)
  935. !
  936. collectionFirst
  937. ^ 1
  938. !
  939. collectionFirstTwo
  940. ^ #(1 2)
  941. !
  942. collectionLast
  943. ^ -4
  944. !
  945. collectionLastTwo
  946. ^ #(3 -4)
  947. !
  948. collectionOfPrintStrings
  949. ^ #('1' '2' '3' '-4')
  950. !
  951. collectionSize
  952. ^ 4
  953. !
  954. collectionWithDuplicates
  955. ^ #('a' 'b' 'c' 1 2 1 'a')
  956. !
  957. collectionWithNewValue
  958. ^ #(1 2 3 -4 'N')
  959. !
  960. sampleNewIndex
  961. ^ 5
  962. !
  963. samplesDo: aBlock
  964. super samplesDo: aBlock.
  965. aBlock value: 3 value: 3.
  966. ! !
  967. !ArrayTest methodsFor: 'tests'!
  968. testAdd
  969. | array |
  970. array := self collection.
  971. array add: 6.
  972. self assert: array last equals: 6
  973. !
  974. testAddFirst
  975. self assert: (self collection addFirst: 0; yourself) first equals: 0
  976. !
  977. testPrintString
  978. | array |
  979. array := Array new.
  980. self assert: array printString equals: 'an Array ()'.
  981. array add: 1; add: 3.
  982. self assert: array printString equals: 'an Array (1 3)'.
  983. array add: 'foo'.
  984. self assert: array printString equals: 'an Array (1 3 ''foo'')'.
  985. array remove: 1; remove: 3.
  986. self assert: array printString equals: 'an Array (''foo'')'.
  987. array addLast: 3.
  988. self assert: array printString equals: 'an Array (''foo'' 3)'.
  989. array addLast: 3.
  990. self assert: array printString equals: 'an Array (''foo'' 3 3)'.
  991. !
  992. testRemove
  993. | array |
  994. array := #(1 2 3 4 5).
  995. array remove: 3.
  996. self assert: array equals: #(1 2 4 5).
  997. self should: [ array remove: 3 ] raise: Error
  998. !
  999. testRemoveFromTo
  1000. self assert: (#(1 2 3 4) removeFrom: 1 to: 3) equals: #(4).
  1001. self assert: (#(1 2 3 4) removeFrom: 2 to: 3) equals: #(1 4).
  1002. self assert: (#(1 2 3 4) removeFrom: 2 to: 4) equals: #(1)
  1003. !
  1004. testRemoveIndex
  1005. self assert: (#(1 2 3 4) removeIndex: 2) equals: #(1 3 4).
  1006. self assert: (#(1 2 3 4) removeIndex: 1) equals: #(2 3 4).
  1007. self assert: (#('hello') removeIndex: 1) equals: #()
  1008. !
  1009. testRemoveLast
  1010. | array |
  1011. array := #(1 2).
  1012. array removeLast.
  1013. self assert: array last equals: 1
  1014. !
  1015. testReversed
  1016. |array|
  1017. array := #(5 4 3 2 1).
  1018. self assert: (array reversed) equals: #(1 2 3 4 5)
  1019. !
  1020. testSort
  1021. | array |
  1022. array := #(10 1 5).
  1023. array sort.
  1024. self assert: array equals: #(1 5 10)
  1025. ! !
  1026. !ArrayTest class methodsFor: 'fixture'!
  1027. collectionClass
  1028. ^ Array
  1029. ! !
  1030. SequenceableCollectionTest subclass: #StringTest
  1031. instanceVariableNames: ''
  1032. package: 'Kernel-Tests'!
  1033. !StringTest methodsFor: 'fixture'!
  1034. collection
  1035. ^ 'helLo'
  1036. !
  1037. collectionFirst
  1038. ^ 'h'
  1039. !
  1040. collectionFirstTwo
  1041. ^ 'he'
  1042. !
  1043. collectionLast
  1044. ^ 'o'
  1045. !
  1046. collectionLastTwo
  1047. ^ 'Lo'
  1048. !
  1049. collectionOfPrintStrings
  1050. ^ '''h''''e''''l''''L''''o'''
  1051. !
  1052. collectionSize
  1053. ^ 5
  1054. !
  1055. collectionWithDuplicates
  1056. ^ 'abbaerte'
  1057. !
  1058. collectionWithNewValue
  1059. ^ 'helLoN'
  1060. !
  1061. sampleNewValueAsCollection
  1062. ^ 'N'
  1063. !
  1064. samplesDo: aBlock
  1065. super samplesDo: aBlock.
  1066. aBlock value: 3 value: 'l'
  1067. ! !
  1068. !StringTest methodsFor: 'tests'!
  1069. testAddAll
  1070. "String instances are read-only"
  1071. self should: [ self collection addAll: self collection ] raise: Error
  1072. !
  1073. testAddRemove
  1074. self should: [ 'hello' add: 'a' ] raise: Error.
  1075. self should: [ 'hello' remove: 'h' ] raise: Error
  1076. !
  1077. testAsArray
  1078. self assert: 'hello' asArray equals: #('h' 'e' 'l' 'l' 'o').
  1079. !
  1080. testAsLowerCase
  1081. self assert: 'JACKIE' asLowercase equals: 'jackie'.
  1082. !
  1083. testAsNumber
  1084. self assert: '3' asNumber equals: 3.
  1085. self assert: '-3' asNumber equals: -3.
  1086. self assert: '-1.5' asNumber equals: -1.5.
  1087. !
  1088. testAsUpperCase
  1089. self assert: 'jackie' asUppercase equals: 'JACKIE'.
  1090. !
  1091. testAsciiValue
  1092. | characterA characterU |
  1093. characterA := 'A'.
  1094. characterU := 'U'.
  1095. self assert: (characterA asciiValue) equals:65.
  1096. self assert: (characterU asciiValue) equals:85
  1097. !
  1098. testAtIfAbsentPut
  1099. "String instances are read-only"
  1100. self should: [ 'hello' at: 6 ifAbsentPut: [ 'a' ] ] raise: Error
  1101. !
  1102. testAtPut
  1103. "String instances are read-only"
  1104. self should: [ 'hello' at: 1 put: 'a' ] raise: Error
  1105. !
  1106. testCapitalized
  1107. self assert: 'test' capitalized equals: 'Test'.
  1108. self assert: 'Test' capitalized equals: 'Test'.
  1109. self assert: '' capitalized equals: ''.
  1110. self assert: 'Test' isCapitalized equals: true.
  1111. self assert: 'test' isCapitalized equals: false.
  1112. !
  1113. testCharCodeAt
  1114. self assert: ('jackie' charCodeAt:1) equals: 106.
  1115. self assert: ('jackie' charCodeAt:2) equals: 97.
  1116. self assert: ('jackie' charCodeAt:3) equals: 99.
  1117. self assert: ('jackie' charCodeAt:4) equals: 107.
  1118. self assert: ('jackie' charCodeAt:5) equals: 105.
  1119. self assert: ('jackie' charCodeAt:6) equals: 101
  1120. !
  1121. testCopyFromTo
  1122. self assert: ('jackie' copyFrom: 1 to: 3) equals: 'jac'.
  1123. self assert: ('jackie' copyFrom: 4 to: 6) equals: 'kie'.
  1124. !
  1125. testCopyWithoutAll
  1126. self
  1127. assert: ('*hello* *world*' copyWithoutAll: '*')
  1128. equals: 'hello world'
  1129. !
  1130. testEquality
  1131. self assert: 'hello' equals: 'hello'.
  1132. self deny: 'hello' = 'world'.
  1133. "Test for issue 459"
  1134. self deny: 'hello' = (#() at: 1 ifAbsent: [ ]).
  1135. self assert: 'hello' equals: 'hello' yourself.
  1136. self assert: 'hello' yourself equals: 'hello'.
  1137. "test JS falsy value"
  1138. self deny: '' = 0
  1139. !
  1140. testIdentity
  1141. self assert: 'hello' == 'hello'.
  1142. self deny: 'hello' == 'world'.
  1143. self assert: 'hello' == 'hello' yourself.
  1144. self assert: 'hello' yourself == 'hello'.
  1145. "test JS falsy value"
  1146. self deny: '' == 0
  1147. !
  1148. testIdentityHash
  1149. self assert: 'foo' identityHash equals: 'foo' identityHash.
  1150. self deny: ('foo' identityHash = 'bar' identityHash)
  1151. !
  1152. testIncludesSubString
  1153. self assert: ('amber' includesSubString: 'ber').
  1154. self deny: ('amber' includesSubString: 'zork').
  1155. !
  1156. testIndexOfStartingAtWithNull
  1157. "String cannot hold JS null"
  1158. !
  1159. testIndexOfWithNull
  1160. "String cannot hold JS null"
  1161. !
  1162. testIsVowel
  1163. |vowel consonant|
  1164. vowel := 'u'.
  1165. consonant := 'z'.
  1166. self assert: vowel isVowel equals: true.
  1167. self assert: consonant isVowel equals: false
  1168. !
  1169. testJoin
  1170. self assert: (',' join: #('hello' 'world')) equals: 'hello,world'
  1171. !
  1172. testRemoveAll
  1173. self should: [ self collection removeAll ] raise: Error
  1174. !
  1175. testReversed
  1176. self assert: 'jackiechan' reversed equals: 'nahceikcaj'.
  1177. !
  1178. testStreamContents
  1179. self
  1180. assert: (String streamContents: [ :aStream |
  1181. aStream
  1182. nextPutAll: 'hello'; space;
  1183. nextPutAll: 'world' ])
  1184. equals: 'hello world'
  1185. !
  1186. testSubStrings
  1187. self assert: ('jackiechan' subStrings: 'ie') equals: #( 'jack' 'chan' ).
  1188. !
  1189. testTrim
  1190. self assert: ' jackie' trimLeft equals: 'jackie'.
  1191. self assert: 'jackie ' trimRight equals: 'jackie'.
  1192. !
  1193. testValue
  1194. self assert: (#asString value: 1) equals: '1'.
  1195. "Which (since String and BlockClosure are now polymorphic) enables the nice idiom..."
  1196. self assert: (#(1 2 3) collect: #asString) equals: #('1' '2' '3')
  1197. ! !
  1198. !StringTest class methodsFor: 'fixture'!
  1199. collectionClass
  1200. ^ String
  1201. ! !
  1202. CollectionTest subclass: #SetTest
  1203. instanceVariableNames: ''
  1204. package: 'Kernel-Tests'!
  1205. !SetTest methodsFor: 'fixture'!
  1206. collection
  1207. ^ Set new
  1208. add: Smalltalk;
  1209. add: nil;
  1210. add: 3@3;
  1211. add: false;
  1212. yourself
  1213. !
  1214. collectionOfPrintStrings
  1215. ^ Set new
  1216. add: 'a SmalltalkImage';
  1217. add: 'nil';
  1218. add: '3@3';
  1219. add: 'false';
  1220. yourself
  1221. !
  1222. collectionSize
  1223. ^ 4
  1224. !
  1225. collectionWithDuplicates
  1226. "Set has no duplicates"
  1227. ^ self collection add: 0; yourself
  1228. !
  1229. collectionWithNewValue
  1230. ^ Set new
  1231. add: Smalltalk;
  1232. add: nil;
  1233. add: 3@3;
  1234. add: 'N';
  1235. add: false;
  1236. yourself
  1237. ! !
  1238. !SetTest methodsFor: 'tests'!
  1239. testAddAll
  1240. super testAddAll.
  1241. self assert: (self collection addAll: self collection; yourself) equals: self collection.
  1242. self assert: (self collection addAll: self collectionWithNewValue; yourself) equals: self collectionWithNewValue.
  1243. self assert: (self collectionWithNewValue addAll: self collection; yourself) equals: self collectionWithNewValue
  1244. !
  1245. testAddRemove
  1246. | set |
  1247. set := Set new.
  1248. self assert: set isEmpty.
  1249. set add: 3.
  1250. self assert: (set includes: 3).
  1251. set add: 5.
  1252. self assert: (set includes: 5).
  1253. set remove: 3.
  1254. self deny: (set includes: 3)
  1255. !
  1256. testAt
  1257. self should: [ Set new at: 1 put: 2 ] raise: Error
  1258. !
  1259. testCollect
  1260. super testCollect.
  1261. self assert: (#(5 6 8) asSet collect: [ :x | x \\ 3 ]) equals: #(0 2) asSet
  1262. !
  1263. testComma
  1264. super testComma.
  1265. self assert: self collection, self collection equals: self collection.
  1266. self assert: self collection, self collectionWithNewValue equals: self collectionWithNewValue.
  1267. self assert: self collectionWithNewValue, self collection equals: self collectionWithNewValue
  1268. !
  1269. testComparing
  1270. self assert: #(0 2) asSet equals: #(0 2) asSet.
  1271. self assert: #(2 0) asSet equals: #(0 2) asSet.
  1272. self deny: #(0 2 3) asSet = #(0 2) asSet.
  1273. self deny: #(1 2) asSet = #(0 2) asSet
  1274. !
  1275. testPrintString
  1276. | set |
  1277. set := Set new.
  1278. self assert: set printString equals: 'a Set ()'.
  1279. set add: 1; add: 3.
  1280. self assert: set printString equals: 'a Set (1 3)'.
  1281. set add: 'foo'.
  1282. self assert: set printString equals: 'a Set (1 3 ''foo'')'.
  1283. set remove: 1; remove: 3.
  1284. self assert: set printString equals: 'a Set (''foo'')'.
  1285. set add: 3.
  1286. self assert: set printString equals: 'a Set (3 ''foo'')'.
  1287. set add: 3.
  1288. self assert: set printString equals: 'a Set (3 ''foo'')'
  1289. !
  1290. testUnboxedObjects
  1291. self assert: {'foo' yourself. 'foo' yourself} asSet asArray equals: #('foo')
  1292. !
  1293. testUnicity
  1294. | set |
  1295. set := Set new.
  1296. set add: 21.
  1297. set add: 'hello'.
  1298. set add: 21.
  1299. self assert: set size equals: 2.
  1300. set add: 'hello'.
  1301. self assert: set size equals: 2.
  1302. self assert: set asArray equals: #(21 'hello')
  1303. ! !
  1304. !SetTest class methodsFor: 'fixture'!
  1305. collectionClass
  1306. ^ Set
  1307. ! !
  1308. TestCase subclass: #ConsoleTranscriptTest
  1309. instanceVariableNames: ''
  1310. package: 'Kernel-Tests'!
  1311. !ConsoleTranscriptTest methodsFor: 'tests'!
  1312. testShow
  1313. | originalTranscript |
  1314. originalTranscript := Transcript current.
  1315. Transcript register: ConsoleTranscript new.
  1316. self shouldnt: [ Transcript show: 'Hello console!!' ] raise: Error.
  1317. self shouldnt: [ Transcript show: console ] raise: Error.
  1318. Transcript register: originalTranscript.
  1319. ! !
  1320. TestCase subclass: #JSObjectProxyTest
  1321. instanceVariableNames: ''
  1322. package: 'Kernel-Tests'!
  1323. !JSObjectProxyTest methodsFor: 'accessing'!
  1324. jsNull
  1325. <return null>
  1326. !
  1327. jsObject
  1328. <return {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': void 0}>
  1329. !
  1330. jsUndefined
  1331. <return>
  1332. ! !
  1333. !JSObjectProxyTest methodsFor: 'tests'!
  1334. testAtIfAbsent
  1335. | testObject |
  1336. testObject := self jsObject.
  1337. self assert: (testObject at: 'abc' ifAbsent: [ 'Property does not exist' ]) equals: 'Property does not exist'.
  1338. self assert: (testObject at: 'e' ifAbsent: [ 'Property does not exist' ]) equals: nil.
  1339. self assert: (testObject at: 'a' ifAbsent: [ 'Property does not exist' ]) equals: 1.
  1340. self assert: (testObject at: 'f' ifAbsent: [ 'Property does not exist' ]) equals: nil.
  1341. !
  1342. testAtIfPresent
  1343. | testObject |
  1344. testObject := self jsObject.
  1345. self assert: (testObject at: 'abc' ifPresent: [ :x | 'hello ',x asString ]) equals: nil.
  1346. self assert: (testObject at: 'e' ifPresent: [ :x | 'hello ',x asString ]) equals: 'hello nil'.
  1347. self assert: (testObject at: 'a' ifPresent: [ :x | 'hello ',x asString ]) equals: 'hello 1'.
  1348. self assert: (testObject at: 'f' ifPresent: [ :x | 'hello ',x asString ]) equals: 'hello nil'.
  1349. !
  1350. testAtIfPresentIfAbsent
  1351. | testObject |
  1352. testObject := self jsObject.
  1353. self assert: (testObject at: 'abc' ifPresent: [ :x|'hello ',x asString ] ifAbsent: [ 'not present' ]) equals: 'not present'.
  1354. self assert: (testObject at: 'e' ifPresent: [ :x|'hello ',x asString ] ifAbsent: [ 'not present' ]) equals: 'hello nil'.
  1355. self assert: (testObject at: 'a' ifPresent: [ :x|'hello ',x asString ] ifAbsent: [ 'not present' ]) equals: 'hello 1'.
  1356. self assert: (testObject at: 'f' ifPresent: [ :x|'hello ',x asString ] ifAbsent: [ 'not present' ]) equals: 'hello nil'.
  1357. !
  1358. testAtPut
  1359. | testObject |
  1360. testObject := self jsObject.
  1361. self assert: (testObject at: 'abc') ~= 'xyz'.
  1362. self assert: (testObject at: 'abc' put: 'xyz') equals: 'xyz'.
  1363. self assert: (testObject at: 'abc') equals: 'xyz'
  1364. !
  1365. testComparison
  1366. self assert: ({ console. 2 } indexOf: console) equals: 1.
  1367. self assert: console = console.
  1368. self deny: console = Object new.
  1369. self deny: console = self jsObject
  1370. !
  1371. testDNU
  1372. self should: [ self jsObject foo ] raise: MessageNotUnderstood
  1373. !
  1374. testDNURegression1057
  1375. | jsObject |
  1376. jsObject := #().
  1377. jsObject basicAt: 'allowJavaScriptCalls' put: true.
  1378. jsObject basicAt: 'foo' put: 3.
  1379. self shouldnt: [ jsObject foo ] raise: Error.
  1380. self assert: jsObject foo equals: 3.
  1381. self shouldnt: [ jsObject foo: 4 ] raise: Error.
  1382. self assert: jsObject foo equals: 4
  1383. !
  1384. testDNURegression1059
  1385. | jsObject |
  1386. jsObject := #().
  1387. jsObject basicAt: 'allowJavaScriptCalls' put: true.
  1388. jsObject basicAt: 'x' put: 3.
  1389. jsObject basicAt: 'x:' put: [ self error ].
  1390. self shouldnt: [ jsObject x: 4 ] raise: Error.
  1391. self assert: jsObject x equals: 4
  1392. !
  1393. testDNURegression1062
  1394. | jsObject stored |
  1395. jsObject := #().
  1396. jsObject basicAt: 'allowJavaScriptCalls' put: true.
  1397. jsObject basicAt: 'x' put: [ :v | stored := v ].
  1398. self shouldnt: [ jsObject x: 4 ] raise: Error.
  1399. self assert: stored equals: 4
  1400. !
  1401. testDNUWithAllowJavaScriptCalls
  1402. | jsObject |
  1403. jsObject := #().
  1404. jsObject basicAt: 'allowJavaScriptCalls' put: true.
  1405. self should: [ jsObject foo ] raise: MessageNotUnderstood
  1406. !
  1407. testMessageSend
  1408. self assert: self jsObject a equals: 1.
  1409. self assert: self jsObject b equals: 2.
  1410. self assert: (self jsObject c: 3) equals: 3
  1411. !
  1412. testMethodWithArguments
  1413. self assert: (self jsObject c: 1) equals: 1
  1414. !
  1415. testPrinting
  1416. self assert: self jsObject printString equals: '[object Object]'
  1417. !
  1418. testPropertyThatReturnsEmptyString
  1419. | object |
  1420. object := self jsObject.
  1421. self assert: object d equals: ''.
  1422. object d: 'hello'.
  1423. self assert: object d equals: 'hello'
  1424. !
  1425. testPropertyThatReturnsUndefined
  1426. | object |
  1427. object := self jsObject.
  1428. self shouldnt: [ object e ] raise: MessageNotUnderstood.
  1429. self assert: object e isNil
  1430. !
  1431. testSetPropertyWithFalsyValue
  1432. | jsObject |
  1433. jsObject := self jsObject.
  1434. self assert: (jsObject a) equals: 1.
  1435. jsObject a: self jsNull.
  1436. self assert: (jsObject a) equals: nil.
  1437. jsObject a: 0.
  1438. self assert: (jsObject a) equals: 0.
  1439. jsObject a: self jsUndefined.
  1440. self assert: (jsObject a) equals: nil.
  1441. jsObject a: ''.
  1442. self assert: (jsObject a) equals: ''.
  1443. jsObject a: false.
  1444. self assert: (jsObject a) equals: false
  1445. !
  1446. testValue
  1447. | testObject |
  1448. testObject := self jsObject.
  1449. testObject at: 'value' put: 'aValue'.
  1450. self assert: testObject value equals: 'aValue'
  1451. !
  1452. testYourself
  1453. | object |
  1454. object := self jsObject
  1455. d: 'test';
  1456. yourself.
  1457. self assert: object d equals: 'test'
  1458. ! !
  1459. TestCase subclass: #JavaScriptExceptionTest
  1460. instanceVariableNames: ''
  1461. package: 'Kernel-Tests'!
  1462. !JavaScriptExceptionTest methodsFor: 'helpers'!
  1463. throwException
  1464. <throw 'test'>
  1465. ! !
  1466. !JavaScriptExceptionTest methodsFor: 'tests'!
  1467. testCatchingException
  1468. [ self throwException ]
  1469. on: Error
  1470. do: [ :error |
  1471. self assert: error exception = 'test' ]
  1472. !
  1473. testRaisingException
  1474. self should: [ self throwException ] raise: JavaScriptException
  1475. ! !
  1476. TestCase subclass: #MessageSendTest
  1477. instanceVariableNames: ''
  1478. package: 'Kernel-Tests'!
  1479. !MessageSendTest methodsFor: 'tests'!
  1480. testValue
  1481. | messageSend |
  1482. messageSend := MessageSend new
  1483. receiver: Object new;
  1484. selector: #asString;
  1485. yourself.
  1486. self assert: messageSend value equals: 'an Object'
  1487. !
  1488. testValueWithArguments
  1489. | messageSend |
  1490. messageSend := MessageSend new
  1491. receiver: 2;
  1492. selector: '+';
  1493. yourself.
  1494. self assert: (messageSend value: 3) equals: 5.
  1495. self assert: (messageSend valueWithPossibleArguments: #(4)) equals: 6
  1496. ! !
  1497. TestCase subclass: #MethodInheritanceTest
  1498. instanceVariableNames: 'receiverTop receiverMiddle receiverBottom method performBlock'
  1499. package: 'Kernel-Tests'!
  1500. !MethodInheritanceTest methodsFor: 'accessing'!
  1501. codeGeneratorClass
  1502. ^ CodeGenerator
  1503. !
  1504. targetClassBottom
  1505. ^ JavaScriptException
  1506. !
  1507. targetClassMiddle
  1508. ^ Error
  1509. !
  1510. targetClassTop
  1511. ^ Object
  1512. ! !
  1513. !MethodInheritanceTest methodsFor: 'factory'!
  1514. compiler
  1515. ^ Compiler new
  1516. codeGeneratorClass: self codeGeneratorClass;
  1517. yourself
  1518. ! !
  1519. !MethodInheritanceTest methodsFor: 'initialization'!
  1520. setUp
  1521. receiverTop := self targetClassTop new.
  1522. receiverMiddle := self targetClassMiddle new.
  1523. receiverBottom := self targetClassBottom new.
  1524. method := nil.
  1525. performBlock := [ self error: 'performBlock not initialized' ]
  1526. !
  1527. tearDown
  1528. [ self deinstallTop ] on: Error do: [ ].
  1529. [ self deinstallMiddle ] on: Error do: [ ].
  1530. [ self deinstallBottom ] on: Error do: [ ]
  1531. ! !
  1532. !MethodInheritanceTest methodsFor: 'testing'!
  1533. deinstallBottom
  1534. self targetClassBottom removeCompiledMethod: method
  1535. !
  1536. deinstallMiddle
  1537. self targetClassMiddle removeCompiledMethod: method
  1538. !
  1539. deinstallTop
  1540. self targetClassTop removeCompiledMethod: method
  1541. !
  1542. installBottom: aString
  1543. method := self compiler install: aString forClass: self targetClassBottom protocol: 'tests'
  1544. !
  1545. installMiddle: aString
  1546. method := self compiler install: aString forClass: self targetClassMiddle protocol: 'tests'
  1547. !
  1548. installTop: aString
  1549. method := self compiler install: aString forClass: self targetClassTop protocol: 'tests'
  1550. !
  1551. shouldMNU
  1552. self shouldMNUTop.
  1553. self shouldMNUMiddle.
  1554. self shouldMNUBottom
  1555. !
  1556. shouldMNUBottom
  1557. self should: [ performBlock value: receiverBottom ] raise: MessageNotUnderstood
  1558. !
  1559. shouldMNUMiddle
  1560. self should: [ performBlock value: receiverMiddle ] raise: MessageNotUnderstood
  1561. !
  1562. shouldMNUTop
  1563. self should: [ performBlock value: receiverTop ] raise: MessageNotUnderstood
  1564. !
  1565. shouldReturn: anObject
  1566. | result |
  1567. result := performBlock value: receiverTop.
  1568. self assert: { 'top'. anObject } equals: { 'top'. result }.
  1569. result := performBlock value: receiverMiddle.
  1570. self assert: { 'middle'. anObject } equals: { 'middle'. result }.
  1571. result := performBlock value: receiverBottom.
  1572. self assert: { 'bottom'. anObject } equals: { 'bottom'. result }
  1573. !
  1574. shouldReturn: anObject and: anObject2 and: anObject3
  1575. | result |
  1576. result := performBlock value: receiverTop.
  1577. self assert: { 'top'. anObject } equals: { 'top'. result }.
  1578. result := performBlock value: receiverMiddle.
  1579. self assert: { 'middle'. anObject2 } equals: { 'middle'. result }.
  1580. result := performBlock value: receiverBottom.
  1581. self assert: { 'bottom'. anObject3 } equals: { 'bottom'. result }
  1582. ! !
  1583. !MethodInheritanceTest methodsFor: 'tests'!
  1584. testMNU11
  1585. performBlock := [ :x | x foo ].
  1586. self shouldMNU.
  1587. self installTop: 'foo ^ false'.
  1588. self installTop: 'foo ^ true'.
  1589. self deinstallTop.
  1590. self shouldMNU
  1591. !
  1592. testMNU22
  1593. performBlock := [ :x | x foo ].
  1594. self shouldMNU.
  1595. self installMiddle: 'foo ^ false'.
  1596. self installMiddle: 'foo ^ true'.
  1597. self deinstallMiddle.
  1598. self shouldMNU
  1599. !
  1600. testReturns1
  1601. performBlock := [ :x | x foo ].
  1602. self installTop: 'foo ^ false'.
  1603. self shouldReturn: false.
  1604. self installTop: 'foo ^ true'.
  1605. self shouldReturn: true
  1606. ! !
  1607. TestCase subclass: #NumberTest
  1608. instanceVariableNames: ''
  1609. package: 'Kernel-Tests'!
  1610. !NumberTest methodsFor: 'tests'!
  1611. testAbs
  1612. self assert: 4 abs equals: 4.
  1613. self assert: -4 abs equals: 4
  1614. !
  1615. testArithmetic
  1616. "We rely on JS here, so we won't test complex behavior, just check if
  1617. message sends are corrects"
  1618. self assert: 1.5 + 1 equals: 2.5.
  1619. self assert: 2 - 1 equals: 1.
  1620. self assert: -2 - 1 equals: -3.
  1621. self assert: 12 / 2 equals: 6.
  1622. self assert: 3 * 4 equals: 12.
  1623. self assert: 7 // 2 equals: 3.
  1624. self assert: 7 \\ 2 equals: 1.
  1625. "Simple parenthesis and execution order"
  1626. self assert: 1 + 2 * 3 equals: 9.
  1627. self assert: 1 + (2 * 3) equals: 7
  1628. !
  1629. testAsNumber
  1630. self assert: 3 asNumber equals: 3.
  1631. !
  1632. testCeiling
  1633. self assert: 1.2 ceiling equals: 2.
  1634. self assert: -1.2 ceiling equals: -1.
  1635. self assert: 1.0 ceiling equals: 1.
  1636. !
  1637. testComparison
  1638. self assert: 3 > 2.
  1639. self assert: 2 < 3.
  1640. self deny: 3 < 2.
  1641. self deny: 2 > 3.
  1642. self assert: 3 >= 3.
  1643. self assert: 3.1 >= 3.
  1644. self assert: 3 <= 3.
  1645. self assert: 3 <= 3.1
  1646. !
  1647. testCopying
  1648. self assert: 1 copy == 1.
  1649. self assert: 1 deepCopy == 1
  1650. !
  1651. testEquality
  1652. self assert: (1 = 1).
  1653. self assert: (0 = 0).
  1654. self deny: (1 = 0).
  1655. self assert: (1 yourself = 1).
  1656. self assert: (1 = 1 yourself).
  1657. self assert: (1 yourself = 1 yourself).
  1658. self deny: 0 = false.
  1659. self deny: false = 0.
  1660. self deny: '' = 0.
  1661. self deny: 0 = ''
  1662. !
  1663. testFloor
  1664. self assert: 1.2 floor equals: 1.
  1665. self assert: -1.2 floor equals: -2.
  1666. self assert: 1.0 floor equals: 1.
  1667. !
  1668. testHexNumbers
  1669. self assert: 16r9 equals: 9.
  1670. self assert: 16rA truncated equals: 10.
  1671. self assert: 16rB truncated equals: 11.
  1672. self assert: 16rC truncated equals: 12.
  1673. self assert: 16rD truncated equals: 13.
  1674. self assert: 16rE truncated equals: 14.
  1675. self assert: 16rF truncated equals: 15
  1676. !
  1677. testIdentity
  1678. self assert: 1 == 1.
  1679. self assert: 0 == 0.
  1680. self deny: 1 == 0.
  1681. self assert: 1 yourself == 1.
  1682. self assert: 1 == 1 yourself.
  1683. self assert: 1 yourself == 1 yourself.
  1684. self deny: 1 == 2
  1685. !
  1686. testInvalidHexNumbers
  1687. self should: [ 16rG ] raise: MessageNotUnderstood.
  1688. self should: [ 16rg ] raise: MessageNotUnderstood.
  1689. self should: [ 16rH ] raise: MessageNotUnderstood.
  1690. self should: [ 16rh ] raise: MessageNotUnderstood.
  1691. self should: [ 16rI ] raise: MessageNotUnderstood.
  1692. self should: [ 16ri ] raise: MessageNotUnderstood.
  1693. self should: [ 16rJ ] raise: MessageNotUnderstood.
  1694. self should: [ 16rj ] raise: MessageNotUnderstood.
  1695. self should: [ 16rK ] raise: MessageNotUnderstood.
  1696. self should: [ 16rk ] raise: MessageNotUnderstood.
  1697. self should: [ 16rL ] raise: MessageNotUnderstood.
  1698. self should: [ 16rl ] raise: MessageNotUnderstood.
  1699. self should: [ 16rM ] raise: MessageNotUnderstood.
  1700. self should: [ 16rm ] raise: MessageNotUnderstood.
  1701. self should: [ 16rN ] raise: MessageNotUnderstood.
  1702. self should: [ 16rn ] raise: MessageNotUnderstood.
  1703. self should: [ 16rO ] raise: MessageNotUnderstood.
  1704. self should: [ 16ro ] raise: MessageNotUnderstood.
  1705. self should: [ 16rP ] raise: MessageNotUnderstood.
  1706. self should: [ 16rp ] raise: MessageNotUnderstood.
  1707. self should: [ 16rQ ] raise: MessageNotUnderstood.
  1708. self should: [ 16rq ] raise: MessageNotUnderstood.
  1709. self should: [ 16rR ] raise: MessageNotUnderstood.
  1710. self should: [ 16rr ] raise: MessageNotUnderstood.
  1711. self should: [ 16rS ] raise: MessageNotUnderstood.
  1712. self should: [ 16rs ] raise: MessageNotUnderstood.
  1713. self should: [ 16rT ] raise: MessageNotUnderstood.
  1714. self should: [ 16rt ] raise: MessageNotUnderstood.
  1715. self should: [ 16rU ] raise: MessageNotUnderstood.
  1716. self should: [ 16ru ] raise: MessageNotUnderstood.
  1717. self should: [ 16rV ] raise: MessageNotUnderstood.
  1718. self should: [ 16rv ] raise: MessageNotUnderstood.
  1719. self should: [ 16rW ] raise: MessageNotUnderstood.
  1720. self should: [ 16rw ] raise: MessageNotUnderstood.
  1721. self should: [ 16rX ] raise: MessageNotUnderstood.
  1722. self should: [ 16rx ] raise: MessageNotUnderstood.
  1723. self should: [ 16rY ] raise: MessageNotUnderstood.
  1724. self should: [ 16ry ] raise: MessageNotUnderstood.
  1725. self should: [ 16rZ ] raise: MessageNotUnderstood.
  1726. self should: [ 16rz ] raise: MessageNotUnderstood.
  1727. self should: [ 16rABcdEfZ ] raise: MessageNotUnderstood.
  1728. !
  1729. testLog
  1730. self assert: 10000 log equals: 4.
  1731. self assert: (512 log: 2) equals: 9.
  1732. self assert: Number e ln equals: 1.
  1733. !
  1734. testMinMax
  1735. self assert: (2 max: 5) equals: 5.
  1736. self assert: (2 min: 5) equals: 2
  1737. !
  1738. testNegated
  1739. self assert: 3 negated equals: -3.
  1740. self assert: -3 negated equals: 3
  1741. !
  1742. testPrintShowingDecimalPlaces
  1743. self assert: (23 printShowingDecimalPlaces: 2) equals: '23.00'.
  1744. self assert: (23.5698 printShowingDecimalPlaces: 2) equals: '23.57'.
  1745. self assert: (234.567 negated printShowingDecimalPlaces: 5) equals: '-234.56700'.
  1746. self assert: (23.4567 printShowingDecimalPlaces: 0) equals: '23'.
  1747. self assert: (23.5567 printShowingDecimalPlaces: 0) equals: '24'.
  1748. self assert: (23.4567 negated printShowingDecimalPlaces: 0) equals: '-23'.
  1749. self assert: (23.5567 negated printShowingDecimalPlaces: 0) equals: '-24'.
  1750. self assert: (100000000 printShowingDecimalPlaces: 1) equals: '100000000.0'.
  1751. self assert: (0.98 printShowingDecimalPlaces: 5) equals: '0.98000'.
  1752. self assert: (0.98 negated printShowingDecimalPlaces: 2) equals: '-0.98'.
  1753. self assert: (2.567 printShowingDecimalPlaces: 2) equals: '2.57'.
  1754. self assert: (-2.567 printShowingDecimalPlaces: 2) equals: '-2.57'.
  1755. self assert: (0 printShowingDecimalPlaces: 2) equals: '0.00'.
  1756. !
  1757. testRaisedTo
  1758. self assert: (2 raisedTo: 4) equals: 16.
  1759. self assert: (2 raisedTo: 0) equals: 1.
  1760. self assert: (2 raisedTo: -3) equals: 0.125.
  1761. self assert: (4 raisedTo: 0.5) equals: 2.
  1762. self assert: 2 ** 4 equals: 16.
  1763. !
  1764. testRounded
  1765. self assert: 3 rounded equals: 3.
  1766. self assert: 3.212 rounded equals: 3.
  1767. self assert: 3.51 rounded equals: 4
  1768. !
  1769. testSign
  1770. self assert: 5 sign equals: 1.
  1771. self assert: 0 sign equals: 0.
  1772. self assert: -1.4 sign equals: -1.
  1773. !
  1774. testSqrt
  1775. self assert: 4 sqrt equals: 2.
  1776. self assert: 16 sqrt equals: 4
  1777. !
  1778. testSquared
  1779. self assert: 4 squared equals: 16
  1780. !
  1781. testTimesRepeat
  1782. | i |
  1783. i := 0.
  1784. 0 timesRepeat: [ i := i + 1 ].
  1785. self assert: i equals: 0.
  1786. 5 timesRepeat: [ i := i + 1 ].
  1787. self assert: i equals: 5
  1788. !
  1789. testTo
  1790. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  1791. !
  1792. testToBy
  1793. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  1794. self should: [ 1 to: 4 by: 0 ] raise: Error
  1795. !
  1796. testTrigonometry
  1797. self assert: 0 cos equals: 1.
  1798. self assert: 0 sin equals: 0.
  1799. self assert: 0 tan equals: 0.
  1800. self assert: 1 arcCos equals: 0.
  1801. self assert: 0 arcSin equals: 0.
  1802. self assert: 0 arcTan equals: 0.
  1803. !
  1804. testTruncated
  1805. self assert: 3 truncated equals: 3.
  1806. self assert: 3.212 truncated equals: 3.
  1807. self assert: 3.51 truncated equals: 3
  1808. ! !
  1809. Object subclass: #ObjectMock
  1810. instanceVariableNames: 'foo bar'
  1811. package: 'Kernel-Tests'!
  1812. !ObjectMock commentStamp!
  1813. ObjectMock is there only to perform tests on classes.!
  1814. !ObjectMock methodsFor: 'not yet classified'!
  1815. foo
  1816. ^ foo
  1817. !
  1818. foo: anObject
  1819. foo := anObject
  1820. ! !
  1821. TestCase subclass: #ObjectTest
  1822. instanceVariableNames: ''
  1823. package: 'Kernel-Tests'!
  1824. !ObjectTest methodsFor: 'tests'!
  1825. notDefined
  1826. <return void 0;>
  1827. !
  1828. testBasicAccess
  1829. | o |
  1830. o := Object new.
  1831. o basicAt: 'a' put: 1.
  1832. self assert: (o basicAt: 'a') equals: 1.
  1833. self assert: (o basicAt: 'b') equals: nil
  1834. !
  1835. testBasicPerform
  1836. | o |
  1837. o := Object new.
  1838. o basicAt: 'func' put: [ 'hello' ].
  1839. o basicAt: 'func2' put: [ :a | a + 1 ].
  1840. self assert: (o basicPerform: 'func') equals: 'hello'.
  1841. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  1842. !
  1843. testDNU
  1844. self should: [ Object new foo ] raise: MessageNotUnderstood
  1845. !
  1846. testEquality
  1847. | o |
  1848. o := Object new.
  1849. self deny: o = Object new.
  1850. self assert: (o = o).
  1851. self assert: (o yourself = o).
  1852. self assert: (o = o yourself)
  1853. !
  1854. testHalt
  1855. self should: [ Object new halt ] raise: Error
  1856. !
  1857. testIdentity
  1858. | o |
  1859. o := Object new.
  1860. self deny: o == Object new.
  1861. self assert: o == o.
  1862. self assert: o yourself == o.
  1863. self assert: o == o yourself
  1864. !
  1865. testIfNil
  1866. self deny: Object new isNil.
  1867. self deny: (Object new ifNil: [ true ]) = true.
  1868. self assert: (Object new ifNotNil: [ true ]) equals: true.
  1869. self assert: (Object new ifNil: [ false ] ifNotNil: [ true ]) equals: true.
  1870. self assert: (Object new ifNotNil: [ true ] ifNil: [ false ]) equals: true
  1871. !
  1872. testInstVars
  1873. | o |
  1874. o := ObjectMock new.
  1875. self assert: (o instVarAt: #foo) equals: nil.
  1876. o instVarAt: #foo put: 1.
  1877. self assert: (o instVarAt: #foo) equals: 1.
  1878. self assert: (o instVarAt: 'foo') equals: 1
  1879. !
  1880. testNilUndefined
  1881. "nil in Smalltalk is the undefined object in JS"
  1882. self assert: self notDefined equals: nil
  1883. !
  1884. testYourself
  1885. | o |
  1886. o := ObjectMock new.
  1887. self assert: o yourself == o
  1888. !
  1889. testidentityHash
  1890. | o1 o2 |
  1891. o1 := Object new.
  1892. o2 := Object new.
  1893. self assert: o1 identityHash == o1 identityHash.
  1894. self deny: o1 identityHash == o2 identityHash
  1895. ! !
  1896. TestCase subclass: #PointTest
  1897. instanceVariableNames: ''
  1898. package: 'Kernel-Tests'!
  1899. !PointTest methodsFor: 'tests'!
  1900. testAccessing
  1901. self assert: (Point x: 3 y: 4) x equals: 3.
  1902. self assert: (Point x: 3 y: 4) y equals: 4.
  1903. self assert: (Point new x: 3) x equals: 3.
  1904. self assert: (Point new y: 4) y equals: 4
  1905. !
  1906. testArithmetic
  1907. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  1908. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  1909. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  1910. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  1911. !
  1912. testAt
  1913. self assert: 3@4 equals: (Point x: 3 y: 4)
  1914. !
  1915. testComparison
  1916. self assert: 3@4 < (4@5).
  1917. self deny: 3@4 < (4@4).
  1918. self assert: 4@5 <= (4@5).
  1919. self deny: 4@5 <= (3@5).
  1920. self assert: 5@6 > (4@5).
  1921. self deny: 5@6 > (6@6).
  1922. self assert: 4@5 >= (4@5).
  1923. self deny: 4@5 >= (5@5)
  1924. !
  1925. testEgality
  1926. self assert: (3@4 = (3@4)).
  1927. self deny: 3@5 = (3@6)
  1928. !
  1929. testNew
  1930. self assert: (Point new x: 3) y equals: nil.
  1931. self deny: (Point new x: 3) x = 0.
  1932. self assert: (Point new y: 4) x equals: nil.
  1933. self deny: (Point new y: 4) y = 0
  1934. !
  1935. testTranslateBy
  1936. self assert: (3@3 translateBy: 0@1) equals: 3@4.
  1937. self assert: (3@3 translateBy: 0@1 negated) equals: 3@2.
  1938. self assert: (3@3 translateBy: 2@3) equals: 5@6.
  1939. self assert: (3@3 translateBy: 3 negated @0) equals: 0@3.
  1940. ! !
  1941. TestCase subclass: #QueueTest
  1942. instanceVariableNames: ''
  1943. package: 'Kernel-Tests'!
  1944. !QueueTest methodsFor: 'tests'!
  1945. testNextIfAbsent
  1946. | queue |
  1947. queue := Queue new.
  1948. queue nextPut: 'index1'.
  1949. self assert: (queue nextIfAbsent: 'empty') = 'index1'.
  1950. self deny: (queue nextIfAbsent: 'empty') = 'index1'
  1951. !
  1952. testQueueNext
  1953. | queue |
  1954. queue := Queue new.
  1955. queue
  1956. nextPut: 'index1';
  1957. nextPut: 'index2'.
  1958. self assert: queue next = 'index1'.
  1959. self deny: queue next = 'index'.
  1960. self should: [ queue next ] raise: Error
  1961. ! !
  1962. TestCase subclass: #RandomTest
  1963. instanceVariableNames: ''
  1964. package: 'Kernel-Tests'!
  1965. !RandomTest methodsFor: 'tests'!
  1966. testAtRandomNumber
  1967. |val|
  1968. 100 timesRepeat: [
  1969. val := 10 atRandom.
  1970. self assert: (val > 0).
  1971. self assert: (val <11)
  1972. ]
  1973. !
  1974. testAtRandomSequenceableCollection
  1975. |val|
  1976. 100 timesRepeat: [
  1977. val := 'abc' atRandom.
  1978. self assert: ((val = 'a') | (val = 'b') | (val = 'c' )).
  1979. ].
  1980. !
  1981. textNext
  1982. 10000 timesRepeat: [
  1983. | current next |
  1984. next := Random new next.
  1985. self assert: (next >= 0).
  1986. self assert: (next < 1).
  1987. self deny: current = next.
  1988. next = current ]
  1989. ! !
  1990. TestCase subclass: #StreamTest
  1991. instanceVariableNames: ''
  1992. package: 'Kernel-Tests'!
  1993. !StreamTest methodsFor: 'accessing'!
  1994. collectionClass
  1995. ^ self class collectionClass
  1996. !
  1997. newCollection
  1998. ^ self collectionClass new
  1999. !
  2000. newStream
  2001. ^ self collectionClass new stream
  2002. ! !
  2003. !StreamTest methodsFor: 'tests'!
  2004. testAtStartAtEnd
  2005. | stream |
  2006. stream := self newStream.
  2007. self assert: stream atStart.
  2008. self assert: stream atEnd.
  2009. stream nextPutAll: self newCollection.
  2010. self assert: stream atEnd.
  2011. self deny: stream atStart.
  2012. stream position: 1.
  2013. self deny: stream atEnd.
  2014. self deny: stream atStart
  2015. !
  2016. testContents
  2017. | stream |
  2018. stream := self newStream.
  2019. stream nextPutAll: self newCollection.
  2020. self assert: stream contents equals: self newCollection
  2021. !
  2022. testIsEmpty
  2023. | stream |
  2024. stream := self newStream.
  2025. self assert: stream isEmpty.
  2026. stream nextPutAll: self newCollection.
  2027. self deny: stream isEmpty
  2028. !
  2029. testPosition
  2030. | collection stream |
  2031. collection := self newCollection.
  2032. stream := self newStream.
  2033. stream nextPutAll: collection.
  2034. self assert: stream position equals: collection size.
  2035. stream position: 0.
  2036. self assert: stream position equals: 0.
  2037. stream next.
  2038. self assert: stream position equals: 1.
  2039. stream next.
  2040. self assert: stream position equals: 2
  2041. !
  2042. testReading
  2043. | stream collection |
  2044. collection := self newCollection.
  2045. stream := self newStream.
  2046. stream
  2047. nextPutAll: collection;
  2048. position: 0.
  2049. collection do: [ :each |
  2050. self assert: stream next equals: each ].
  2051. self assert: stream next isNil
  2052. !
  2053. testStreamContents
  2054. !
  2055. testWrite
  2056. | stream collection |
  2057. collection := self newCollection.
  2058. stream := self newStream.
  2059. collection do: [ :each | stream << each ].
  2060. self assert: stream contents equals: collection
  2061. !
  2062. testWriting
  2063. | stream collection |
  2064. collection := self newCollection.
  2065. stream := self newStream.
  2066. collection do: [ :each | stream nextPut: each ].
  2067. self assert: stream contents equals: collection.
  2068. stream := self newStream.
  2069. stream nextPutAll: collection.
  2070. self assert: stream contents equals: collection
  2071. ! !
  2072. !StreamTest class methodsFor: 'accessing'!
  2073. collectionClass
  2074. ^ nil
  2075. ! !
  2076. !StreamTest class methodsFor: 'testing'!
  2077. isAbstract
  2078. ^ self collectionClass isNil
  2079. ! !
  2080. StreamTest subclass: #ArrayStreamTest
  2081. instanceVariableNames: ''
  2082. package: 'Kernel-Tests'!
  2083. !ArrayStreamTest methodsFor: 'accessing'!
  2084. newCollection
  2085. ^ { true. 1. 3@4. 'foo' }
  2086. ! !
  2087. !ArrayStreamTest class methodsFor: 'accessing'!
  2088. collectionClass
  2089. ^ Array
  2090. ! !
  2091. StreamTest subclass: #StringStreamTest
  2092. instanceVariableNames: ''
  2093. package: 'Kernel-Tests'!
  2094. !StringStreamTest methodsFor: 'accessing'!
  2095. newCollection
  2096. ^ 'hello world'
  2097. ! !
  2098. !StringStreamTest class methodsFor: 'accessing'!
  2099. collectionClass
  2100. ^ String
  2101. ! !
  2102. TestCase subclass: #UndefinedTest
  2103. instanceVariableNames: ''
  2104. package: 'Kernel-Tests'!
  2105. !UndefinedTest methodsFor: 'tests'!
  2106. testCopying
  2107. self assert: nil copy equals: nil
  2108. !
  2109. testDeepCopy
  2110. self assert: nil deepCopy = nil
  2111. !
  2112. testIfNil
  2113. self assert: (nil ifNil: [ true ]) equals: true.
  2114. self deny: (nil ifNotNil: [ true ]) = true.
  2115. self assert: (nil ifNil: [ true ] ifNotNil: [ false ]) equals: true.
  2116. self deny: (nil ifNotNil: [ true ] ifNil: [ false ]) = true
  2117. !
  2118. testIsNil
  2119. self assert: nil isNil.
  2120. self deny: nil notNil.
  2121. ! !