2
0

Kernel-Tests.st 22 KB

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