Kernel-Tests.st 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. testPrintString
  618. | set |
  619. set := Set new.
  620. self assert: 'a Set ()' equals: ( set printString ).
  621. set add: 1; add: 3.
  622. self assert: 'a Set (1 3)' equals: ( set printString ).
  623. set add: 'foo'.
  624. self assert: 'a Set (1 3 ''foo'')' equals: ( set printString ).
  625. set remove: 1; remove: 3.
  626. self assert: 'a Set (''foo'')' equals: ( set printString ).
  627. set add: 3.
  628. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  629. set add: 3.
  630. self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
  631. !
  632. testSize
  633. self assert: Set new size equals: 0.
  634. self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
  635. self assert: (Set withAll: #(1 1 1 1)) size equals: 1
  636. !
  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. TestCase subclass: #StringTest
  649. instanceVariableNames: ''
  650. package: 'Kernel-Tests'!
  651. !StringTest methodsFor: 'tests'!
  652. testAddRemove
  653. self should: ['hello' add: 'a'] raise: Error.
  654. self should: ['hello' remove: 'h'] raise: Error
  655. !
  656. testAsArray
  657. self assert: 'hello' asArray = #('h' 'e' 'l' 'l' 'o').
  658. !
  659. testAt
  660. self assert: ('hello' at: 1) = 'h'.
  661. self assert: ('hello' at: 5) = 'o'.
  662. self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
  663. !
  664. testAtPut
  665. "String instances are read-only"
  666. self should: ['hello' at: 1 put: 'a'] raise: Error
  667. !
  668. testCopyWithoutAll
  669. self
  670. assert: 'hello world'
  671. equals: ('*hello* *world*' copyWithoutAll: '*')
  672. !
  673. testEquality
  674. self assert: 'hello' = 'hello'.
  675. self deny: 'hello' = 'world'.
  676. self assert: 'hello' = 'hello' yourself.
  677. self assert: 'hello' yourself = 'hello'.
  678. "test JS falsy value"
  679. self deny: '' = 0
  680. !
  681. testIdentity
  682. self assert: 'hello' == 'hello'.
  683. self deny: 'hello' == 'world'.
  684. self assert: 'hello' == 'hello' yourself.
  685. self assert: 'hello' yourself == 'hello'.
  686. "test JS falsy value"
  687. self deny: '' == 0
  688. !
  689. testIncludesSubString
  690. self assert: ('amber' includesSubString: 'ber').
  691. self deny: ('amber' includesSubString: 'zork').
  692. !
  693. testJoin
  694. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  695. !
  696. testSize
  697. self assert: 'smalltalk' size equals: 9.
  698. self assert: '' size equals: 0
  699. !
  700. testStreamContents
  701. self
  702. assert: 'hello world'
  703. equals: (String streamContents: [:aStream| aStream
  704. nextPutAll: 'hello'; space;
  705. nextPutAll: 'world'])
  706. ! !
  707. TestCase subclass: #SymbolTest
  708. instanceVariableNames: ''
  709. package: 'Kernel-Tests'!
  710. !SymbolTest methodsFor: 'tests'!
  711. testAsString
  712. self assert: #hello asString equals: 'hello'
  713. !
  714. testAsSymbol
  715. self assert: #hello == #hello asSymbol
  716. !
  717. testAt
  718. self assert: (#hello at: 1) = 'h'.
  719. self assert: (#hello at: 5) = 'o'.
  720. self assert: (#hello at: 6 ifAbsent: [nil]) = nil
  721. !
  722. testAtPut
  723. "Symbol instances are read-only"
  724. self should: ['hello' at: 1 put: 'a'] raise: Error
  725. !
  726. testComparing
  727. self assert: #ab > #aa.
  728. self deny: #ab > #ba.
  729. self assert: #ab < #ba.
  730. self deny: #bb < #ba.
  731. self assert: #ab >= #aa.
  732. self deny: #ab >= #ba.
  733. self assert: #ab <= #ba.
  734. self deny: #bb <= #ba
  735. !
  736. testCopying
  737. self assert: #hello copy == #hello.
  738. self assert: #hello deepCopy == #hello
  739. !
  740. testEquality
  741. self assert: #hello = #hello.
  742. self deny: #hello = #world.
  743. self assert: #hello = #hello yourself.
  744. self assert: #hello yourself = #hello.
  745. self deny: #hello = 'hello'.
  746. self deny: 'hello' = #hello.
  747. !
  748. testIdentity
  749. self assert: #hello == #hello.
  750. self deny: #hello == #world.
  751. self assert: #hello = #hello yourself.
  752. self assert: #hello yourself = #hello asString asSymbol
  753. !
  754. testIsSymbolIsString
  755. self assert: #hello isSymbol.
  756. self deny: 'hello' isSymbol.
  757. self deny: #hello isString.
  758. self assert: 'hello' isString
  759. !
  760. testSize
  761. self assert: #a size equals: 1.
  762. self assert: #aaaaa size equals: 5
  763. ! !
  764. TestCase subclass: #UndefinedTest
  765. instanceVariableNames: ''
  766. package: 'Kernel-Tests'!
  767. !UndefinedTest methodsFor: 'tests'!
  768. testCopying
  769. self assert: nil copy equals: nil
  770. !
  771. testDeepCopy
  772. self assert: nil deepCopy = nil
  773. !
  774. testIfNil
  775. self assert: (nil ifNil: [true]) equals: true.
  776. self deny: (nil ifNotNil: [true]) = true.
  777. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  778. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  779. !
  780. testIsNil
  781. self assert: nil isNil.
  782. self deny: nil notNil.
  783. ! !