Kernel-Tests.st 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148
  1. Smalltalk current createPackage: 'Kernel-Tests'!
  2. TestCase subclass: #AnnouncementSubscriptionTest
  3. instanceVariableNames: ''
  4. package: 'Kernel-Tests'!
  5. !AnnouncementSubscriptionTest methodsFor: 'tests'!
  6. testHandlesAnnouncement
  7. | subscription announcementClass1 announcementClass2 classBuilder |
  8. classBuilder := ClassBuilder new.
  9. announcementClass1 := classBuilder basicAddSubclassOf: SystemAnnouncement named: 'TestAnnouncement1' instanceVariableNames: #() package: 'Kernel-Tests'.
  10. subscription := AnnouncementSubscription new announcementClass: SystemAnnouncement.
  11. "Test whether the same class triggers the announcement"
  12. self assert: (subscription handlesAnnouncement: SystemAnnouncement) equals: true.
  13. "Test whether a subclass triggers the announcement"
  14. self assert: (subscription handlesAnnouncement: announcementClass1) equals: true.
  15. "Test whether an unrelated class does not trigger the announcement"
  16. self assert: (subscription handlesAnnouncement: Object) equals: false.
  17. classBuilder basicRemoveClass: announcementClass1.
  18. ! !
  19. TestCase subclass: #BlockClosureTest
  20. instanceVariableNames: ''
  21. package: 'Kernel-Tests'!
  22. !BlockClosureTest methodsFor: 'tests'!
  23. testCanClearInterval
  24. self shouldnt: [([Error new signal] valueWithInterval: 0) clearInterval] raise: Error
  25. !
  26. testCanClearTimeout
  27. self shouldnt: [([Error new signal] valueWithTimeout: 0) clearTimeout] raise: Error
  28. !
  29. testCompiledSource
  30. self assert: ([1+1] compiledSource includesSubString: 'function')
  31. !
  32. testCurrySelf
  33. | curriedMethod array |
  34. curriedMethod := [ :selfarg :x | selfarg at: x ] currySelf asCompiledMethod: 'foo:'.
  35. array := #(3 1 4).
  36. ClassBuilder new installMethod: curriedMethod forClass: Array category: '**test helper'.
  37. [ self assert: (array foo: 2) equals: 1 ]
  38. ensure: [ Array removeCompiledMethod: curriedMethod ]
  39. !
  40. testEnsure
  41. self assert: ([3] ensure: [4]) equals: 3
  42. !
  43. testEnsureRaises
  44. self should: [[Error new signal] ensure: [true]] raise: Error
  45. !
  46. testExceptionSemantics
  47. "See https://github.com/NicolasPetton/amber/issues/314"
  48. self timeout: 100.
  49. (self async: [
  50. [
  51. self assert: true.
  52. Error signal.
  53. "The following should *not* be run"
  54. self deny: true.
  55. self finished.
  56. ] on: Error do: [ :ex | self finished ]
  57. ]) valueWithTimeout: 0
  58. !
  59. testNewWithValues
  60. <
  61. function theTestPrototype() {this.name = "theTestPrototype";}
  62. function theTestConstructor(arg1, arg2, arg3) {}
  63. theTestConstructor.prototype = new theTestPrototype;
  64. var theWrappedConstructor = _st(theTestConstructor);
  65. var theResult = theWrappedConstructor._newWithValues_([1, 2, 3]);
  66. self._assert_equals_(Object.getPrototypeOf(theResult).name, 'theTestPrototype');
  67. "newWithValues: cannot help if the argument list is wrong, and should warn that a mistake was made."
  68. function constructionShouldFail() {var anotherResult = theWrappedConstructor._newWithValues_('This is so wrong');}
  69. self._should_raise_(_st(constructionShouldFail), smalltalk.Error);
  70. >
  71. !
  72. testNumArgs
  73. self assert: [] numArgs equals: 0.
  74. self assert: [:a :b | ] numArgs equals: 2
  75. !
  76. testOnDo
  77. self assert: ([Error new signal] on: Error do: [:ex | true])
  78. !
  79. testValue
  80. self assert: ([1+1] value) equals: 2.
  81. self assert: ([:x | x +1] value: 2) equals: 3.
  82. self assert: ([:x :y | x*y] value: 2 value: 4) equals: 8.
  83. "Arguments are optional in Amber. This isn't ANSI compliant."
  84. self assert: ([:a :b :c | 1] value) equals: 1
  85. !
  86. testValueWithPossibleArguments
  87. self assert: ([1] valueWithPossibleArguments: #(3 4)) equals: 1.
  88. self assert: ([:a | a + 4] valueWithPossibleArguments: #(3 4)) equals: 7.
  89. self assert: ([:a :b | a + b] valueWithPossibleArguments: #(3 4 5)) equals: 7.
  90. !
  91. testWhileFalse
  92. | i |
  93. i := 0.
  94. [i > 5] whileFalse: [i := i + 1].
  95. self assert: i equals: 6.
  96. i := 0.
  97. [i := i + 1. i > 5] whileFalse.
  98. self assert: i equals: 6
  99. !
  100. testWhileTrue
  101. | i |
  102. i := 0.
  103. [i < 5] whileTrue: [i := i + 1].
  104. self assert: i equals: 5.
  105. i := 0.
  106. [i := i + 1. i < 5] whileTrue.
  107. self assert: i equals: 5
  108. ! !
  109. TestCase subclass: #BooleanTest
  110. instanceVariableNames: ''
  111. package: 'Kernel-Tests'!
  112. !BooleanTest methodsFor: 'tests'!
  113. testEquality
  114. "We're on top of JS...just be sure to check the basics!!"
  115. self deny: 0 = false.
  116. self deny: false = 0.
  117. self deny: '' = false.
  118. self deny: false = ''.
  119. self assert: (true = true).
  120. self deny: false = true.
  121. self deny: true = false.
  122. self assert: (false = false).
  123. "JS may do some type coercing after sending a message"
  124. self assert: (true yourself = true).
  125. self assert: (true yourself = true yourself)
  126. !
  127. testIdentity
  128. "We're on top of JS...just be sure to check the basics!!"
  129. self deny: 0 == false.
  130. self deny: false == 0.
  131. self deny: '' == false.
  132. self deny: false == ''.
  133. self assert: true == true.
  134. self deny: false == true.
  135. self deny: true == false.
  136. self assert: false == false.
  137. "JS may do some type coercing after sending a message"
  138. self assert: true yourself == true.
  139. self assert: true yourself == true yourself
  140. !
  141. testIfTrueIfFalse
  142. self assert: (true ifTrue: ['alternative block']) equals: 'alternative block'.
  143. self assert: (true ifFalse: ['alternative block']) equals: nil.
  144. self assert: (false ifTrue: ['alternative block']) equals: nil.
  145. self assert: (false ifFalse: ['alternative block']) equals: 'alternative block'.
  146. self assert: (false ifTrue: ['alternative block'] ifFalse: ['alternative block2']) equals: 'alternative block2'.
  147. self assert: (false ifFalse: ['alternative block'] ifTrue: ['alternative block2']) equals: 'alternative block'.
  148. self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) equals: 'alternative block'.
  149. self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) equals: 'alternative block2'.
  150. !
  151. testIfTrueIfFalseWithBoxing
  152. self assert: (true yourself ifTrue: ['alternative block']) equals: 'alternative block'.
  153. self assert: (true yourself ifFalse: ['alternative block']) equals: nil.
  154. self assert: (false yourself ifTrue: ['alternative block']) equals: nil.
  155. self assert: (false yourself ifFalse: ['alternative block']) equals: 'alternative block'.
  156. self assert: (false yourself ifTrue: ['alternative block'] ifFalse: ['alternative block2']) equals: 'alternative block2'.
  157. self assert: (false yourself ifFalse: ['alternative block'] ifTrue: ['alternative block2']) equals: 'alternative block'.
  158. self assert: (true yourself ifTrue: ['alternative block'] ifFalse: ['alternative block2']) equals: 'alternative block'.
  159. self assert: (true yourself ifFalse: ['alternative block'] ifTrue: ['alternative block2']) equals: 'alternative block2'.
  160. !
  161. testLogic
  162. "Trivial logic table"
  163. self assert: (true & true);
  164. deny: (true & false);
  165. deny: (false & true);
  166. deny: (false & false).
  167. self assert: (true | true);
  168. assert: (true | false);
  169. assert: (false | true);
  170. deny: (false | false).
  171. "Checking that expressions work fine too"
  172. self assert: (true & (1 > 0));
  173. deny: ((1 > 0) & false);
  174. deny: ((1 > 0) & (1 > 2)).
  175. self assert: (false | (1 > 0));
  176. assert: ((1 > 0) | false);
  177. assert: ((1 > 0) | (1 > 2))
  178. !
  179. testLogicKeywords
  180. "Trivial logic table"
  181. self
  182. assert: (true and: [ true]);
  183. deny: (true and: [ false ]);
  184. deny: (false and: [ true ]);
  185. deny: (false and: [ false ]).
  186. self
  187. assert: (true or: [ true ]);
  188. assert: (true or: [ false ]);
  189. assert: (false or: [ true ]);
  190. deny: (false or: [ false ]).
  191. "Checking that expressions work fine too"
  192. self
  193. assert: (true and: [ 1 > 0 ]);
  194. deny: ((1 > 0) and: [ false ]);
  195. deny: ((1 > 0) and: [ 1 > 2 ]).
  196. self
  197. assert: (false or: [ 1 > 0 ]);
  198. assert: ((1 > 0) or: [ false ]);
  199. assert: ((1 > 0) or: [ 1 > 2 ])
  200. !
  201. testNonBooleanError
  202. self should: [ '' ifTrue: [] ifFalse: [] ] raise: NonBooleanReceiver
  203. ! !
  204. TestCase subclass: #ClassBuilderTest
  205. instanceVariableNames: 'builder theClass'
  206. package: 'Kernel-Tests'!
  207. !ClassBuilderTest methodsFor: 'running'!
  208. setUp
  209. builder := ClassBuilder new
  210. !
  211. tearDown
  212. theClass ifNotNil: [Smalltalk current removeClass: theClass. theClass := nil]
  213. ! !
  214. !ClassBuilderTest methodsFor: 'tests'!
  215. testClassCopy
  216. theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  217. self assert: theClass superclass == ObjectMock superclass.
  218. self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
  219. self assert: theClass name equals: 'ObjectMock2'.
  220. self assert: theClass package == ObjectMock package.
  221. self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
  222. !
  223. testClassMigration
  224. | instance oldClass |
  225. oldClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  226. instance := (Smalltalk current at: 'ObjectMock2') new.
  227. "Change the superclass of ObjectMock2"
  228. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  229. instanceVariableNames: ''
  230. package: 'Kernel-Tests'.
  231. self deny: oldClass == ObjectMock2.
  232. self assert: ObjectMock2 superclass == ObjectMock.
  233. self assert: ObjectMock2 instanceVariableNames isEmpty.
  234. self assert: ObjectMock2 selectors equals: oldClass selectors.
  235. self assert: ObjectMock2 comment equals: oldClass comment.
  236. self assert: ObjectMock2 package name equals: 'Kernel-Tests'.
  237. self deny: instance class == ObjectMock2.
  238. "Commeting this out. Tests implementation detail."
  239. "self assert: instance class name equals: 'OldObjectMock2'."
  240. self assert: (Smalltalk current at: instance class name) isNil.
  241. Smalltalk current removeClass: ObjectMock2
  242. !
  243. testClassMigrationWithClassInstanceVariables
  244. builder copyClass: ObjectMock named: 'ObjectMock2'.
  245. ObjectMock2 class instanceVariableNames: 'foo bar'.
  246. "Change the superclass of ObjectMock2"
  247. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  248. instanceVariableNames: ''
  249. package: 'Kernel-Tests'.
  250. self assert: ObjectMock2 class instanceVariableNames equals: #('foo' 'bar').
  251. Smalltalk current removeClass: ObjectMock2
  252. !
  253. testClassMigrationWithSubclasses
  254. builder copyClass: ObjectMock named: 'ObjectMock2'.
  255. ObjectMock2 subclass: 'ObjectMock3' instanceVariableNames: '' package: 'Kernel-Tests'.
  256. ObjectMock3 subclass: 'ObjectMock4' instanceVariableNames: '' package: 'Kernel-Tests'.
  257. "Change the superclass of ObjectMock2"
  258. ObjectMock subclass: (Smalltalk current at: 'ObjectMock2')
  259. instanceVariableNames: ''
  260. package: 'Kernel-Tests'.
  261. self assert: (ObjectMock subclasses includes: ObjectMock2).
  262. self assert: (ObjectMock2 subclasses includes: ObjectMock3).
  263. self assert: (ObjectMock3 subclasses includes: ObjectMock4).
  264. ObjectMock allSubclasses do: [ :each | Smalltalk current removeClass: each ]
  265. !
  266. testInstanceVariableNames
  267. self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
  268. ! !
  269. TestCase subclass: #CollectionTest
  270. instanceVariableNames: ''
  271. package: 'Kernel-Tests'!
  272. !CollectionTest methodsFor: 'accessing'!
  273. collection
  274. ^ self collectionClass withAll: self defaultValues
  275. !
  276. collectionClass
  277. ^ self class collectionClass
  278. !
  279. collectionWithDuplicates
  280. ^ self collectionClass withAll: #('a' 'b' 'c' 1 2 1 'a')
  281. !
  282. defaultValues
  283. ^ #(1 2 3 -4)
  284. ! !
  285. !CollectionTest methodsFor: 'convenience'!
  286. assertSameContents: aCollection as: anotherCollection
  287. self assert: (aCollection size = anotherCollection size).
  288. aCollection do: [ :each |
  289. self assert: ((aCollection occurrencesOf: each) = (anotherCollection occurrencesOf: each)) ]
  290. ! !
  291. !CollectionTest methodsFor: 'testing'!
  292. isCollectionReadOnly
  293. ^ false
  294. ! !
  295. !CollectionTest methodsFor: 'tests'!
  296. testAsArray
  297. self
  298. assertSameContents: self collection
  299. as: self collection asArray
  300. !
  301. testAsOrderedCollection
  302. self
  303. assertSameContents: self collection
  304. as: self collection asOrderedCollection
  305. !
  306. testAsSet
  307. | c set |
  308. c := self collectionWithDuplicates.
  309. set := c asSet.
  310. self assert: set size equals: 5.
  311. c do: [ :each |
  312. self assert: (set includes: each) ]
  313. !
  314. testAssociation
  315. self assert: #key:value: equals: 'key:value:'.
  316. self deny: #key:value: = 'value:key:'
  317. !
  318. testCollect
  319. | newCollection |
  320. newCollection := #(1 2 3 4).
  321. self
  322. assertSameContents: (self collection collect: [ :each |
  323. each abs ])
  324. as: newCollection
  325. !
  326. testDetect
  327. self assert: (self collection detect: [ :each | each < 0 ]) equals: -4.
  328. self
  329. should: [ self collection detect: [ :each | each = 6 ] ]
  330. raise: Error
  331. !
  332. testDo
  333. | newCollection |
  334. newCollection := OrderedCollection new.
  335. self collection do: [ :each |
  336. newCollection add: each ].
  337. self
  338. assertSameContents: self collection
  339. as: newCollection
  340. !
  341. testIsEmpty
  342. self assert: self collectionClass new isEmpty.
  343. self deny: self collection isEmpty
  344. !
  345. testSelect
  346. | newCollection |
  347. newCollection := #(2 -4).
  348. self
  349. assertSameContents: (self collection select: [ :each |
  350. each even ])
  351. as: newCollection
  352. !
  353. testSize
  354. self assert: self collectionClass new size equals: 0.
  355. self assert: self collection size equals: 4
  356. ! !
  357. !CollectionTest class methodsFor: 'accessing'!
  358. collectionClass
  359. ^ nil
  360. ! !
  361. !CollectionTest class methodsFor: 'testing'!
  362. isAbstract
  363. ^ self collectionClass isNil
  364. ! !
  365. CollectionTest subclass: #IndexableCollectionTest
  366. instanceVariableNames: ''
  367. package: 'Kernel-Tests'!
  368. !IndexableCollectionTest methodsFor: 'tests'!
  369. testAt
  370. self assert: (self collection at: 4) equals: -4.
  371. self should: [ self collection at: 5 ] raise: Error
  372. !
  373. testAtIfAbsent
  374. self assert: (self collection at: (self collection size + 1) ifAbsent: [ 'none' ]) equals: 'none'
  375. !
  376. testContains
  377. | collection |
  378. collection := self collection.
  379. self assert: (self collection contains: [ :each | each = self collection first ]).
  380. self deny: (self collection contains: [ :each | each = Object new ])
  381. !
  382. testIndexOf
  383. self assert: (self collection indexOf: 2) equals: 2.
  384. self should: [ self collection indexOf: 999 ] raise: Error.
  385. self assert: (self collection indexOf: 999 ifAbsent: [ 'sentinel' ]) equals: 'sentinel'
  386. !
  387. testWithIndexDo
  388. | collection |
  389. collection := self collection.
  390. self collection withIndexDo: [ :each :index |
  391. self assert: (collection at: index) equals: each ]
  392. ! !
  393. IndexableCollectionTest subclass: #HashedCollectionTest
  394. instanceVariableNames: ''
  395. package: 'Kernel-Tests'!
  396. !HashedCollectionTest methodsFor: 'accessing'!
  397. collection
  398. ^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4 }
  399. !
  400. collectionWithDuplicates
  401. ^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4. 'e' -> 1. 'f' -> 2. 'g' -> 10 }
  402. ! !
  403. !HashedCollectionTest methodsFor: 'tests'!
  404. testAsDictionary
  405. self assert: ( self collectionClass new asDictionary isMemberOf: Dictionary ).
  406. !
  407. testAt
  408. self assert: (self collection at: 'a') equals: 2.
  409. self should: [ self collection at: 5 ] raise: Error
  410. !
  411. testContains
  412. | collection |
  413. collection := self collection.
  414. self assert: (self collection contains: [ :each | each = self collection values first ]).
  415. self deny: (self collection contains: [ :each | each = Object new ])
  416. !
  417. testFrom
  418. "Accept a collection of associations."
  419. | associations |
  420. associations := { 'a' -> 1. 'b' -> 2 }.
  421. self assertSameContents: ( self class collectionClass from: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.
  422. !
  423. testIndexOf
  424. self assert: (self collection indexOf: 2) equals: 'a'.
  425. self should: [ self collection indexOf: 999 ] raise: Error.
  426. self assert: (self collection indexOf: 999 ifAbsent: [ 'sentinel' ]) equals: 'sentinel'
  427. !
  428. testNewFromPairs
  429. "Accept an array in which all odd indexes are keys and evens are values."
  430. | flattenedAssociations |
  431. flattenedAssociations := { 'a'. 1. 'b'. 2 }.
  432. self assertSameContents: ( self class collectionClass newFromPairs: flattenedAssociations ) as: #{ 'a' -> 1. 'b' -> 2 }.
  433. ! !
  434. !HashedCollectionTest class methodsFor: 'accessing'!
  435. collectionClass
  436. ^ HashedCollection
  437. ! !
  438. HashedCollectionTest subclass: #DictionaryTest
  439. instanceVariableNames: ''
  440. package: 'Kernel-Tests'!
  441. !DictionaryTest methodsFor: 'accessing'!
  442. collection
  443. ^ Dictionary new
  444. at: 1 put: 1;
  445. at: 'a' put: 2;
  446. at: true put: 3;
  447. at: 4 put: -4;
  448. yourself
  449. !
  450. collectionWithDuplicates
  451. ^ Dictionary new
  452. at: 1 put: 1;
  453. at: 'a' put: 2;
  454. at: true put: 3;
  455. at: 4 put: -4;
  456. at: 'b' put: 1;
  457. at: 3 put: 3;
  458. at: false put: 12;
  459. yourself
  460. ! !
  461. !DictionaryTest methodsFor: 'tests'!
  462. testAccessing
  463. | d |
  464. d := Dictionary new.
  465. d at: 'hello' put: 'world'.
  466. self assert: (d at: 'hello') equals: 'world'.
  467. self assert: (d at: 'hello' ifAbsent: [nil]) equals: 'world'.
  468. self deny: (d at: 'foo' ifAbsent: [nil]) = 'world'.
  469. self assert: (d includesKey: 'hello').
  470. self deny: (d includesKey: 'foo').
  471. d at: 1 put: 2.
  472. self assert: (d at: 1) equals: 2.
  473. d at: 1@3 put: 3.
  474. self assert: (d at: 1@3) equals: 3.
  475. self assert: (d includesKey: 1@3).
  476. self deny: (d includesKey: 3@1)
  477. !
  478. testAsHashedCollection
  479. self assert: ( self collectionClass new asHashedCollection isMemberOf: HashedCollection ).
  480. !
  481. testDynamicDictionaries
  482. self assert: #{'hello' -> 1} asDictionary equals: (Dictionary with: 'hello' -> 1)
  483. !
  484. testEquality
  485. | d1 d2 |
  486. self assert: (Dictionary new = Dictionary new).
  487. d1 := Dictionary new at: 1 put: 2; yourself.
  488. d2 := Dictionary new at: 1 put: 2; yourself.
  489. self assert: (d1 = d2).
  490. d2 := Dictionary new at: 1 put: 3; yourself.
  491. self deny: d1 = d2.
  492. d2 := Dictionary new at: 2 put: 2; yourself.
  493. self deny: d1 = d2.
  494. d2 := Dictionary new at: 1 put: 2; at: 3 put: 4; yourself.
  495. self deny: d1 = d2.
  496. !
  497. testIfAbsent
  498. | d visited |
  499. visited := false.
  500. d := Dictionary new.
  501. d at: 'hello' ifAbsent: [ visited := true ].
  502. self assert: visited.
  503. !
  504. testIfPresent
  505. | d visited absent |
  506. visited := false.
  507. d := Dictionary new.
  508. d at: 'hello' put: 'world'.
  509. d at: 'hello' ifPresent: [ :value | visited := value ].
  510. self assert: visited equals: 'world'.
  511. absent := d at: 'bye' ifPresent: [ :value | visited := value ].
  512. self assert: absent isNil.
  513. !
  514. testIfPresentIfAbsent
  515. | d visited |
  516. visited := false.
  517. d := Dictionary new.
  518. d at: 'hello' put: 'world'.
  519. d at: 'hello' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  520. self assert: visited equals: 'world'.
  521. d at: 'buy' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  522. self assert: visited.
  523. !
  524. testKeys
  525. | d |
  526. d := Dictionary new.
  527. d at: 1 put: 2.
  528. d at: 2 put: 3.
  529. d at: 3 put: 4.
  530. self assert: d keys equals: #(1 2 3)
  531. !
  532. testPointKey
  533. | d |
  534. d := Dictionary new.
  535. d at: 1@1 put: 'foo'.
  536. self assert: (d at: 1@1) equals: 'foo'.
  537. d at: 1@1 put: 'bar'.
  538. self assert: (d at: 1@1) equals: 'bar'.
  539. d removeKey: 1@1.
  540. self assert: (d at: 1@1 ifAbsent: [ 'baz' ]) equals: 'baz'.
  541. self deny: (d includesKey: 1@1)
  542. !
  543. testPrintString
  544. self
  545. assert: (Dictionary new
  546. at:'firstname' put: 'James';
  547. at:'lastname' put: 'Bond';
  548. printString)
  549. equals: 'a Dictionary (''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  550. !
  551. testRemoveKey
  552. | d key |
  553. d := Dictionary new.
  554. d at: 1 put: 2.
  555. d at: 2 put: 3.
  556. d at: 3 put: 4.
  557. key := 2.
  558. self assert: d keys equals: #(1 2 3).
  559. d removeKey: key.
  560. self assert: d keys equals: #(1 3).
  561. self assert: d values equals: #(2 4).
  562. self deny: (d includesKey: 2)
  563. !
  564. testRemoveKeyIfAbsent
  565. | d key |
  566. d := Dictionary new.
  567. d at: 1 put: 2.
  568. d at: 2 put: 3.
  569. d at: 3 put: 4.
  570. key := 2.
  571. self assert: (d removeKey: key) equals: 3.
  572. key := 3.
  573. self assert: (d removeKey: key ifAbsent: [42]) equals: 4.
  574. key := 'why'.
  575. self assert: (d removeKey: key ifAbsent: [42] ) equals: 42.
  576. !
  577. testSize
  578. | d |
  579. d := Dictionary new.
  580. self assert: d size equals: 0.
  581. d at: 1 put: 2.
  582. self assert: d size equals: 1.
  583. d at: 2 put: 3.
  584. self assert: d size equals: 2.
  585. !
  586. testValues
  587. | d |
  588. d := Dictionary new.
  589. d at: 1 put: 2.
  590. d at: 2 put: 3.
  591. d at: 3 put: 4.
  592. self assert: d values equals: #(2 3 4)
  593. ! !
  594. !DictionaryTest class methodsFor: 'accessing'!
  595. collectionClass
  596. ^ Dictionary
  597. ! !
  598. IndexableCollectionTest subclass: #SequenceableCollectionTest
  599. instanceVariableNames: ''
  600. package: 'Kernel-Tests'!
  601. SequenceableCollectionTest subclass: #ArrayTest
  602. instanceVariableNames: ''
  603. package: 'Kernel-Tests'!
  604. !ArrayTest methodsFor: 'tests'!
  605. testAdd
  606. | array |
  607. array := #(1 2 3 4 5).
  608. array add:6 .
  609. self assert: array equals: #(1 2 3 4 5 6).
  610. !
  611. testAddFirst
  612. self assert: (#(2 3 4 5) addFirst: 1; yourself) equals: #(1 2 3 4 5)
  613. !
  614. testAtIfAbsent
  615. | array |
  616. array := #('hello' 'world').
  617. self assert: (array at: 1) equals: 'hello'.
  618. self assert: (array at: 2) equals: 'world'.
  619. self assert: (array at: 2 ifAbsent: ['not found']) equals: 'world'.
  620. self assert: (array at: 0 ifAbsent: ['not found']) equals: 'not found'.
  621. self assert: (array at: -10 ifAbsent: ['not found']) equals: 'not found'.
  622. self assert: (array at: 3 ifAbsent: ['not found']) equals: 'not found'.
  623. !
  624. testFirst
  625. |array|
  626. array := #(1 2 3 4 5).
  627. self assert: (array first) = (array at:1)
  628. !
  629. testFirstN
  630. self assert: ({1. 2. 3. 4. 5} first: 3) equals: {1. 2. 3}
  631. !
  632. testFourth
  633. |array|
  634. array := #(1 2 3 4 5).
  635. self assert: (array fourth) = (array at:4)
  636. !
  637. testIfEmpty
  638. self assert: ( '' ifEmpty: ['zork'] ) equals: 'zork'
  639. !
  640. testLast
  641. |array|
  642. array := #(1 2 3 4 5).
  643. self assert: (array last) = (array at:5)
  644. !
  645. testPrintString
  646. | array |
  647. array := Array new.
  648. self assert: array printString equals: 'an Array ()'.
  649. array add: 1; add: 3.
  650. self assert: array printString equals: 'an Array (1 3)'.
  651. array add: 'foo'.
  652. self assert: array printString equals: 'an Array (1 3 ''foo'')'.
  653. array remove: 1; remove: 3.
  654. self assert: array printString equals: 'an Array (''foo'')'.
  655. array addLast: 3.
  656. self assert: array printString equals: 'an Array (''foo'' 3)'.
  657. array addLast: 3.
  658. self assert: array printString equals: 'an Array (''foo'' 3 3)'.
  659. !
  660. testRemove
  661. |array|
  662. array := #(1 2 3 4 5).
  663. array remove:3.
  664. self assert: array equals: #(1 2 4 5).
  665. self should: [array remove:3] raise: Error.
  666. !
  667. testRemoveFromTo
  668. self assert: (#(1 2 3 4) removeFrom: 1 to: 3) equals: #(4).
  669. self assert: (#(1 2 3 4) removeFrom: 2 to: 3) equals: #(1 4).
  670. self assert: (#(1 2 3 4) removeFrom: 2 to: 4) equals: #(1)
  671. !
  672. testRemoveIndex
  673. self assert: (#(1 2 3 4) removeIndex: 2) equals: #(1 3 4).
  674. self assert: (#(1 2 3 4) removeIndex: 1) equals: #(2 3 4).
  675. self assert: (#('hello') removeIndex: 1) equals: #()
  676. !
  677. testRemoveLast
  678. |array|
  679. array := #(1 2).
  680. array removeLast.
  681. self assert: array last = 1.
  682. !
  683. testReversed
  684. |array|
  685. array := #(5 4 3 2 1).
  686. self assert: (array reversed) equals: #(1 2 3 4 5)
  687. !
  688. testSize
  689. | array |
  690. array := #('hello' 'world').
  691. self assert: array size = 2.
  692. self assert: Array new size = 0.
  693. !
  694. testSort
  695. |array|
  696. array := #(3 1 4 5 2).
  697. array sort.
  698. self assert: array equals: #(1 2 3 4 5)
  699. !
  700. testThird
  701. |array|
  702. array := #(1 2 3 4 5).
  703. self assert: (array third) = (array at:3)
  704. ! !
  705. !ArrayTest class methodsFor: 'accessing'!
  706. collectionClass
  707. ^ Array
  708. ! !
  709. SequenceableCollectionTest subclass: #StringTest
  710. instanceVariableNames: ''
  711. package: 'Kernel-Tests'!
  712. !StringTest methodsFor: 'accessing'!
  713. collection
  714. ^'hello'
  715. !
  716. collectionWithDuplicates
  717. ^ 'abbaerte'
  718. ! !
  719. !StringTest methodsFor: 'tests'!
  720. testAddRemove
  721. self should: ['hello' add: 'a'] raise: Error.
  722. self should: ['hello' remove: 'h'] raise: Error
  723. !
  724. testAsArray
  725. self assert: 'hello' asArray equals: #('h' 'e' 'l' 'l' 'o').
  726. !
  727. testAsLowerCase
  728. self assert: 'JACKIE' asLowercase equals: 'jackie'.
  729. !
  730. testAsNumber
  731. self assert: '3' asNumber equals: 3.
  732. self assert: '-3' asNumber equals: -3.
  733. self assert: '-1.5' asNumber equals: -1.5.
  734. !
  735. testAsUpperCase
  736. self assert: 'jackie' asUppercase equals: 'JACKIE'.
  737. !
  738. testAsciiValue
  739. |characterA characterU|
  740. characterA := 'A'.
  741. characterU := 'U'.
  742. self assert: (characterA asciiValue) equals:65.
  743. self assert: (characterU asciiValue) equals:85
  744. !
  745. testAt
  746. self assert: ('hello' at: 1) equals: 'h'.
  747. self assert: ('hello' at: 5) equals: 'o'.
  748. self assert: ('hello' at: 6 ifAbsent: [nil]) equals: nil
  749. !
  750. testAtPut
  751. "String instances are read-only"
  752. self should: ['hello' at: 1 put: 'a'] raise: Error
  753. !
  754. testCapitalized
  755. self assert: 'test' capitalized equals: 'Test'.
  756. self assert: 'Test' capitalized equals: 'Test'.
  757. self assert: '' capitalized equals: ''.
  758. self assert: 'Test' isCapitalized equals: true.
  759. self assert: 'test' isCapitalized equals: false.
  760. !
  761. testCharCodeAt
  762. |s|
  763. s := 'jackie'.
  764. self assert: ('jackie' charCodeAt:1) equals: 106.
  765. self assert: ('jackie' charCodeAt:2) equals: 97.
  766. self assert: ('jackie' charCodeAt:3) equals: 99.
  767. self assert: ('jackie' charCodeAt:4) equals: 107.
  768. self assert: ('jackie' charCodeAt:5) equals: 105.
  769. self assert: ('jackie' charCodeAt:6) equals: 101.
  770. !
  771. testCollect
  772. | newCollection |
  773. newCollection := 'hheelllloo'.
  774. self
  775. assertSameContents: (self collection collect: [ :each |
  776. each, each ])
  777. as: newCollection
  778. !
  779. testCopyFromTo
  780. self assert: ('jackie' copyFrom: 1 to: 3) equals: 'jac'.
  781. self assert: ('jackie' copyFrom: 4 to: 6) equals: 'kie'.
  782. !
  783. testCopyWithoutAll
  784. self
  785. assert: ('*hello* *world*' copyWithoutAll: '*')
  786. equals: 'hello world'
  787. !
  788. testDetect
  789. self assert: (self collection detect: [ :each | each = 'h' ]) equals: 'h'.
  790. self
  791. should: [ self collection detect: [ :each | each = 6 ] ]
  792. raise: Error
  793. !
  794. testEquality
  795. self assert: 'hello' equals: 'hello'.
  796. self deny: 'hello' = 'world'.
  797. "Test for issue 459"
  798. self deny: 'hello' = (#() at: 1 ifAbsent: [ ]).
  799. self assert: 'hello' equals: 'hello' yourself.
  800. self assert: 'hello' yourself equals: 'hello'.
  801. "test JS falsy value"
  802. self deny: '' = 0
  803. !
  804. testIdentity
  805. self assert: 'hello' == 'hello'.
  806. self deny: 'hello' == 'world'.
  807. self assert: 'hello' == 'hello' yourself.
  808. self assert: 'hello' yourself == 'hello'.
  809. "test JS falsy value"
  810. self deny: '' == 0
  811. !
  812. testIdentityHash
  813. self assert: 'foo' identityHash equals: 'foo' identityHash.
  814. self deny: ('foo' identityHash = 'bar' identityHash)
  815. !
  816. testIncludesSubString
  817. self assert: ('amber' includesSubString: 'ber').
  818. self deny: ('amber' includesSubString: 'zork').
  819. !
  820. testIndexOf
  821. self assert: (self collection indexOf: 'e') equals: 2.
  822. self should: [ self collection indexOf: 999 ] raise: Error.
  823. self assert: (self collection indexOf: 999 ifAbsent: [ 'sentinel' ]) equals: 'sentinel'
  824. !
  825. testIsVowel
  826. |vowel consonant|
  827. vowel := 'u'.
  828. consonant := 'z'.
  829. self assert: vowel isVowel equals: true.
  830. self assert: consonant isVowel equals: false
  831. !
  832. testJoin
  833. self assert: (',' join: #('hello' 'world')) equals: 'hello,world'
  834. !
  835. testReversed
  836. self assert: 'jackiechan' reversed equals: 'nahceikcaj'.
  837. !
  838. testSelect
  839. | newCollection |
  840. newCollection := 'o'.
  841. self
  842. assertSameContents: (self collection select: [ :each |
  843. each = 'o' ])
  844. as: newCollection
  845. !
  846. testSize
  847. self assert: 'smalltalk' size equals: 9.
  848. self assert: '' size equals: 0
  849. !
  850. testStreamContents
  851. self
  852. assert: (String streamContents: [ :aStream |
  853. aStream
  854. nextPutAll: 'hello'; space;
  855. nextPutAll: 'world' ])
  856. equals: 'hello world'
  857. !
  858. testSubStrings
  859. self assert: ('jackiechan' subStrings: 'ie') equals: #( 'jack' 'chan' ).
  860. !
  861. testTrim
  862. self assert: ' jackie' trimLeft equals: 'jackie'.
  863. self assert: 'jackie ' trimRight equals: 'jackie'.
  864. ! !
  865. !StringTest class methodsFor: 'accessing'!
  866. collectionClass
  867. ^ String
  868. ! !
  869. TestCase subclass: #ConsoleTranscriptTest
  870. instanceVariableNames: ''
  871. package: 'Kernel-Tests'!
  872. !ConsoleTranscriptTest methodsFor: 'tests'!
  873. testShow
  874. | originalTranscript |
  875. originalTranscript := Transcript current.
  876. Transcript register: ConsoleTranscript new.
  877. self shouldnt: [ Transcript show: 'Hello console!!' ] raise: Error.
  878. self shouldnt: [ Transcript show: console ] raise: Error.
  879. Transcript register: originalTranscript.
  880. ! !
  881. TestCase subclass: #JSObjectProxyTest
  882. instanceVariableNames: ''
  883. package: 'Kernel-Tests'!
  884. !JSObjectProxyTest methodsFor: 'accessing'!
  885. jsObject
  886. <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}, d: '', 'e': null, 'f': void 0}>
  887. ! !
  888. !JSObjectProxyTest methodsFor: 'tests'!
  889. testAtIfAbsent
  890. | testObject |
  891. testObject := self jsObject.
  892. self assert: (testObject at: 'abc' ifAbsent: ['Property does not exist']) equals: 'Property does not exist'.
  893. self assert: (testObject at: 'e' ifAbsent: ['Property does not exist']) equals: nil.
  894. self assert: (testObject at: 'a' ifAbsent: ['Property does not exist']) equals: 1.
  895. self assert: (testObject at: 'f' ifAbsent: ['Property does not exist']) equals: nil.
  896. !
  897. testAtIfPresent
  898. | testObject |
  899. testObject := self jsObject.
  900. self assert: (testObject at: 'abc' ifPresent: [ :x | 'hello ',x asString ]) equals: nil.
  901. self assert: (testObject at: 'e' ifPresent: [:x | 'hello ',x asString ]) equals: 'hello nil'.
  902. self assert: (testObject at: 'a' ifPresent: [:x | 'hello ',x asString ]) equals: 'hello 1'.
  903. self assert: (testObject at: 'f' ifPresent: [:x | 'hello ',x asString ]) equals: 'hello nil'.
  904. !
  905. testAtIfPresentIfAbsent
  906. | testObject |
  907. testObject := self jsObject.
  908. self assert: (testObject at: 'abc' ifPresent: [:x|'hello ',x asString] ifAbsent: ['not present']) equals: 'not present'.
  909. self assert: (testObject at: 'e' ifPresent: [:x|'hello ',x asString] ifAbsent: ['not present']) equals: 'hello nil'.
  910. self assert: (testObject at: 'a' ifPresent: [:x|'hello ',x asString] ifAbsent: ['not present']) equals: 'hello 1'.
  911. self assert: (testObject at: 'f' ifPresent: [:x|'hello ',x asString] ifAbsent: ['not present']) equals: 'hello nil'.
  912. !
  913. testDNU
  914. self should: [self jsObject foo] raise: MessageNotUnderstood
  915. !
  916. testMessageSend
  917. self assert: self jsObject a equals: 1.
  918. self assert: self jsObject b equals: 2.
  919. self assert: (self jsObject c: 3) equals: 3
  920. !
  921. testMethodWithArguments
  922. self assert: (self jsObject c: 1) equals: 1
  923. !
  924. testPrinting
  925. self assert: self jsObject printString equals: '[object Object]'
  926. !
  927. testPropertyThatReturnsEmptyString
  928. | object |
  929. object := self jsObject.
  930. self assert: object d equals: ''.
  931. object d: 'hello'.
  932. self assert: object d equals: 'hello'
  933. !
  934. testPropertyThatReturnsUndefined
  935. | object |
  936. object := self jsObject.
  937. self shouldnt: [ object e ] raise: MessageNotUnderstood.
  938. self assert: object e isNil
  939. !
  940. testValue
  941. | testObject |
  942. testObject := self jsObject.
  943. self assert: testObject value printString equals: '[object Object]'.
  944. testObject at: 'value' put: 'aValue'.
  945. self assert: testObject value equals: 'aValue'
  946. !
  947. testYourself
  948. | object |
  949. object := self jsObject
  950. d: 'test';
  951. yourself.
  952. self assert: object d equals: 'test'
  953. ! !
  954. TestCase subclass: #JavaScriptExceptionTest
  955. instanceVariableNames: ''
  956. package: 'Kernel-Tests'!
  957. !JavaScriptExceptionTest methodsFor: 'helpers'!
  958. throwException
  959. <throw 'test'>
  960. ! !
  961. !JavaScriptExceptionTest methodsFor: 'tests'!
  962. testCatchingException
  963. [ self throwException ]
  964. on: Error
  965. do: [ :error |
  966. self assert: error exception = 'test' ]
  967. !
  968. testRaisingException
  969. self should: [ self throwException ] raise: JavaScriptException
  970. ! !
  971. TestCase subclass: #MessageSendTest
  972. instanceVariableNames: ''
  973. package: 'Kernel-Tests'!
  974. !MessageSendTest methodsFor: 'tests'!
  975. testValue
  976. | messageSend |
  977. messageSend := MessageSend new
  978. receiver: Object new;
  979. selector: #asString;
  980. yourself.
  981. self assert: messageSend value equals: 'an Object'
  982. !
  983. testValueWithArguments
  984. | messageSend |
  985. messageSend := MessageSend new
  986. receiver: 2;
  987. selector: '+';
  988. yourself.
  989. self assert: (messageSend value: 3) equals: 5.
  990. self assert: (messageSend valueWithPossibleArguments: #(4)) equals: 6
  991. ! !
  992. TestCase subclass: #MethodInheritanceTest
  993. instanceVariableNames: 'receiverTop receiverMiddle receiverBottom method performBlock'
  994. package: 'Kernel-Tests'!
  995. !MethodInheritanceTest methodsFor: 'accessing'!
  996. codeGeneratorClass
  997. ^ CodeGenerator
  998. !
  999. targetClassBottom
  1000. ^ JavaScriptException
  1001. !
  1002. targetClassMiddle
  1003. ^ Error
  1004. !
  1005. targetClassTop
  1006. ^ Object
  1007. ! !
  1008. !MethodInheritanceTest methodsFor: 'factory'!
  1009. compiler
  1010. ^ Compiler new
  1011. codeGeneratorClass: self codeGeneratorClass;
  1012. yourself
  1013. ! !
  1014. !MethodInheritanceTest methodsFor: 'initialization'!
  1015. setUp
  1016. receiverTop := self targetClassTop new.
  1017. receiverMiddle := self targetClassMiddle new.
  1018. receiverBottom := self targetClassBottom new.
  1019. method := nil.
  1020. performBlock := [ self error: 'performBlock not initialized' ]
  1021. !
  1022. tearDown
  1023. [ self deinstallTop ] on: Error do: [].
  1024. [ self deinstallMiddle ] on: Error do: [].
  1025. [ self deinstallBottom ] on: Error do: []
  1026. ! !
  1027. !MethodInheritanceTest methodsFor: 'testing'!
  1028. deinstallBottom
  1029. self targetClassBottom removeCompiledMethod: method
  1030. !
  1031. deinstallMiddle
  1032. self targetClassMiddle removeCompiledMethod: method
  1033. !
  1034. deinstallTop
  1035. self targetClassTop removeCompiledMethod: method
  1036. !
  1037. installBottom: aString
  1038. method := self compiler install: aString forClass: self targetClassBottom category: 'tests'
  1039. !
  1040. installMiddle: aString
  1041. method := self compiler install: aString forClass: self targetClassMiddle category: 'tests'
  1042. !
  1043. installTop: aString
  1044. method := self compiler install: aString forClass: self targetClassTop category: 'tests'
  1045. !
  1046. shouldMNU
  1047. self shouldMNUTop.
  1048. self shouldMNUMiddle.
  1049. self shouldMNUBottom
  1050. !
  1051. shouldMNUBottom
  1052. self should: [ performBlock value: receiverBottom ] raise: MessageNotUnderstood
  1053. !
  1054. shouldMNUMiddle
  1055. self should: [ performBlock value: receiverMiddle ] raise: MessageNotUnderstood
  1056. !
  1057. shouldMNUTop
  1058. self should: [ performBlock value: receiverTop ] raise: MessageNotUnderstood
  1059. !
  1060. shouldReturn: anObject
  1061. | result |
  1062. result := performBlock value: receiverTop.
  1063. self assert: { 'top'. anObject } equals: { 'top'. result }.
  1064. result := performBlock value: receiverMiddle.
  1065. self assert: { 'middle'. anObject } equals: { 'middle'. result }.
  1066. result := performBlock value: receiverBottom.
  1067. self assert: { 'bottom'. anObject } equals: { 'bottom'. result }
  1068. !
  1069. shouldReturn: anObject and: anObject2 and: anObject3
  1070. | result |
  1071. result := performBlock value: receiverTop.
  1072. self assert: { 'top'. anObject } equals: { 'top'. result }.
  1073. result := performBlock value: receiverMiddle.
  1074. self assert: { 'middle'. anObject2 } equals: { 'middle'. result }.
  1075. result := performBlock value: receiverBottom.
  1076. self assert: { 'bottom'. anObject3 } equals: { 'bottom'. result }
  1077. ! !
  1078. !MethodInheritanceTest methodsFor: 'tests'!
  1079. testMNU11
  1080. performBlock := [ :x | x foo ].
  1081. self shouldMNU.
  1082. self installTop: 'foo ^ false'.
  1083. self installTop: 'foo ^ true'.
  1084. self deinstallTop.
  1085. self shouldMNU
  1086. !
  1087. testMNU22
  1088. performBlock := [ :x | x foo ].
  1089. self shouldMNU.
  1090. self installMiddle: 'foo ^ false'.
  1091. self installMiddle: 'foo ^ true'.
  1092. self deinstallMiddle.
  1093. self shouldMNU
  1094. !
  1095. testReturns1
  1096. performBlock := [ :x | x foo ].
  1097. self installTop: 'foo ^ false'.
  1098. self shouldReturn: false.
  1099. self installTop: 'foo ^ true'.
  1100. self shouldReturn: true
  1101. ! !
  1102. TestCase subclass: #NumberTest
  1103. instanceVariableNames: ''
  1104. package: 'Kernel-Tests'!
  1105. !NumberTest methodsFor: 'tests'!
  1106. testAbs
  1107. self assert: 4 abs equals: 4.
  1108. self assert: -4 abs equals: 4
  1109. !
  1110. testArithmetic
  1111. "We rely on JS here, so we won't test complex behavior, just check if
  1112. message sends are corrects"
  1113. self assert: 1.5 + 1 equals: 2.5.
  1114. self assert: 2 - 1 equals: 1.
  1115. self assert: -2 - 1 equals: -3.
  1116. self assert: 12 / 2 equals: 6.
  1117. self assert: 3 * 4 equals: 12.
  1118. self assert: 7 // 2 equals: 3.
  1119. self assert: 7 \\ 2 equals: 1.
  1120. "Simple parenthesis and execution order"
  1121. self assert: 1 + 2 * 3 equals: 9.
  1122. self assert: 1 + (2 * 3) equals: 7
  1123. !
  1124. testAsNumber
  1125. self assert: 3 asNumber equals: 3.
  1126. !
  1127. testCeiling
  1128. self assert: 1.2 ceiling equals: 2.
  1129. self assert: -1.2 ceiling equals: -1.
  1130. self assert: 1.0 ceiling equals: 1.
  1131. !
  1132. testComparison
  1133. self assert: 3 > 2.
  1134. self assert: 2 < 3.
  1135. self deny: 3 < 2.
  1136. self deny: 2 > 3.
  1137. self assert: 3 >= 3.
  1138. self assert: 3.1 >= 3.
  1139. self assert: 3 <= 3.
  1140. self assert: 3 <= 3.1
  1141. !
  1142. testCopying
  1143. self assert: 1 copy == 1.
  1144. self assert: 1 deepCopy == 1
  1145. !
  1146. testEquality
  1147. self assert: (1 = 1).
  1148. self assert: (0 = 0).
  1149. self deny: (1 = 0).
  1150. self assert: (1 yourself = 1).
  1151. self assert: (1 = 1 yourself).
  1152. self assert: (1 yourself = 1 yourself).
  1153. self deny: 0 = false.
  1154. self deny: false = 0.
  1155. self deny: '' = 0.
  1156. self deny: 0 = ''
  1157. !
  1158. testFloor
  1159. self assert: 1.2 floor equals: 1.
  1160. self assert: -1.2 floor equals: -2.
  1161. self assert: 1.0 floor equals: 1.
  1162. !
  1163. testHexNumbers
  1164. self assert: 16r9 equals: 9.
  1165. self assert: 16rA truncated equals: 10.
  1166. self assert: 16rB truncated equals: 11.
  1167. self assert: 16rC truncated equals: 12.
  1168. self assert: 16rD truncated equals: 13.
  1169. self assert: 16rE truncated equals: 14.
  1170. self assert: 16rF truncated equals: 15
  1171. !
  1172. testIdentity
  1173. self assert: 1 == 1.
  1174. self assert: 0 == 0.
  1175. self deny: 1 == 0.
  1176. self assert: 1 yourself == 1.
  1177. self assert: 1 == 1 yourself.
  1178. self assert: 1 yourself == 1 yourself.
  1179. self deny: 1 == 2
  1180. !
  1181. testInvalidHexNumbers
  1182. self should: [16rG] raise: MessageNotUnderstood.
  1183. self should: [16rg] raise: MessageNotUnderstood.
  1184. self should: [16rH] raise: MessageNotUnderstood.
  1185. self should: [16rh] raise: MessageNotUnderstood.
  1186. self should: [16rI] raise: MessageNotUnderstood.
  1187. self should: [16ri] raise: MessageNotUnderstood.
  1188. self should: [16rJ] raise: MessageNotUnderstood.
  1189. self should: [16rj] raise: MessageNotUnderstood.
  1190. self should: [16rK] raise: MessageNotUnderstood.
  1191. self should: [16rk] raise: MessageNotUnderstood.
  1192. self should: [16rL] raise: MessageNotUnderstood.
  1193. self should: [16rl] raise: MessageNotUnderstood.
  1194. self should: [16rM] raise: MessageNotUnderstood.
  1195. self should: [16rm] raise: MessageNotUnderstood.
  1196. self should: [16rN] raise: MessageNotUnderstood.
  1197. self should: [16rn] raise: MessageNotUnderstood.
  1198. self should: [16rO] raise: MessageNotUnderstood.
  1199. self should: [16ro] raise: MessageNotUnderstood.
  1200. self should: [16rP] raise: MessageNotUnderstood.
  1201. self should: [16rp] raise: MessageNotUnderstood.
  1202. self should: [16rQ] raise: MessageNotUnderstood.
  1203. self should: [16rq] raise: MessageNotUnderstood.
  1204. self should: [16rR] raise: MessageNotUnderstood.
  1205. self should: [16rr] raise: MessageNotUnderstood.
  1206. self should: [16rS] raise: MessageNotUnderstood.
  1207. self should: [16rs] raise: MessageNotUnderstood.
  1208. self should: [16rT] raise: MessageNotUnderstood.
  1209. self should: [16rt] raise: MessageNotUnderstood.
  1210. self should: [16rU] raise: MessageNotUnderstood.
  1211. self should: [16ru] raise: MessageNotUnderstood.
  1212. self should: [16rV] raise: MessageNotUnderstood.
  1213. self should: [16rv] raise: MessageNotUnderstood.
  1214. self should: [16rW] raise: MessageNotUnderstood.
  1215. self should: [16rw] raise: MessageNotUnderstood.
  1216. self should: [16rX] raise: MessageNotUnderstood.
  1217. self should: [16rx] raise: MessageNotUnderstood.
  1218. self should: [16rY] raise: MessageNotUnderstood.
  1219. self should: [16ry] raise: MessageNotUnderstood.
  1220. self should: [16rZ] raise: MessageNotUnderstood.
  1221. self should: [16rz] raise: MessageNotUnderstood.
  1222. self should: [16rABcdEfZ] raise: MessageNotUnderstood.
  1223. !
  1224. testLog
  1225. self assert: 10000 log equals: 4.
  1226. self assert: (512 log: 2) equals: 9.
  1227. self assert: Number e ln equals: 1.
  1228. !
  1229. testMinMax
  1230. self assert: (2 max: 5) equals: 5.
  1231. self assert: (2 min: 5) equals: 2
  1232. !
  1233. testNegated
  1234. self assert: 3 negated equals: -3.
  1235. self assert: -3 negated equals: 3
  1236. !
  1237. testPrintShowingDecimalPlaces
  1238. self assert: (23 printShowingDecimalPlaces: 2) equals: '23.00'.
  1239. self assert: (23.5698 printShowingDecimalPlaces: 2) equals: '23.57'.
  1240. self assert: (234.567 negated printShowingDecimalPlaces: 5) equals: '-234.56700'.
  1241. self assert: (23.4567 printShowingDecimalPlaces: 0) equals: '23'.
  1242. self assert: (23.5567 printShowingDecimalPlaces: 0) equals: '24'.
  1243. self assert: (23.4567 negated printShowingDecimalPlaces: 0) equals: '-23'.
  1244. self assert: (23.5567 negated printShowingDecimalPlaces: 0) equals: '-24'.
  1245. self assert: (100000000 printShowingDecimalPlaces: 1) equals: '100000000.0'.
  1246. self assert: (0.98 printShowingDecimalPlaces: 5) equals: '0.98000'.
  1247. self assert: (0.98 negated printShowingDecimalPlaces: 2) equals: '-0.98'.
  1248. self assert: (2.567 printShowingDecimalPlaces: 2) equals: '2.57'.
  1249. self assert: (-2.567 printShowingDecimalPlaces: 2) equals: '-2.57'.
  1250. self assert: (0 printShowingDecimalPlaces: 2) equals: '0.00'.
  1251. !
  1252. testRaisedTo
  1253. self assert: (2 raisedTo: 4) equals: 16.
  1254. self assert: (2 raisedTo: 0) equals: 1.
  1255. self assert: (2 raisedTo: -3) equals: 0.125.
  1256. self assert: (4 raisedTo: 0.5) equals: 2.
  1257. self assert: 2 ** 4 equals: 16.
  1258. !
  1259. testRounded
  1260. self assert: 3 rounded equals: 3.
  1261. self assert: 3.212 rounded equals: 3.
  1262. self assert: 3.51 rounded equals: 4
  1263. !
  1264. testSign
  1265. self assert: 5 sign equals: 1.
  1266. self assert: 0 sign equals: 0.
  1267. self assert: -1.4 sign equals: -1.
  1268. !
  1269. testSqrt
  1270. self assert: 4 sqrt equals: 2.
  1271. self assert: 16 sqrt equals: 4
  1272. !
  1273. testSquared
  1274. self assert: 4 squared equals: 16
  1275. !
  1276. testTimesRepeat
  1277. | i |
  1278. i := 0.
  1279. 0 timesRepeat: [i := i + 1].
  1280. self assert: i equals: 0.
  1281. 5 timesRepeat: [i := i + 1].
  1282. self assert: i equals: 5
  1283. !
  1284. testTo
  1285. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  1286. !
  1287. testToBy
  1288. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  1289. self should: [1 to: 4 by: 0] raise: Error
  1290. !
  1291. testTrigonometry
  1292. self assert: 0 cos equals: 1.
  1293. self assert: 0 sin equals: 0.
  1294. self assert: 0 tan equals: 0.
  1295. self assert: 1 arcCos equals: 0.
  1296. self assert: 0 arcSin equals: 0.
  1297. self assert: 0 arcTan equals: 0.
  1298. !
  1299. testTruncated
  1300. self assert: 3 truncated equals: 3.
  1301. self assert: 3.212 truncated equals: 3.
  1302. self assert: 3.51 truncated equals: 3
  1303. ! !
  1304. Object subclass: #ObjectMock
  1305. instanceVariableNames: 'foo bar'
  1306. package: 'Kernel-Tests'!
  1307. !ObjectMock commentStamp!
  1308. ObjectMock is there only to perform tests on classes.!
  1309. !ObjectMock methodsFor: 'not yet classified'!
  1310. foo
  1311. ^foo
  1312. !
  1313. foo: anObject
  1314. foo := anObject
  1315. ! !
  1316. TestCase subclass: #ObjectTest
  1317. instanceVariableNames: ''
  1318. package: 'Kernel-Tests'!
  1319. !ObjectTest methodsFor: 'tests'!
  1320. notDefined
  1321. <return void 0;>
  1322. !
  1323. testBasicAccess
  1324. | o |
  1325. o := Object new.
  1326. o basicAt: 'a' put: 1.
  1327. self assert: (o basicAt: 'a') equals: 1.
  1328. self assert: (o basicAt: 'b') equals: nil
  1329. !
  1330. testBasicPerform
  1331. | o |
  1332. o := Object new.
  1333. o basicAt: 'func' put: ['hello'].
  1334. o basicAt: 'func2' put: [:a | a + 1].
  1335. self assert: (o basicPerform: 'func') equals: 'hello'.
  1336. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  1337. !
  1338. testDNU
  1339. self should: [Object new foo] raise: MessageNotUnderstood
  1340. !
  1341. testEquality
  1342. | o |
  1343. o := Object new.
  1344. self deny: o = Object new.
  1345. self assert: (o = o).
  1346. self assert: (o yourself = o).
  1347. self assert: (o = o yourself)
  1348. !
  1349. testHalt
  1350. self should: [Object new halt] raise: Error
  1351. !
  1352. testIdentity
  1353. | o |
  1354. o := Object new.
  1355. self deny: o == Object new.
  1356. self assert: o == o.
  1357. self assert: o yourself == o.
  1358. self assert: o == o yourself
  1359. !
  1360. testIfNil
  1361. self deny: Object new isNil.
  1362. self deny: (Object new ifNil: [true]) = true.
  1363. self assert: (Object new ifNotNil: [true]) equals: true.
  1364. self assert: (Object new ifNil: [false] ifNotNil: [true]) equals: true.
  1365. self assert: (Object new ifNotNil: [true] ifNil: [false]) equals: true
  1366. !
  1367. testInstVars
  1368. | o |
  1369. o := ObjectMock new.
  1370. self assert: (o instVarAt: #foo) equals: nil.
  1371. o instVarAt: #foo put: 1.
  1372. self assert: (o instVarAt: #foo) equals: 1.
  1373. self assert: (o instVarAt: 'foo') equals: 1
  1374. !
  1375. testNilUndefined
  1376. "nil in Smalltalk is the undefined object in JS"
  1377. self assert: self notDefined equals: nil
  1378. !
  1379. testYourself
  1380. | o |
  1381. o := ObjectMock new.
  1382. self assert: o yourself == o
  1383. !
  1384. testidentityHash
  1385. | o1 o2 |
  1386. o1 := Object new.
  1387. o2 := Object new.
  1388. self assert: o1 identityHash == o1 identityHash.
  1389. self deny: o1 identityHash == o2 identityHash
  1390. ! !
  1391. TestCase subclass: #PointTest
  1392. instanceVariableNames: ''
  1393. package: 'Kernel-Tests'!
  1394. !PointTest methodsFor: 'tests'!
  1395. testAccessing
  1396. self assert: (Point x: 3 y: 4) x equals: 3.
  1397. self assert: (Point x: 3 y: 4) y equals: 4.
  1398. self assert: (Point new x: 3) x equals: 3.
  1399. self assert: (Point new y: 4) y equals: 4
  1400. !
  1401. testArithmetic
  1402. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  1403. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  1404. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  1405. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  1406. !
  1407. testAt
  1408. self assert: 3@4 equals: (Point x: 3 y: 4)
  1409. !
  1410. testEgality
  1411. self assert: (3@4 = (3@4)).
  1412. self deny: 3@5 = (3@6)
  1413. !
  1414. testNew
  1415. self assert: (Point new x: 3)y equals: nil.
  1416. self deny: (Point new x: 3)x = 0.
  1417. self assert: (Point new y: 4)x equals: nil.
  1418. self deny: (Point new y: 4)y = 0.
  1419. !
  1420. testTranslateBy
  1421. self assert: (3@3 translateBy: 0@1) equals: 3@4.
  1422. self assert: (3@3 translateBy: 0@1 negated) equals: 3@2.
  1423. self assert: (3@3 translateBy: 2@3) equals: 5@6.
  1424. self assert: (3@3 translateBy: 3 negated @0) equals: 0@3.
  1425. ! !
  1426. TestCase subclass: #QueueTest
  1427. instanceVariableNames: ''
  1428. package: 'Kernel-Tests'!
  1429. !QueueTest methodsFor: 'not yet classified'!
  1430. testNextIfAbsent
  1431. | queueVal |
  1432. queueVal:= Queue new.
  1433. queueVal nextPut: 'index1'.
  1434. self assert: (queueVal nextIfAbsent:'empty') = 'index1'.
  1435. self deny: (queueVal nextIfAbsent:'empty') = 'index1'.
  1436. !
  1437. testQueueNext
  1438. | collec |
  1439. collec:= Queue new.
  1440. collec nextPut: 'index1' ;
  1441. nextPut: 'index2' .
  1442. self assert: collec next = 'index1'.
  1443. self deny: collec next = 'index'.
  1444. self should:[ collec next ] raise: Error.
  1445. ! !
  1446. TestCase subclass: #RandomTest
  1447. instanceVariableNames: ''
  1448. package: 'Kernel-Tests'!
  1449. !RandomTest methodsFor: 'tests'!
  1450. testAtRandom
  1451. |val|
  1452. 10000 timesRepeat: [
  1453. val := 'abc' atRandom.
  1454. self assert: ((val = 'a') | (val = 'b') | (val = 'c' )).
  1455. ].
  1456. 10000 timesRepeat: [
  1457. val := 10 atRandom.
  1458. self assert: (val > 0).
  1459. self assert: (val <11)
  1460. ]
  1461. !
  1462. textNext
  1463. 10000 timesRepeat: [
  1464. | current next |
  1465. next := Random new next.
  1466. self assert: (next >= 0).
  1467. self assert: (next < 1).
  1468. self deny: current = next.
  1469. next = current]
  1470. ! !
  1471. TestCase subclass: #SetTest
  1472. instanceVariableNames: ''
  1473. package: 'Kernel-Tests'!
  1474. !SetTest methodsFor: 'tests'!
  1475. testAddRemove
  1476. | set |
  1477. set := Set new.
  1478. self assert: set isEmpty.
  1479. set add: 3.
  1480. self assert: (set includes: 3).
  1481. set add: 5.
  1482. self assert: (set includes: 5).
  1483. set remove: 3.
  1484. self deny: (set includes: 3)
  1485. !
  1486. testAt
  1487. self should: [Set new at: 1 put: 2] raise: Error
  1488. !
  1489. testCollect
  1490. self assert: (#(5 6 8) asSet collect: [ :x | x \\ 3 ]) equals: #(0 2) asSet
  1491. !
  1492. testComparing
  1493. self assert: #(0 2) asSet equals: #(0 2) asSet.
  1494. self assert: #(2 0) asSet equals: #(0 2) asSet.
  1495. self deny: #(0 2 3) asSet = #(0 2) asSet.
  1496. self deny: #(1 2) asSet = #(0 2) asSet
  1497. !
  1498. testPrintString
  1499. | set |
  1500. set := Set new.
  1501. self assert: set printString equals: 'a Set ()'.
  1502. set add: 1; add: 3.
  1503. self assert: set printString equals: 'a Set (1 3)'.
  1504. set add: 'foo'.
  1505. self assert: set printString equals: 'a Set (1 3 ''foo'')'.
  1506. set remove: 1; remove: 3.
  1507. self assert: set printString equals: 'a Set (''foo'')'.
  1508. set add: 3.
  1509. self assert: set printString equals: 'a Set (''foo'' 3)'.
  1510. set add: 3.
  1511. self assert: set printString equals: 'a Set (''foo'' 3)'
  1512. !
  1513. testSize
  1514. self assert: Set new size equals: 0.
  1515. self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
  1516. self assert: (Set withAll: #(1 1 1 1)) size equals: 1
  1517. !
  1518. testUnboxedObjects
  1519. self assert: {'foo' yourself. 'foo' yourself} asSet asArray equals: #('foo')
  1520. !
  1521. testUnicity
  1522. | set |
  1523. set := Set new.
  1524. set add: 21.
  1525. set add: 'hello'.
  1526. set add: 21.
  1527. self assert: set size equals: 2.
  1528. set add: 'hello'.
  1529. self assert: set size equals: 2.
  1530. self assert: set asArray equals: #(21 'hello')
  1531. ! !
  1532. TestCase subclass: #StreamTest
  1533. instanceVariableNames: ''
  1534. package: 'Kernel-Tests'!
  1535. !StreamTest methodsFor: 'accessing'!
  1536. collectionClass
  1537. ^ self class collectionClass
  1538. !
  1539. newCollection
  1540. ^ self collectionClass new
  1541. !
  1542. newStream
  1543. ^ self collectionClass new stream
  1544. ! !
  1545. !StreamTest methodsFor: 'tests'!
  1546. testAtStartAtEnd
  1547. | stream |
  1548. stream := self newStream.
  1549. self assert: stream atStart.
  1550. self assert: stream atEnd.
  1551. stream nextPutAll: self newCollection.
  1552. self assert: stream atEnd.
  1553. self deny: stream atStart.
  1554. stream position: 1.
  1555. self deny: stream atEnd.
  1556. self deny: stream atStart
  1557. !
  1558. testContents
  1559. | stream |
  1560. stream := self newStream.
  1561. stream nextPutAll: self newCollection.
  1562. self assert: stream contents equals: self newCollection
  1563. !
  1564. testIsEmpty
  1565. | stream |
  1566. stream := self newStream.
  1567. self assert: stream isEmpty.
  1568. stream nextPutAll: self newCollection.
  1569. self deny: stream isEmpty
  1570. !
  1571. testPosition
  1572. | collection stream |
  1573. collection := self newCollection.
  1574. stream := self newStream.
  1575. stream nextPutAll: collection.
  1576. self assert: stream position equals: collection size.
  1577. stream position: 0.
  1578. self assert: stream position equals: 0.
  1579. stream next.
  1580. self assert: stream position equals: 1.
  1581. stream next.
  1582. self assert: stream position equals: 2
  1583. !
  1584. testReading
  1585. | stream collection |
  1586. collection := self newCollection.
  1587. stream := self newStream.
  1588. stream
  1589. nextPutAll: collection;
  1590. position: 0.
  1591. collection do: [ :each |
  1592. self assert: stream next equals: each ].
  1593. self assert: stream next isNil
  1594. !
  1595. testStreamContents
  1596. !
  1597. testWrite
  1598. | stream collection |
  1599. collection := self newCollection.
  1600. stream := self newStream.
  1601. collection do: [ :each | stream << each ].
  1602. self assert: stream contents equals: collection
  1603. !
  1604. testWriting
  1605. | stream collection |
  1606. collection := self newCollection.
  1607. stream := self newStream.
  1608. collection do: [ :each | stream nextPut: each ].
  1609. self assert: stream contents equals: collection.
  1610. stream := self newStream.
  1611. stream nextPutAll: collection.
  1612. self assert: stream contents equals: collection
  1613. ! !
  1614. !StreamTest class methodsFor: 'accessing'!
  1615. collectionClass
  1616. ^ nil
  1617. ! !
  1618. !StreamTest class methodsFor: 'testing'!
  1619. isAbstract
  1620. ^ self collectionClass isNil
  1621. ! !
  1622. StreamTest subclass: #ArrayStreamTest
  1623. instanceVariableNames: ''
  1624. package: 'Kernel-Tests'!
  1625. !ArrayStreamTest methodsFor: 'accessing'!
  1626. newCollection
  1627. ^ { true. 1. 3@4. 'foo' }
  1628. ! !
  1629. !ArrayStreamTest class methodsFor: 'accessing'!
  1630. collectionClass
  1631. ^ Array
  1632. ! !
  1633. StreamTest subclass: #StringStreamTest
  1634. instanceVariableNames: ''
  1635. package: 'Kernel-Tests'!
  1636. !StringStreamTest methodsFor: 'accessing'!
  1637. newCollection
  1638. ^ 'hello world'
  1639. ! !
  1640. !StringStreamTest class methodsFor: 'accessing'!
  1641. collectionClass
  1642. ^ String
  1643. ! !
  1644. TestCase subclass: #UndefinedTest
  1645. instanceVariableNames: ''
  1646. package: 'Kernel-Tests'!
  1647. !UndefinedTest methodsFor: 'tests'!
  1648. testCopying
  1649. self assert: nil copy equals: nil
  1650. !
  1651. testDeepCopy
  1652. self assert: nil deepCopy = nil
  1653. !
  1654. testIfNil
  1655. self assert: (nil ifNil: [true]) equals: true.
  1656. self deny: (nil ifNotNil: [true]) = true.
  1657. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  1658. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  1659. !
  1660. testIsNil
  1661. self assert: nil isNil.
  1662. self deny: nil notNil.
  1663. ! !