1
0

Kernel-Tests.st 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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. testIfAbsent
  210. | d visited |
  211. visited := false.
  212. d := Dictionary new.
  213. d at: 'hello' ifAbsent: [ visited := true ].
  214. self assert: visited.
  215. !
  216. testIfPresent
  217. | d visited absent |
  218. visited := false.
  219. d := Dictionary new.
  220. d at: 'hello' put: 'world'.
  221. d at: 'hello' ifPresent: [ :value | visited := value ].
  222. self assert: visited = 'world'.
  223. absent := d at: 'bye' ifPresent: [ :value | visited := value ].
  224. self assert: absent isNil.
  225. !
  226. testIfPresentIfAbsent
  227. | d visited |
  228. visited := false.
  229. d := Dictionary new.
  230. d at: 'hello' put: 'world'.
  231. d at: 'hello' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  232. self assert: visited = 'world'.
  233. d at: 'buy' ifPresent: [ :value | visited := value ] ifAbsent: [ visited := true ].
  234. self assert: visited.
  235. !
  236. testKeys
  237. | d |
  238. d := Dictionary new.
  239. d at: 1 put: 2.
  240. d at: 2 put: 3.
  241. d at: 3 put: 4.
  242. self assert: d keys = #(1 2 3)
  243. !
  244. testPrintString
  245. self
  246. assert: 'a Dictionary(''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  247. equals: (Dictionary new
  248. at:'firstname' put: 'James';
  249. at:'lastname' put: 'Bond';
  250. printString)
  251. !
  252. testRemoveKey
  253. | d key |
  254. d := Dictionary new.
  255. d at: 1 put: 2.
  256. d at: 2 put: 3.
  257. d at: 3 put: 4.
  258. key := 2.
  259. self assert: d keys = #(1 2 3).
  260. d removeKey: key.
  261. self assert: d keys = #(1 3).
  262. self assert: d values = #(2 4).
  263. self deny: (d includesKey: 2)
  264. !
  265. testRemoveKeyIfAbsent
  266. | d key |
  267. d := Dictionary new.
  268. d at: 1 put: 2.
  269. d at: 2 put: 3.
  270. d at: 3 put: 4.
  271. key := 2.
  272. self assert: (d removeKey: key) = 3.
  273. key := 3.
  274. self assert: (d removeKey: key ifAbsent: [42]) = 4.
  275. key := 'why'.
  276. self assert: (d removeKey: key ifAbsent: [42] ) = 42.
  277. !
  278. testSize
  279. | d |
  280. d := Dictionary new.
  281. self assert: d size = 0.
  282. d at: 1 put: 2.
  283. self assert: d size = 1.
  284. d at: 2 put: 3.
  285. self assert: d size = 2.
  286. !
  287. testValues
  288. | d |
  289. d := Dictionary new.
  290. d at: 1 put: 2.
  291. d at: 2 put: 3.
  292. d at: 3 put: 4.
  293. self assert: d values = #(2 3 4)
  294. ! !
  295. TestCase subclass: #JSObjectProxyTest
  296. instanceVariableNames: ''
  297. package: 'Kernel-Tests'!
  298. !JSObjectProxyTest methodsFor: 'accessing'!
  299. jsObject
  300. <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}}>
  301. ! !
  302. !JSObjectProxyTest methodsFor: 'tests'!
  303. testDNU
  304. self should: [self jsObject foo] raise: MessageNotUnderstood
  305. !
  306. testMessageSend
  307. self assert: self jsObject a equals: 1.
  308. self assert: self jsObject b equals: 2.
  309. self assert: (self jsObject c: 3) equals: 3
  310. !
  311. testMethodWithArguments
  312. self deny: ('body' asJQuery hasClass: 'amber').
  313. 'body' asJQuery addClass: 'amber'.
  314. self assert: ('body' asJQuery hasClass: 'amber').
  315. 'body' asJQuery removeClass: 'amber'.
  316. self deny: ('body' asJQuery hasClass: 'amber').
  317. !
  318. testPrinting
  319. self assert: self jsObject printString = '[object Object]'
  320. !
  321. testPropertyThatReturnsEmptyString
  322. <document.location.hash = ''>.
  323. self assert: '' equals: document location hash.
  324. document location hash: 'test'.
  325. self assert: '#test' equals: document location hash.
  326. !
  327. testYourself
  328. |body|
  329. body := 'body' asJQuery
  330. addClass: 'amber';
  331. yourself.
  332. self assert: (body hasClass: 'amber').
  333. body removeClass: 'amber'.
  334. self deny: (body hasClass: 'amber').
  335. ! !
  336. TestCase subclass: #NumberTest
  337. instanceVariableNames: ''
  338. package: 'Kernel-Tests'!
  339. !NumberTest methodsFor: 'tests'!
  340. testArithmetic
  341. "We rely on JS here, so we won't test complex behavior, just check if
  342. message sends are corrects"
  343. self assert: 1.5 + 1 = 2.5.
  344. self assert: 2 - 1 = 1.
  345. self assert: -2 - 1 = -3.
  346. self assert: 12 / 2 = 6.
  347. self assert: 3 * 4 = 12.
  348. "Simple parenthesis and execution order"
  349. self assert: 1 + 2 * 3 = 9.
  350. self assert: 1 + (2 * 3) = 7
  351. !
  352. testComparison
  353. self assert: 3 > 2.
  354. self assert: 2 < 3.
  355. self deny: 3 < 2.
  356. self deny: 2 > 3.
  357. self assert: 3 >= 3.
  358. self assert: 3.1 >= 3.
  359. self assert: 3 <= 3.
  360. self assert: 3 <= 3.1
  361. !
  362. testCopying
  363. self assert: 1 copy == 1.
  364. self assert: 1 deepCopy == 1
  365. !
  366. testEquality
  367. self assert: 1 = 1.
  368. self assert: 0 = 0.
  369. self deny: 1 = 0.
  370. self assert: 1 yourself = 1.
  371. self assert: 1 = 1 yourself.
  372. self assert: 1 yourself = 1 yourself.
  373. self deny: 0 = false.
  374. self deny: false = 0.
  375. self deny: '' = 0.
  376. self deny: 0 = ''
  377. !
  378. testIdentity
  379. self assert: 1 == 1.
  380. self assert: 0 == 0.
  381. self deny: 1 == 0.
  382. self assert: 1 yourself == 1.
  383. self assert: 1 == 1 yourself.
  384. self assert: 1 yourself == 1 yourself.
  385. self deny: 1 == 2
  386. !
  387. testMinMax
  388. self assert: (2 max: 5) equals: 5.
  389. self assert: (2 min: 5) equals: 2
  390. !
  391. testNegated
  392. self assert: 3 negated = -3.
  393. self assert: -3 negated = 3
  394. !
  395. testPrintShowingDecimalPlaces
  396. self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
  397. self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
  398. self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
  399. self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
  400. self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
  401. self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
  402. self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
  403. self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
  404. self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
  405. self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
  406. self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
  407. self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
  408. self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
  409. !
  410. testRounded
  411. self assert: 3 rounded = 3.
  412. self assert: 3.212 rounded = 3.
  413. self assert: 3.51 rounded = 4
  414. !
  415. testSqrt
  416. self assert: 4 sqrt = 2.
  417. self assert: 16 sqrt = 4
  418. !
  419. testSquared
  420. self assert: 4 squared = 16
  421. !
  422. testTimesRepeat
  423. | i |
  424. i := 0.
  425. 0 timesRepeat: [i := i + 1].
  426. self assert: i equals: 0.
  427. 5 timesRepeat: [i := i + 1].
  428. self assert: i equals: 5
  429. !
  430. testTo
  431. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  432. !
  433. testToBy
  434. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  435. self should: [1 to: 4 by: 0] raise: Error
  436. !
  437. testTruncated
  438. self assert: 3 truncated = 3.
  439. self assert: 3.212 truncated = 3.
  440. self assert: 3.51 truncated = 3
  441. ! !
  442. Object subclass: #ObjectMock
  443. instanceVariableNames: 'foo bar'
  444. package: 'Kernel-Tests'!
  445. !ObjectMock methodsFor: 'not yet classified'!
  446. foo
  447. ^foo
  448. !
  449. foo: anObject
  450. foo := anObject
  451. ! !
  452. TestCase subclass: #ObjectTest
  453. instanceVariableNames: ''
  454. package: 'Kernel-Tests'!
  455. !ObjectTest methodsFor: 'tests'!
  456. testBasicAccess
  457. | o |
  458. o := Object new.
  459. o basicAt: 'a' put: 1.
  460. self assert: (o basicAt: 'a') equals: 1.
  461. self assert: (o basicAt: 'b') equals: nil
  462. !
  463. testBasicPerform
  464. | o |
  465. o := Object new.
  466. o basicAt: 'func' put: ['hello'].
  467. o basicAt: 'func2' put: [:a | a + 1].
  468. self assert: (o basicPerform: 'func') equals: 'hello'.
  469. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  470. !
  471. testDNU
  472. self should: [Object new foo] raise: MessageNotUnderstood
  473. !
  474. testEquality
  475. | o |
  476. o := Object new.
  477. self deny: o = Object new.
  478. self assert: o = o.
  479. self assert: o yourself = o.
  480. self assert: o = o yourself
  481. !
  482. testHalt
  483. self should: [Object new halt] raise: Error
  484. !
  485. testIdentity
  486. | o |
  487. o := Object new.
  488. self deny: o == Object new.
  489. self assert: o == o.
  490. self assert: o yourself == o.
  491. self assert: o == o yourself
  492. !
  493. testIfNil
  494. self deny: Object new isNil.
  495. self deny: (Object new ifNil: [true]) = true.
  496. self assert: (Object new ifNotNil: [true]) = true.
  497. self assert: (Object new ifNil: [false] ifNotNil: [true]) = true.
  498. self assert: (Object new ifNotNil: [true] ifNil: [false]) = true
  499. !
  500. testInstVars
  501. | o |
  502. o := ObjectMock new.
  503. self assert: (o instVarAt: #foo) equals: nil.
  504. o instVarAt: #foo put: 1.
  505. self assert: (o instVarAt: #foo) equals: 1.
  506. self assert: (o instVarAt: 'foo') equals: 1
  507. !
  508. testNilUndefined
  509. "nil in Smalltalk is the undefined object in JS"
  510. self assert: nil = undefined
  511. !
  512. testYourself
  513. | o |
  514. o := ObjectMock new.
  515. self assert: o yourself == o
  516. !
  517. testidentityHash
  518. | o1 o2 |
  519. o1 := Object new.
  520. o2 := Object new.
  521. self assert: o1 identityHash == o1 identityHash.
  522. self deny: o1 identityHash == o2 identityHash
  523. ! !
  524. TestCase subclass: #PackageTest
  525. instanceVariableNames: 'zorkPackage grulPackage backUpCommitPathJs backUpCommitPathSt'
  526. package: 'Kernel-Tests'!
  527. !PackageTest methodsFor: 'running'!
  528. setUp
  529. backUpCommitPathJs := Package defaultCommitPathJs.
  530. backUpCommitPathSt := Package defaultCommitPathSt.
  531. Package resetCommitPaths.
  532. zorkPackage := Package new name: 'Zork'.
  533. grulPackage := Package new
  534. name: 'Grul';
  535. commitPathJs: 'server/grul/js';
  536. commitPathSt: 'grul/st';
  537. yourself
  538. !
  539. tearDown
  540. Package
  541. defaultCommitPathJs: backUpCommitPathJs;
  542. defaultCommitPathSt: backUpCommitPathSt
  543. ! !
  544. !PackageTest methodsFor: 'tests'!
  545. testGrulCommitPathJsShouldBeServerGrulJs
  546. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  547. !
  548. testGrulCommitPathStShouldBeGrulSt
  549. self assert: 'grul/st' equals: grulPackage commitPathSt
  550. !
  551. testZorkCommitPathJsShouldBeJs
  552. self assert: 'js' equals: zorkPackage commitPathJs
  553. !
  554. testZorkCommitPathStShouldBeSt
  555. self assert: 'st' equals: zorkPackage commitPathSt
  556. ! !
  557. PackageTest subclass: #PackageWithDefaultCommitPathChangedTest
  558. instanceVariableNames: ''
  559. package: 'Kernel-Tests'!
  560. !PackageWithDefaultCommitPathChangedTest methodsFor: 'running'!
  561. setUp
  562. super setUp.
  563. Package
  564. defaultCommitPathJs: 'javascripts/';
  565. defaultCommitPathSt: 'smalltalk/'.
  566. ! !
  567. !PackageWithDefaultCommitPathChangedTest methodsFor: 'tests'!
  568. testGrulCommitPathJsShouldBeServerGrulJs
  569. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  570. !
  571. testGrulCommitPathStShouldBeGrulSt
  572. self assert: 'grul/st' equals: grulPackage commitPathSt
  573. !
  574. testZorkCommitPathJsShouldBeJavascript
  575. self assert: 'javascripts/' equals: zorkPackage commitPathJs
  576. !
  577. testZorkCommitPathStShouldBeSmalltalk
  578. self assert: 'smalltalk/' equals: zorkPackage commitPathSt
  579. ! !
  580. !PackageWithDefaultCommitPathChangedTest class methodsFor: 'accessing'!
  581. shouldInheritSelectors
  582. ^ false
  583. ! !
  584. TestCase subclass: #PointTest
  585. instanceVariableNames: ''
  586. package: 'Kernel-Tests'!
  587. !PointTest methodsFor: 'tests'!
  588. testAccessing
  589. self assert: (Point x: 3 y: 4) x equals: 3.
  590. self assert: (Point x: 3 y: 4) y equals: 4.
  591. self assert: (Point new x: 3) x equals: 3.
  592. self assert: (Point new y: 4) y equals: 4
  593. !
  594. testArithmetic
  595. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  596. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  597. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  598. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  599. !
  600. testAt
  601. self assert: 3@4 equals: (Point x: 3 y: 4)
  602. !
  603. testEgality
  604. self assert: 3@4 = (3@4).
  605. self deny: 3@5 = (3@6)
  606. !
  607. testTranslateBy
  608. self assert: 3@4 equals: (3@3 translateBy: 0@1).
  609. self assert: 3@2 equals: (3@3 translateBy: 0@1 negated).
  610. self assert: 5@6 equals: (3@3 translateBy: 2@3).
  611. self assert: 0@3 equals: (3@3 translateBy: 3 negated @0).
  612. ! !
  613. TestCase subclass: #RandomTest
  614. instanceVariableNames: ''
  615. package: 'Kernel-Tests'!
  616. !RandomTest methodsFor: 'tests'!
  617. textNext
  618. 10000 timesRepeat: [
  619. | current next |
  620. next := Random new next.
  621. self assert: (next >= 0).
  622. self assert: (next < 1).
  623. self deny: current = next.
  624. next = current]
  625. ! !
  626. TestCase subclass: #SetTest
  627. instanceVariableNames: ''
  628. package: 'Kernel-Tests'!
  629. !SetTest methodsFor: 'tests'!
  630. testAddRemove
  631. | set |
  632. set := Set new.
  633. self assert: set isEmpty.
  634. set add: 3.
  635. self assert: (set includes: 3).
  636. set add: 5.
  637. self assert: (set includes: 5).
  638. set remove: 3.
  639. self deny: (set includes: 3)
  640. !
  641. testAt
  642. self should: [Set new at: 1 put: 2] raise: Error
  643. !
  644. testPrintString
  645. | set |
  646. set := Set new.
  647. self assert: 'a Set ()' equals: ( set printString ).
  648. set add: 1; add: 3.
  649. self assert: 'a Set (1 3)' equals: ( set printString ).
  650. set add: 'foo'.
  651. self assert: 'a Set (1 3 ''foo'')' equals: ( set printString ).
  652. set remove: 1; remove: 3.
  653. self assert: 'a Set (''foo'')' equals: ( set printString ).
  654. set add: 3.
  655. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  656. set add: 3.
  657. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  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. testUnicity
  665. | set |
  666. set := Set new.
  667. set add: 21.
  668. set add: 'hello'.
  669. set add: 21.
  670. self assert: set size = 2.
  671. set add: 'hello'.
  672. self assert: set size = 2.
  673. self assert: set asArray equals: #(21 'hello')
  674. ! !
  675. TestCase subclass: #StringTest
  676. instanceVariableNames: ''
  677. package: 'Kernel-Tests'!
  678. !StringTest methodsFor: 'tests'!
  679. testAddRemove
  680. self should: ['hello' add: 'a'] raise: Error.
  681. self should: ['hello' remove: 'h'] raise: Error
  682. !
  683. testAsArray
  684. self assert: 'hello' asArray = #('h' 'e' 'l' 'l' 'o').
  685. !
  686. testAt
  687. self assert: ('hello' at: 1) = 'h'.
  688. self assert: ('hello' at: 5) = 'o'.
  689. self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
  690. !
  691. testAtPut
  692. "String instances are read-only"
  693. self should: ['hello' at: 1 put: 'a'] raise: Error
  694. !
  695. testCopyWithoutAll
  696. self
  697. assert: 'hello world'
  698. equals: ('*hello* *world*' copyWithoutAll: '*')
  699. !
  700. testEquality
  701. self assert: 'hello' = 'hello'.
  702. self deny: 'hello' = 'world'.
  703. self assert: 'hello' = 'hello' yourself.
  704. self assert: 'hello' yourself = 'hello'.
  705. "test JS falsy value"
  706. self deny: '' = 0
  707. !
  708. testIdentity
  709. self assert: 'hello' == 'hello'.
  710. self deny: 'hello' == 'world'.
  711. self assert: 'hello' == 'hello' yourself.
  712. self assert: 'hello' yourself == 'hello'.
  713. "test JS falsy value"
  714. self deny: '' == 0
  715. !
  716. testIncludesSubString
  717. self assert: ('amber' includesSubString: 'ber').
  718. self deny: ('amber' includesSubString: 'zork').
  719. !
  720. testJoin
  721. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  722. !
  723. testSize
  724. self assert: 'smalltalk' size equals: 9.
  725. self assert: '' size equals: 0
  726. !
  727. testStreamContents
  728. self
  729. assert: 'hello world'
  730. equals: (String streamContents: [:aStream| aStream
  731. nextPutAll: 'hello'; space;
  732. nextPutAll: 'world'])
  733. ! !
  734. TestCase subclass: #SymbolTest
  735. instanceVariableNames: ''
  736. package: 'Kernel-Tests'!
  737. !SymbolTest methodsFor: 'tests'!
  738. testAsString
  739. self assert: #hello asString equals: 'hello'
  740. !
  741. testAsSymbol
  742. self assert: #hello == #hello asSymbol
  743. !
  744. testAt
  745. self assert: (#hello at: 1) = 'h'.
  746. self assert: (#hello at: 5) = 'o'.
  747. self assert: (#hello at: 6 ifAbsent: [nil]) = nil
  748. !
  749. testAtPut
  750. "Symbol instances are read-only"
  751. self should: ['hello' at: 1 put: 'a'] raise: Error
  752. !
  753. testComparing
  754. self assert: #ab > #aa.
  755. self deny: #ab > #ba.
  756. self assert: #ab < #ba.
  757. self deny: #bb < #ba.
  758. self assert: #ab >= #aa.
  759. self deny: #ab >= #ba.
  760. self assert: #ab <= #ba.
  761. self deny: #bb <= #ba
  762. !
  763. testCopying
  764. self assert: #hello copy == #hello.
  765. self assert: #hello deepCopy == #hello
  766. !
  767. testEquality
  768. self assert: #hello = #hello.
  769. self deny: #hello = #world.
  770. self assert: #hello = #hello yourself.
  771. self assert: #hello yourself = #hello.
  772. self deny: #hello = 'hello'.
  773. self deny: 'hello' = #hello.
  774. !
  775. testIdentity
  776. self assert: #hello == #hello.
  777. self deny: #hello == #world.
  778. self assert: #hello = #hello yourself.
  779. self assert: #hello yourself = #hello asString asSymbol
  780. !
  781. testIsSymbolIsString
  782. self assert: #hello isSymbol.
  783. self deny: 'hello' isSymbol.
  784. self deny: #hello isString.
  785. self assert: 'hello' isString
  786. !
  787. testSize
  788. self assert: #a size equals: 1.
  789. self assert: #aaaaa size equals: 5
  790. ! !
  791. TestCase subclass: #UndefinedTest
  792. instanceVariableNames: ''
  793. package: 'Kernel-Tests'!
  794. !UndefinedTest methodsFor: 'tests'!
  795. testCopying
  796. self assert: nil copy equals: nil
  797. !
  798. testDeepCopy
  799. self assert: nil deepCopy = nil
  800. !
  801. testIfNil
  802. self assert: (nil ifNil: [true]) equals: true.
  803. self deny: (nil ifNotNil: [true]) = true.
  804. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  805. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  806. !
  807. testIsNil
  808. self assert: nil isNil.
  809. self deny: nil notNil.
  810. ! !