Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. -- a component
  2. data FileSystem m = FileSystem {
  3. exists :: Path -> m (Either Text Bool)
  4. , readFile :: Path -> m (Either Text Text)
  5. }
  6.  
  7. -- a constructor for a mock file system
  8. newFileSystemWith :: (FileSystemValues -> FileSystemValues) -> FileSystem
  9. newFileSystemWith f = FileSystem {
  10. exists = \_ -> pure (_exists $ f fileSystemValues)
  11. , readFile = \_ -> pure (_readFile $ f fileSystemValues)
  12. }
  13.  
  14. -- mocked returned values
  15. data FileSystemValues = FileSystemValues {
  16. _exists :: Either Text Bool
  17. , _read :: Either Text Text
  18. }
  19.  
  20. fileSystemValues = FileSystemValues
  21. (Left "todo - exists")
  22. (Left "todo - readFile")
  23.  
  24. -- set mock values
  25. existingFiles v = v { _exists = Right True }
  26. someText t v = v { _read = Right t }
  27.  
  28. -- create a mock and compose functions to set return values
  29. myMock = newFileSystemWith (existingFiles . someText "hello world")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement