Kernel-Tests.st 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. Smalltalk current createPackage: 'Kernel-Tests' properties: #{}!
  2. TestCase subclass: #ArrayTest
  3. instanceVariableNames: ''
  4. category: 'Kernel-Tests'!
  5. !ArrayTest methodsFor: 'testing'!
  6. testFirstN
  7. self assert: {1. 2. 3} equals: ({1. 2. 3. 4. 5} first: 3).
  8. !
  9. testIfEmpty
  10. self assert: 'zork' equals: ( '' ifEmpty: ['zork'] )
  11. ! !
  12. TestCase subclass: #StringTest
  13. instanceVariableNames: ''
  14. category: 'Kernel-Tests'!
  15. !StringTest methodsFor: 'tests'!
  16. testJoin
  17. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  18. !
  19. testStreamContents
  20. self
  21. assert: 'hello world'
  22. equals: (String streamContents: [:aStream| aStream
  23. nextPutAll: 'hello'; space;
  24. nextPutAll: 'world'])
  25. !
  26. testIncludesSubString
  27. self assert: ('amber' includesSubString: 'ber').
  28. self deny: ('amber' includesSubString: 'zork').
  29. !
  30. testEquality
  31. self assert: 'hello' = 'hello'.
  32. self deny: 'hello' = 'world'.
  33. self assert: 'hello' = 'hello' yourself.
  34. self assert: 'hello' yourself = 'hello'.
  35. "test JS falsy value"
  36. self deny: '' = 0
  37. !
  38. testCopyWithoutAll
  39. self
  40. assert: 'hello world'
  41. equals: ('*hello* *world*' copyWithoutAll: '*')
  42. !
  43. testAt
  44. self assert: ('hello' at: 1) = 'h'.
  45. self assert: ('hello' at: 5) = 'o'.
  46. self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
  47. !
  48. testAtPut
  49. "String instances are read-only"
  50. self should: ['hello' at: 1 put: 'a'] raise: Error
  51. !
  52. testSize
  53. self assert: 'smalltalk' size equals: 9.
  54. self assert: '' size equals: 0
  55. !
  56. testAddRemove
  57. self should: ['hello' add: 'a'] raise: Error.
  58. self should: ['hello' remove: 'h'] raise: Error
  59. !
  60. testAsArray
  61. self assert: 'hello' asArray = #('h' 'e' 'l' 'l' 'o').
  62. ! !
  63. TestCase subclass: #DictionaryTest
  64. instanceVariableNames: ''
  65. category: 'Kernel-Tests'!
  66. !DictionaryTest methodsFor: 'tests'!
  67. testPrintString
  68. self
  69. assert: 'a Dictionary(''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  70. equals: (Dictionary new
  71. at:'firstname' put: 'James';
  72. at:'lastname' put: 'Bond';
  73. printString)
  74. !
  75. testEquality
  76. | d1 d2 |
  77. self assert: Dictionary new = Dictionary new.
  78. d1 := Dictionary new at: 1 put: 2; yourself.
  79. d2 := Dictionary new at: 1 put: 2; yourself.
  80. self assert: d1 = d2.
  81. d2 := Dictionary new at: 1 put: 3; yourself.
  82. self deny: d1 = d2.
  83. d2 := Dictionary new at: 2 put: 2; yourself.
  84. self deny: d1 = d2.
  85. d2 := Dictionary new at: 1 put: 2; at: 3 put: 4; yourself.
  86. self deny: d1 = d2.
  87. !
  88. testDynamicDictionaries
  89. self assert: #{'hello' -> 1} asDictionary = (Dictionary with: 'hello' -> 1)
  90. !
  91. testAccessing
  92. | d |
  93. d := Dictionary new.
  94. d at: 'hello' put: 'world'.
  95. self assert: (d at: 'hello') = 'world'.
  96. self assert: (d at: 'hello' ifAbsent: [nil]) = 'world'.
  97. self deny: (d at: 'foo' ifAbsent: [nil]) = 'world'.
  98. d at: 1 put: 2.
  99. self assert: (d at: 1) = 2.
  100. d at: 1@3 put: 3.
  101. self assert: (d at: 1@3) = 3
  102. !
  103. testSize
  104. | d |
  105. d := Dictionary new.
  106. self assert: d size = 0.
  107. d at: 1 put: 2.
  108. self assert: d size = 1.
  109. d at: 2 put: 3.
  110. self assert: d size = 2.
  111. !
  112. testValues
  113. | d |
  114. d := Dictionary new.
  115. d at: 1 put: 2.
  116. d at: 2 put: 3.
  117. d at: 3 put: 4.
  118. self assert: d values = #(2 3 4)
  119. !
  120. testKeys
  121. | d |
  122. d := Dictionary new.
  123. d at: 1 put: 2.
  124. d at: 2 put: 3.
  125. d at: 3 put: 4.
  126. self assert: d keys = #(1 2 3)
  127. ! !
  128. TestCase subclass: #BooleanTest
  129. instanceVariableNames: ''
  130. category: 'Kernel-Tests'!
  131. !BooleanTest methodsFor: 'tests'!
  132. testLogic
  133. "Trivial logic table"
  134. self assert: (true & true); deny: (true & false); deny: (false & true); deny: (false & false).
  135. self assert: (true | true); assert: (true | false); assert: (false | true); deny: (false | false).
  136. "Checking that expressions work fine too"
  137. self assert: (true & (1 > 0)); deny: ((1 > 0) & false); deny: ((1 > 0) & (1 > 2)).
  138. self assert: (false | (1 > 0)); assert: ((1 > 0) | false); assert: ((1 > 0) | (1 > 2))
  139. !
  140. testEquality
  141. "We're on top of JS...just be sure to check the basics!!"
  142. self deny: 0 = false.
  143. self deny: false = 0.
  144. self deny: '' = false.
  145. self deny: false = ''.
  146. self assert: true = true.
  147. self deny: false = true.
  148. self deny: true = false.
  149. self assert: false = false.
  150. "JS may do some type coercing after sending a message"
  151. self assert: true yourself = true.
  152. self assert: true yourself = true yourself
  153. !
  154. testLogicKeywords
  155. "Trivial logic table"
  156. self
  157. assert: (true and: [ true]);
  158. deny: (true and: [ false ]);
  159. deny: (false and: [ true ]);
  160. deny: (false and: [ false ]).
  161. self
  162. assert: (true or: [ true ]);
  163. assert: (true or: [ false ]);
  164. assert: (false or: [ true ]);
  165. deny: (false or: [ false ]).
  166. "Checking that expressions work fine too"
  167. self
  168. assert: (true and: [ 1 > 0 ]);
  169. deny: ((1 > 0) and: [ false ]);
  170. deny: ((1 > 0) and: [ 1 > 2 ]).
  171. self
  172. assert: (false or: [ 1 > 0 ]);
  173. assert: ((1 > 0) or: [ false ]);
  174. assert: ((1 > 0) or: [ 1 > 2 ])
  175. !
  176. testIfTrueIfFalse
  177. self assert: (true ifTrue: ['alternative block']) = 'alternative block'.
  178. self assert: (true ifFalse: ['alternative block']) = nil.
  179. self assert: (false ifTrue: ['alternative block']) = nil.
  180. self assert: (false ifFalse: ['alternative block']) = 'alternative block'.
  181. self assert: (false ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
  182. self assert: (false ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
  183. self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
  184. self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
  185. ! !
  186. TestCase subclass: #NumberTest
  187. instanceVariableNames: ''
  188. category: 'Kernel-Tests'!
  189. !NumberTest methodsFor: 'tests'!
  190. testPrintShowingDecimalPlaces
  191. self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
  192. self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
  193. self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
  194. self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
  195. self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
  196. self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
  197. self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
  198. self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
  199. self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
  200. self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
  201. self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
  202. self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
  203. self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
  204. !
  205. testEquality
  206. self assert: 1 = 1.
  207. self assert: 0 = 0.
  208. self deny: 1 = 0.
  209. self assert: 1 yourself = 1.
  210. self assert: 1 = 1 yourself.
  211. self assert: 1 yourself = 1 yourself.
  212. self deny: 0 = false.
  213. self deny: false = 0.
  214. self deny: '' = 0.
  215. self deny: 0 = ''
  216. !
  217. testArithmetic
  218. "We rely on JS here, so we won't test complex behavior, just check if
  219. message sends are corrects"
  220. self assert: 1.5 + 1 = 2.5.
  221. self assert: 2 - 1 = 1.
  222. self assert: -2 - 1 = -3.
  223. self assert: 12 / 2 = 6.
  224. self assert: 3 * 4 = 12.
  225. "Simple parenthesis and execution order"
  226. self assert: 1 + 2 * 3 = 9.
  227. self assert: 1 + (2 * 3) = 7
  228. !
  229. testRounded
  230. self assert: 3 rounded = 3.
  231. self assert: 3.212 rounded = 3.
  232. self assert: 3.51 rounded = 4
  233. !
  234. testNegated
  235. self assert: 3 negated = -3.
  236. self assert: -3 negated = 3
  237. !
  238. testComparison
  239. self assert: 3 > 2.
  240. self assert: 2 < 3.
  241. self deny: 3 < 2.
  242. self deny: 2 > 3.
  243. self assert: 3 >= 3.
  244. self assert: 3.1 >= 3.
  245. self assert: 3 <= 3.
  246. self assert: 3 <= 3.1
  247. !
  248. testTruncated
  249. self assert: 3 truncated = 3.
  250. self assert: 3.212 truncated = 3.
  251. self assert: 3.51 truncated = 3
  252. !
  253. testCopying
  254. self assert: 1 copy == 1.
  255. self assert: 1 deepCopy == 1
  256. !
  257. testMinMax
  258. self assert: (2 max: 5) equals: 5.
  259. self assert: (2 min: 5) equals: 2
  260. !
  261. testIdentity
  262. self assert: 1 == 1.
  263. self assert: 0 == 0.
  264. self deny: 1 == 0.
  265. self assert: 1 yourself == 1.
  266. self assert: 1 == 1 yourself.
  267. self assert: 1 yourself == 1 yourself.
  268. self deny: 1 == 2
  269. !
  270. testSqrt
  271. self assert: 4 sqrt = 2.
  272. self assert: 16 sqrt = 4
  273. !
  274. testSquared
  275. self assert: 4 squared = 16
  276. !
  277. testTimesRepeat
  278. | i |
  279. i := 0.
  280. 0 timesRepeat: [i := i + 1].
  281. self assert: i equals: 0.
  282. 5 timesRepeat: [i := i + 1].
  283. self assert: i equals: 5
  284. !
  285. testTo
  286. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  287. !
  288. testToBy
  289. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  290. self should: [1 to: 4 by: 0] raise: Error
  291. ! !
  292. TestCase subclass: #JSObjectProxyTest
  293. instanceVariableNames: ''
  294. category: 'Kernel-Tests'!
  295. !JSObjectProxyTest methodsFor: 'accessing'!
  296. jsObject
  297. <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}}>
  298. ! !
  299. !JSObjectProxyTest methodsFor: 'tests'!
  300. testMethodWithArguments
  301. self deny: ('body' asJQuery hasClass: 'amber').
  302. 'body' asJQuery addClass: 'amber'.
  303. self assert: ('body' asJQuery hasClass: 'amber').
  304. 'body' asJQuery removeClass: 'amber'.
  305. self deny: ('body' asJQuery hasClass: 'amber').
  306. !
  307. testYourself
  308. |body|
  309. body := 'body' asJQuery
  310. addClass: 'amber';
  311. yourself.
  312. self assert: (body hasClass: 'amber').
  313. body removeClass: 'amber'.
  314. self deny: (body hasClass: 'amber').
  315. !
  316. testPropertyThatReturnsEmptyString
  317. <document.location.hash = ''>.
  318. self assert: '' equals: document location hash.
  319. document location hash: 'test'.
  320. self assert: '#test' equals: document location hash.
  321. !
  322. testDNU
  323. self should: [self jsObject foo] raise: MessageNotUnderstood
  324. !
  325. testMessageSend
  326. self assert: self jsObject a equals: 1.
  327. self assert: self jsObject b equals: 2.
  328. self assert: (self jsObject c: 3) equals: 3
  329. !
  330. testPrinting
  331. self assert: self jsObject printString = '[object Object]'
  332. ! !
  333. TestCase subclass: #PackageTest
  334. instanceVariableNames: 'zorkPackage grulPackage backUpCommitPathJs backUpCommitPathSt'
  335. category: 'Kernel-Tests'!
  336. !PackageTest methodsFor: 'running'!
  337. setUp
  338. backUpCommitPathJs := Package defaultCommitPathJs.
  339. backUpCommitPathSt := Package defaultCommitPathSt.
  340. Package resetCommitPaths.
  341. zorkPackage := Package new name: 'Zork'.
  342. grulPackage := Package new
  343. name: 'Grul';
  344. commitPathJs: 'server/grul/js';
  345. commitPathSt: 'grul/st';
  346. yourself
  347. !
  348. tearDown
  349. Package
  350. defaultCommitPathJs: backUpCommitPathJs;
  351. defaultCommitPathSt: backUpCommitPathSt
  352. ! !
  353. !PackageTest methodsFor: 'tests'!
  354. testGrulCommitPathStShouldBeGrulSt
  355. self assert: 'grul/st' equals: grulPackage commitPathSt
  356. !
  357. testZorkCommitPathStShouldBeSt
  358. self assert: 'st' equals: zorkPackage commitPathSt
  359. !
  360. testZorkCommitPathJsShouldBeJs
  361. self assert: 'js' equals: zorkPackage commitPathJs
  362. !
  363. testGrulCommitPathJsShouldBeServerGrulJs
  364. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  365. ! !
  366. TestCase subclass: #BlockClosureTest
  367. instanceVariableNames: ''
  368. category: 'Kernel-Tests'!
  369. !BlockClosureTest methodsFor: 'tests'!
  370. testValue
  371. self assert: ([1+1] value) equals: 2.
  372. self assert: ([:x | x +1] value: 2) equals: 3.
  373. self assert: ([:x :y | x*y] value: 2 value: 4) equals: 8.
  374. "Arguments are optional in Amber. This isn't ANSI compliant."
  375. self assert: ([:a :b :c | 1] value) equals: 1
  376. !
  377. testOnDo
  378. self assert: ([Error new signal] on: Error do: [:ex | true])
  379. !
  380. testEnsure
  381. self assert: ([Error new] ensure: [true])
  382. !
  383. testNumArgs
  384. self assert: [] numArgs equals: 0.
  385. self assert: [:a :b | ] numArgs equals: 2
  386. !
  387. testValueWithPossibleArguments
  388. self assert: ([1] valueWithPossibleArguments: #(3 4)) equals: 1.
  389. self assert: ([:a | a + 4] valueWithPossibleArguments: #(3 4)) equals: 7.
  390. self assert: ([:a :b | a + b] valueWithPossibleArguments: #(3 4 5)) equals: 7.
  391. !
  392. testWhileTrue
  393. | i |
  394. i := 0.
  395. [i < 5] whileTrue: [i := i + 1].
  396. self assert: i equals: 5.
  397. i := 0.
  398. [i := i + 1. i < 5] whileTrue.
  399. self assert: i equals: 5
  400. !
  401. testWhileFalse
  402. | i |
  403. i := 0.
  404. [i > 5] whileFalse: [i := i + 1].
  405. self assert: i equals: 6.
  406. i := 0.
  407. [i := i + 1. i > 5] whileFalse.
  408. self assert: i equals: 6
  409. !
  410. testCompiledSource
  411. self assert: ([1+1] compiledSource includesSubString: 'function')
  412. ! !
  413. TestCase subclass: #ObjectTest
  414. instanceVariableNames: ''
  415. category: 'Kernel-Tests'!
  416. !ObjectTest methodsFor: 'tests'!
  417. testEquality
  418. | o |
  419. o := Object new.
  420. self deny: o = Object new.
  421. self assert: o = o.
  422. self assert: o yourself = o.
  423. self assert: o = o yourself
  424. !
  425. testIdentity
  426. | o |
  427. o := Object new.
  428. self deny: o == Object new.
  429. self assert: o == o
  430. !
  431. testHalt
  432. self should: [Object new halt] raise: Error
  433. !
  434. testBasicAccess
  435. | o |
  436. o := Object new.
  437. o basicAt: 'a' put: 1.
  438. self assert: (o basicAt: 'a') equals: 1.
  439. self assert: (o basicAt: 'b') equals: nil
  440. !
  441. testNilUndefined
  442. "nil in Smalltalk is the undefined object in JS"
  443. self assert: nil = undefined
  444. !
  445. testidentityHash
  446. | o1 o2 |
  447. o1 := Object new.
  448. o2 := Object new.
  449. self assert: o1 identityHash == o1 identityHash.
  450. self deny: o1 identityHash == o2 identityHash
  451. !
  452. testBasicPerform
  453. | o |
  454. o := Object new.
  455. o basicAt: 'func' put: ['hello'].
  456. o basicAt: 'func2' put: [:a | a + 1].
  457. self assert: (o basicPerform: 'func') equals: 'hello'.
  458. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  459. !
  460. testIfNil
  461. self deny: Object new isNil.
  462. self deny: (Object new ifNil: [true]) = true.
  463. self assert: (Object new ifNotNil: [true]) = true.
  464. self assert: (Object new ifNil: [false] ifNotNil: [true]) = true.
  465. self assert: (Object new ifNotNil: [true] ifNil: [false]) = true
  466. !
  467. testInstVars
  468. | o |
  469. o := ObjectMock new.
  470. self assert: (o instVarAt: #foo) equals: nil.
  471. o instVarAt: #foo put: 1.
  472. self assert: (o instVarAt: #foo) equals: 1.
  473. self assert: (o instVarAt: 'foo') equals: 1
  474. !
  475. testYourself
  476. | o |
  477. o := ObjectMock new.
  478. self assert: o yourself == o
  479. !
  480. testDNU
  481. self should: [Object new foo] raise: MessageNotUnderstood
  482. ! !
  483. TestCase subclass: #SymbolTest
  484. instanceVariableNames: ''
  485. category: 'Kernel-Tests'!
  486. !SymbolTest methodsFor: 'tests'!
  487. testEquality
  488. self assert: #hello = #hello.
  489. self deny: #hello = #world.
  490. self assert: #hello = #hello yourself.
  491. self assert: #hello yourself = #hello.
  492. self deny: #hello = 'hello'.
  493. self deny: 'hello' = #hello.
  494. !
  495. testAt
  496. self assert: (#hello at: 1) = 'h'.
  497. self assert: (#hello at: 5) = 'o'.
  498. self assert: (#hello at: 6 ifAbsent: [nil]) = nil
  499. !
  500. testAtPut
  501. "Symbol instances are read-only"
  502. self should: ['hello' at: 1 put: 'a'] raise: Error
  503. !
  504. testIdentity
  505. self assert: #hello == #hello.
  506. self deny: #hello == #world.
  507. self assert: #hello = #hello yourself.
  508. self assert: #hello yourself = #hello asString asSymbol
  509. !
  510. testComparing
  511. self assert: #ab > #aa.
  512. self deny: #ab > #ba.
  513. self assert: #ab < #ba.
  514. self deny: #bb < #ba.
  515. self assert: #ab >= #aa.
  516. self deny: #ab >= #ba.
  517. self assert: #ab <= #ba.
  518. self deny: #bb <= #ba
  519. !
  520. testSize
  521. self assert: #a size equals: 1.
  522. self assert: #aaaaa size equals: 5
  523. !
  524. testAsString
  525. self assert: #hello asString equals: 'hello'
  526. !
  527. testAsSymbol
  528. self assert: #hello == #hello asSymbol
  529. !
  530. testCopying
  531. self assert: #hello copy == #hello.
  532. self assert: #hello deepCopy == #hello
  533. !
  534. testIsSymbolIsString
  535. self assert: #hello isSymbol.
  536. self deny: 'hello' isSymbol.
  537. self deny: #hello isString.
  538. self assert: 'hello' isString
  539. ! !
  540. Object subclass: #ObjectMock
  541. instanceVariableNames: 'foo bar'
  542. category: 'Kernel-Tests'!
  543. !ObjectMock methodsFor: 'not yet classified'!
  544. foo
  545. ^foo
  546. !
  547. foo: anObject
  548. foo := anObject
  549. ! !
  550. TestCase subclass: #UndefinedTest
  551. instanceVariableNames: ''
  552. category: 'Kernel-Tests'!
  553. !UndefinedTest methodsFor: 'tests'!
  554. testIsNil
  555. self assert: nil isNil.
  556. self deny: nil notNil.
  557. !
  558. testIfNil
  559. self assert: (nil ifNil: [true]) equals: true.
  560. self deny: (nil ifNotNil: [true]) = true.
  561. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  562. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  563. !
  564. testCopying
  565. self assert: nil copy equals: nil
  566. !
  567. testDeepCopy
  568. self assert: nil deepCopy = nil
  569. ! !
  570. TestCase subclass: #PointTest
  571. instanceVariableNames: ''
  572. category: 'Kernel-Tests'!
  573. !PointTest methodsFor: 'tests'!
  574. testAccessing
  575. self assert: (Point x: 3 y: 4) x equals: 3.
  576. self assert: (Point x: 3 y: 4) y equals: 4.
  577. self assert: (Point new x: 3) x equals: 3.
  578. self assert: (Point new y: 4) y equals: 4
  579. !
  580. testAt
  581. self assert: 3@4 equals: (Point x: 3 y: 4)
  582. !
  583. testEgality
  584. self assert: 3@4 = (3@4).
  585. self deny: 3@5 = (3@6)
  586. !
  587. testArithmetic
  588. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  589. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  590. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  591. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  592. !
  593. testTranslateBy
  594. self assert: 3@4 equals: (3@3 translateBy: 0@1).
  595. self assert: 3@2 equals: (3@3 translateBy: 0@1 negated).
  596. self assert: 5@6 equals: (3@3 translateBy: 2@3).
  597. self assert: 0@3 equals: (3@3 translateBy: 3 negated @0).
  598. ! !
  599. TestCase subclass: #RandomTest
  600. instanceVariableNames: ''
  601. category: 'Kernel-Tests'!
  602. !RandomTest methodsFor: 'tests'!
  603. textNext
  604. 10000 timesRepeat: [
  605. | current next |
  606. next := Random new next.
  607. self assert: (next >= 0).
  608. self assert: (next < 1).
  609. self deny: current = next.
  610. next = current]
  611. ! !
  612. TestCase subclass: #ClassBuilderTest
  613. instanceVariableNames: 'builder theClass'
  614. category: 'Kernel-Tests'!
  615. !ClassBuilderTest methodsFor: 'running'!
  616. setUp
  617. builder := ClassBuilder new
  618. !
  619. tearDown
  620. theClass ifNotNil: [Smalltalk current removeClass: theClass. theClass := nil]
  621. !
  622. testClassCopy
  623. theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  624. self assert: theClass superclass == ObjectMock superclass.
  625. self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
  626. self assert: theClass name equals: 'ObjectMock2'.
  627. self assert: theClass package == ObjectMock package.
  628. self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
  629. !
  630. testInstanceVariableNames
  631. self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
  632. ! !
  633. TestCase subclass: #SetTest
  634. instanceVariableNames: ''
  635. category: 'Kernel-Tests'!
  636. !SetTest methodsFor: 'tests'!
  637. testUnicity
  638. | set |
  639. set := Set new.
  640. set add: 21.
  641. set add: 'hello'.
  642. set add: 21.
  643. self assert: set size = 2.
  644. set add: 'hello'.
  645. self assert: set size = 2.
  646. self assert: set asArray equals: #(21 'hello')
  647. !
  648. testAt
  649. self should: [Set new at: 1 put: 2] raise: Error
  650. !
  651. testAddRemove
  652. | set |
  653. set := Set new.
  654. self assert: set isEmpty.
  655. set add: 3.
  656. self assert: (set includes: 3).
  657. set add: 5.
  658. self assert: (set includes: 5).
  659. set remove: 3.
  660. self deny: (set includes: 3)
  661. !
  662. testSize
  663. self assert: Set new size equals: 0.
  664. self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
  665. self assert: (Set withAll: #(1 1 1 1)) size equals: 1
  666. ! !
  667. PackageTest subclass: #PackageWithDefaultCommitPathChangedTest
  668. instanceVariableNames: ''
  669. category: 'Kernel-Tests'!
  670. !PackageWithDefaultCommitPathChangedTest methodsFor: 'running'!
  671. setUp
  672. super setUp.
  673. Package
  674. defaultCommitPathJs: 'javascripts/';
  675. defaultCommitPathSt: 'smalltalk/'.
  676. ! !
  677. !PackageWithDefaultCommitPathChangedTest methodsFor: 'tests'!
  678. testGrulCommitPathJsShouldBeServerGrulJs
  679. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  680. !
  681. testGrulCommitPathStShouldBeGrulSt
  682. self assert: 'grul/st' equals: grulPackage commitPathSt
  683. !
  684. testZorkCommitPathJsShouldBeJavascript
  685. self assert: 'javascripts/' equals: zorkPackage commitPathJs
  686. !
  687. testZorkCommitPathStShouldBeSmalltalk
  688. self assert: 'smalltalk/' equals: zorkPackage commitPathSt
  689. ! !
  690. !PackageWithDefaultCommitPathChangedTest class methodsFor: 'accessing'!
  691. shouldInheritSelectors
  692. ^ false
  693. ! !