Kernel-Tests.st 65 KB

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