Axxord-Tests.st 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Smalltalk createPackage: 'Axxord-Tests'!
  2. TestCase subclass: #PlainConsumeTransformTest
  3. instanceVariableNames: ''
  4. package: 'Axxord-Tests'!
  5. !PlainConsumeTransformTest methodsFor: 'tests'!
  6. testModelTransformSentToAxon
  7. | model result axon |
  8. result := nil.
  9. model := #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
  10. axon := TestSpyAxon new.
  11. axon registerIn: model.
  12. model axes: #(foo 2) transform: [:r | #new].
  13. self assert: axon changedAspectLog equals: #((foo 2))
  14. !
  15. testNontrivialModelGetsAppropriateValueForTransform
  16. | model result |
  17. result := nil.
  18. model := #{ 'foo' -> #('bar' #(1 #(2 5)) 'baz'). 'moo' -> 'zoo' }.
  19. model axes: #(foo 2) transform: [:r | result := r].
  20. self assert: #(1 #(2 5)) equals: result
  21. !
  22. testNontrivialModelReturnsAppropriateValue
  23. | model result |
  24. result := nil.
  25. model := #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
  26. model axes: #(foo 2) consume: [:r | result := r].
  27. self assert: #(1 #(2 3)) equals: result
  28. !
  29. testNontrivialModelTransformsAppropriateValue
  30. | model result |
  31. result := nil.
  32. model := #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
  33. model axes: #(foo 2) transform: [:r | #new].
  34. model axes: #(foo 2) consume: [:r | result := r].
  35. self assert: #new equals: result.
  36. model axes: #() consume: [:r | result := r].
  37. self assert: #{ 'foo' -> #('bar' #new 'baz'). 'moo' -> 'zoo' } equals: result
  38. !
  39. testRootModelCannotTransform
  40. | model result |
  41. result := nil.
  42. model := #(1 #(2 3)).
  43. self should: [ model axes: #() transform: [:r | #{'foo'->#(4 5 6)}] ] raise: Error
  44. !
  45. testRootModelReturnsDirectRoot
  46. | model result |
  47. result := nil.
  48. model := #(1 #(2 4)).
  49. model axes: #() consume: [:r | r at: 2 put: nil].
  50. model axes: #() consume: [:r | result := r].
  51. self assert: #(1 nil) equals: result
  52. !
  53. testRootModelReturnsRoot
  54. | model result |
  55. result := nil.
  56. model := #(1 #(2 3)).
  57. model axes: #() consume: [:r | result := r].
  58. self assert: #(1 #(2 3)) equals: result
  59. !
  60. testRootTransformBlockIsNotRun
  61. | model result |
  62. result := nil.
  63. model := #(2 #(1 0)).
  64. [model axes: #() transform: [:r | result := r]] on: Error do: [].
  65. self assert: result isNil
  66. ! !
  67. DumbAxon subclass: #TestSpyAxon
  68. instanceVariableNames: 'changedAspectLog'
  69. package: 'Axxord-Tests'!
  70. !TestSpyAxon commentStamp!
  71. I am an axon that logs changed aspects. I am useful in tests.!
  72. !TestSpyAxon methodsFor: 'accessing'!
  73. changedAspectLog
  74. ^ changedAspectLog
  75. !
  76. changedAspectLog: anObject
  77. changedAspectLog := anObject
  78. ! !
  79. !TestSpyAxon methodsFor: 'action'!
  80. changed: anAspect
  81. changedAspectLog add: anAspect
  82. ! !
  83. !TestSpyAxon methodsFor: 'initialization'!
  84. initialize
  85. super initialize.
  86. changedAspectLog := #()
  87. ! !