Trapped-Tests.st 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. Smalltalk current createPackage: 'Trapped-Tests' properties: #{}!
  2. TestCase subclass: #IsolatorTest
  3. instanceVariableNames: 'rootModel'
  4. package: 'Trapped-Tests'!
  5. !IsolatorTest methodsFor: 'running'!
  6. setUp
  7. rootModel := EavModel new
  8. getBlock: [:x | x root];
  9. putBlock: [:x :y | x root: y].
  10. ! !
  11. !IsolatorTest methodsFor: 'tests'!
  12. testNontrivialModelGetsAppropriateValueForModification
  13. | isolator model result |
  14. result := nil.
  15. isolator := Isolator on: #{ 'foo' -> #('bar' #(1 #(2 5)) 'baz'). 'moo' -> 'zoo' }.
  16. model := EavModel new
  17. getBlock: [ :x | (x root at: 'foo') at: 2 ];
  18. putBlock: [ :x :y | (x root at: 'foo') at: 2 put: y].
  19. isolator model: model modify: [:r|result := r].
  20. self assert: #(1 #(2 5)) equals: result
  21. !
  22. testNontrivialModelModifiesAppropriateValue
  23. | isolator model result |
  24. result := nil.
  25. isolator := Isolator on: #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
  26. model := EavModel new
  27. getBlock: [ :x | (x root at: 'foo') at: 2 ];
  28. putBlock: [ :x :y | (x root at: 'foo') at: 2 put: y].
  29. isolator model: model modify: [:r|#new].
  30. isolator model: model read: [:r|result := r].
  31. self assert: #new equals: result.
  32. isolator model: rootModel read: [:r|result := r].
  33. self assert: #{ 'foo' -> #('bar' #new 'baz'). 'moo' -> 'zoo' } equals: result
  34. !
  35. testNontrivialModelReturnsAppropriateValue
  36. | isolator model result |
  37. result := nil.
  38. isolator := Isolator on: #{ 'foo' -> #('bar' #(1 #(2 3)) 'baz'). 'moo' -> 'zoo' }.
  39. model := EavModel new getBlock: [ :x | (x root at: 'foo') at: 2 ].
  40. isolator model: model read: [:r|result := r].
  41. self assert: #(1 #(2 3)) equals: result
  42. !
  43. testRootModelExaminesThenModifiesRoot
  44. | isolator result |
  45. result := nil.
  46. isolator := Isolator on: #(1 #(2 3)).
  47. isolator model: rootModel modify: [:r|r second].
  48. isolator model: rootModel read: [:r|result := r].
  49. self assert: #(2 3) equals: result
  50. !
  51. testRootModelGetsRootForModification
  52. | isolator result |
  53. result := nil.
  54. isolator := Isolator on: #(2 #(1 0)).
  55. isolator model: rootModel modify: [:r|result := r].
  56. self assert: #(2 #(1 0)) equals: result
  57. !
  58. testRootModelModifiesAndDeeplyIsolatesInPlaceModifiedRoot
  59. | isolator result newValue |
  60. result := nil. newValue := nil.
  61. isolator := Isolator on: #(1 #(2 3)).
  62. isolator model: rootModel modify: [:r|newValue := r. r at: 1 put: 4. r].
  63. newValue at: 2 put: 'bar'.
  64. isolator model: rootModel read: [:r|result := r].
  65. newValue at: 2 put: 'baz'.
  66. self assert: #(4 #(2 3)) equals: result
  67. !
  68. testRootModelModifiesAndDeeplyIsolatesRoot
  69. | isolator result newValue |
  70. result := nil.
  71. isolator := Isolator on: #(1 #(2 3)).
  72. newValue := #{'foo'->#(4 5 6)}.
  73. isolator model: rootModel modify: [:r|newValue].
  74. (newValue at: 'foo') at: 1 put: 'bar'.
  75. isolator model: rootModel read: [:r|result := r].
  76. (newValue at: 'foo') at: 3 put: 'baz'.
  77. self assert: #{'foo'->#(4 5 6)} equals: result
  78. !
  79. testRootModelModifiesAndIsolatesRoot
  80. | isolator result newValue |
  81. result := nil.
  82. isolator := Isolator on: #(1 #(2 3)).
  83. newValue := #{'foo'->#(4 5 6)}.
  84. isolator model: rootModel modify: [:r|newValue].
  85. newValue at: 'foo' put: 'bar'.
  86. isolator model: rootModel read: [:r|result := r].
  87. newValue at: 'foo' put: 'baz'.
  88. self assert: #{'foo'->#(4 5 6)} equals: result
  89. !
  90. testRootModelModifiesRoot
  91. | isolator result |
  92. result := nil.
  93. isolator := Isolator on: #(1 #(2 3)).
  94. isolator model: rootModel modify: [:r|#{'foo'->#(4 5 6)}].
  95. isolator model: rootModel read: [:r|result := r].
  96. self assert: #{'foo'->#(4 5 6)} equals: result
  97. !
  98. testRootModelReturnsDeeplyIsolatedRoot
  99. | isolator result |
  100. result := nil.
  101. isolator := Isolator on: #(1 #(2 3)).
  102. isolator model: rootModel read: [:r|(r at: 2) at: 1 put: 0].
  103. isolator model: rootModel read: [:r|result := r].
  104. self assert: #(1 #(2 3)) equals: result
  105. !
  106. testRootModelReturnsIsolatedRoot
  107. | isolator result |
  108. result := nil.
  109. isolator := Isolator on: #(1 #(2 4)).
  110. isolator model: rootModel read: [:r|r at: 2 put: nil].
  111. isolator model: rootModel read: [:r|result := r].
  112. self assert: #(1 #(2 4)) equals: result
  113. !
  114. testRootModelReturnsRoot
  115. | isolator result |
  116. result := nil.
  117. isolator := Isolator on: #(1 #(2 3)).
  118. isolator model: rootModel read: [:r|result := r].
  119. self assert: #(1 #(2 3)) equals: result
  120. ! !