Kernel-Tests.st 36 KB

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