1
0

Kernel-Tests.st 19 KB

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