1
0

Kernel-Tests.st 19 KB

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