1
0

Kernel-Tests.st 34 KB

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