Skip to content

Commit 3c66944

Browse files
Render UTs
1 parent 8faa1d8 commit 3c66944

File tree

6 files changed

+123
-4
lines changed

6 files changed

+123
-4
lines changed

TODO.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ DONE-text box option that auto goes into edit text box
294294

295295

296296
::NEWEST TODO::
297-
-render testing utilities
297+
DONE-render testing utilities
298298
-layers improvements
299299
-shift select in layers please ;__;
300300
-selecting multiple items and hitting new folder should put those items in folder maybe

src/Potato/Flow/Controller/OwlLayers.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ layerEntriesToPrettyText lentries = foldr foldrfn "" lentries where
109109
then if _layerEntry_isCollapsed
110110
then ">"
111111
else "v"
112-
else " "
112+
else ""
113113
hideText = case _layerEntry_hideState of
114114
LHS_True -> ""
115115
LHS_False -> " "

src/Potato/Flow/Render.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Potato.Flow.Render (
1818
, printRenderedCanvasRegion
1919
, potatoRenderWithOwlTree
2020
, potatoRenderPFState
21+
, renderedCanvasRegion_getAt
2122
, renderedCanvasToText
2223
, renderedCanvasRegionToText
2324

@@ -228,6 +229,9 @@ renderedCanvasToText :: RenderedCanvasRegion -> Text
228229
renderedCanvasToText rcr = renderedCanvasRegionToText (_renderedCanvasRegion_box rcr) rcr
229230

230231

232+
renderedCanvasRegion_getAt :: RenderedCanvasRegion -> V2 Int -> MWidePChar
233+
renderedCanvasRegion_getAt rcr = (V.!) (_renderedCanvasRegion_contents rcr) . toIndex (_renderedCanvasRegion_box rcr)
234+
231235
-- TODO this does not handle wide chars at all fack
232236
-- | assumes region LBox is strictly contained in _renderedCanvasRegion_box
233237
renderedCanvasRegionToText :: LBox -> RenderedCanvasRegion -> Text

test/Potato/Flow/Controller/Manipulator/LayersSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ drag_folder_depth_test = hSpecGoatTesterWithOwlPFState emptyOwlPFState $ do
444444
-- 1<box>
445445

446446

447+
447448
spec :: Spec
448449
spec = do
449450
describe "Layers" $ do

test/Potato/Flow/GoatTester.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,26 @@ verifySelectionIsAndOnlyIs desc f = verifyState desc f' where
370370
then Just $ "failed, expected 1 selected 🦉, got " <> show nselection
371371
else (\m -> "failed with message: " <> m <> "\ngot:\n" <> potatoShow (_superOwl_elt sowl)) <$> f sowl
372372

373+
374+
375+
verifyRenderNonEmptyCount :: (Monad m) => Int -> GoatTesterT m ()
376+
verifyRenderNonEmptyCount expected = verifyState "verifyRenderNonEmptyCount" f where
377+
f gs = if n == expected
378+
then Nothing
379+
else Just $ "got " <> show n <> " non-empty chars, expected " <> show expected
380+
where n = renderedCanvasRegion_nonEmptyCount (_goatState_renderedCanvas gs)
381+
382+
verifyCharRenderedAt :: (Monad m) => V2 Int -> Maybe Char -> GoatTesterT m ()
383+
verifyCharRenderedAt pos mchar = verifyState "verifyCharRenderedAt" f where
384+
f gs = if mchar == mchar'
385+
then Nothing
386+
else Just $ "expected: " <> show mchar <> "\ngot: " <> show mchar'
387+
where
388+
mchar' = case renderedCanvasRegion_getAt (_goatState_renderedCanvas gs) pos of
389+
(-1, _) -> Nothing
390+
(_, c) -> Just c
391+
392+
373393
-- otheruseful stuff
374394

375395
-- export as part of this module becaues it's super useful
@@ -382,3 +402,16 @@ toMaybe True x = Just x
382402
alwaysFail :: (Monad m) => Text -> GoatTesterT m ()
383403
alwaysFail msg = GoatTesterT $ do
384404
unGoatTesterT $ putRecord "this test always fails" (Just msg)
405+
406+
407+
debugFailWithLayers :: (Monad m) => GoatTesterT m ()
408+
debugFailWithLayers = do
409+
gs <- getGoatState
410+
putRecord "debugFailWithLayers" (Just $ potatoShow $ _goatState_layersState gs)
411+
412+
debugFailWithRenderedCanvas :: (Monad m) => GoatTesterT m ()
413+
debugFailWithRenderedCanvas = do
414+
gs <- getGoatState
415+
let
416+
canvas = _goatState_renderedCanvas gs
417+
putRecord "debugFailWithRenderedCanvas" (traceShow (renderedCanvas_box canvas) $ Just $ renderedCanvasToText canvas)

test/Potato/Flow/RenderSpec.hs

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import qualified Data.Text as T
1414

1515
import Potato.Flow
1616
import Potato.Flow.TestStates
17+
import Potato.Flow.GoatTester
18+
import Potato.Flow.Controller.Manipulator.TestHelpers
19+
1720

1821
testCanvas :: Int -> Int -> Int -> Int -> RenderedCanvasRegion
1922
testCanvas x y w h = emptyRenderedCanvasRegion (LBox (V2 x y) (V2 w h))
@@ -33,8 +36,10 @@ potatoRenderWithSEltAndEmptyOwlTreeForTest selts rcr = potatoRenderWithOwlTree e
3336
testsstyle :: SuperStyle
3437
testsstyle = def { _superStyle_fill = FillStyle_Simple '@' }
3538

36-
spec :: Spec
37-
spec = do
39+
40+
41+
spec1 :: Spec
42+
spec1 = do
3843
describe "Canvas" $ do
3944
it "potato renders blank text" $ do
4045
let
@@ -164,3 +169,79 @@ spec = do
164169
canvas1 = _renderContext_renderedCanvasRegion rendercontext1
165170
-- TODO test something
166171
canvas1 `shouldBe` canvas1
172+
173+
174+
emptyOwlStateWithSize :: (Int, Int) -> OwlPFState
175+
emptyOwlStateWithSize (x, y) = OwlPFState emptyOwlTree (SCanvas (LBox 0 (V2 x y)))
176+
177+
render_basic :: Spec
178+
render_basic = hSpecGoatTesterWithOwlPFState (emptyOwlStateWithSize (20,20)) $ do
179+
180+
setMarker "verify empty initial state"
181+
verifyRenderNonEmptyCount 0
182+
183+
setMarker "draw a box"
184+
drawCanvasBox (0, 0, 2, 2)
185+
verifyRenderNonEmptyCount 4
186+
187+
setMarker "hide the box"
188+
layerMouseDownUpRel LMO_Hide 0 0
189+
verifyRenderNonEmptyCount 0
190+
191+
setMarker "unhide the box"
192+
layerMouseDownUpRel LMO_Hide 0 0
193+
verifyRenderNonEmptyCount 4
194+
195+
setMarker "delete the box"
196+
pressBackspace
197+
verifyRenderNonEmptyCount 0
198+
199+
200+
render_hide_basic :: Spec
201+
render_hide_basic = hSpecGoatTesterWithOwlPFState (emptyOwlStateWithSize (20,20)) $ do
202+
203+
setMarker "verify empty initial state"
204+
verifyRenderNonEmptyCount 0
205+
206+
setMarker "make a folder"
207+
addFolder "hide me"
208+
209+
setMarker "draw a box"
210+
drawCanvasBox (0, 0, 2, 2)
211+
verifyRenderNonEmptyCount 4
212+
213+
setMarker "hide the folder"
214+
layerMouseDownUpRel LMO_Hide 0 0
215+
verifyRenderNonEmptyCount 0
216+
217+
setMarker "deselect evertyhing"
218+
pressEscape
219+
verifySelectionCount 0
220+
221+
setMarker "drag the box out of the folder"
222+
layerMouseDownUpRel LMO_Normal 1 1
223+
verifySelectionCount 1
224+
layerMouseDownRel LMO_Normal 1 1
225+
layerMouseDownUpRel (LMO_DropInFolder 0) 2 0
226+
verifyRenderNonEmptyCount 4
227+
228+
setMarker "drag the box into the folder"
229+
layerMouseDownRel LMO_Normal 1 0
230+
layerMouseDownUpRel (LMO_DropInFolder 0) 1 1
231+
verifyRenderNonEmptyCount 0
232+
233+
234+
235+
236+
spec2 :: Spec
237+
spec2 = do
238+
describe "Render" $ do
239+
describe "render_basic" $ render_basic
240+
describe "render_hide_basic" $ render_hide_basic
241+
242+
243+
244+
spec :: Spec
245+
spec = do
246+
spec1
247+
spec2

0 commit comments

Comments
 (0)