graphql-engine/server/src-test/Data/TimeSpec.hs
Robert c1bdc99334 Fix comment formatting to allow parsing in haddock-mode
This is just a one-off fix, based on running ormolu across
the code base, which uses GHC's parser in haddock mode.

### Description

Fixes several instances of illegal haddock comments.

### Related Issues

#1679

### Steps to test and verify

Run ormolu over the codebase. Prior to this change, it complains that it
can't parse certain files due to malformed Haddock comments, after it
doesn't (there are still some other errors).

### Limitations, known bugs & workarounds

This doesn't ensure that we don't introduce similar issues in the future;
that'll be dealt with once we implement #1679.

#### Breaking changes

- [x] No Breaking changes, only touches code comments

https://github.com/hasura/graphql-engine-mono/pull/2010

GitOrigin-RevId: 7fbab0325ce13a16a04ff98d351f1af768e25d7c
2021-08-16 22:20:25 +00:00

45 lines
1.3 KiB
Haskell

-- | Time-related properties we care about.
module Data.TimeSpec (spec) where
import Data.Aeson
import Data.Time
import Data.Time.Clock.Units
import Prelude
import Test.Hspec
spec :: Spec
spec = do
timeUnitsSpec
diffTimeSpec
timeUnitsSpec :: Spec
timeUnitsSpec =
describe "time units" $ do
it "converts correctly" $ do
seconds 123 `shouldBe` 123
milliseconds 123 `shouldBe` 0.123
microseconds 123 `shouldBe` 0.000123
nanoseconds 123 `shouldBe` 0.000000123
it "has a correct Read instance" $ do
seconds (read "123") `shouldBe` 123
milliseconds (read "123") `shouldBe` 0.123
microseconds (read "123") `shouldBe` 0.000123
nanoseconds (read "123") `shouldBe` 0.000000123
it "JSON serializes as proper units" $ do
toJSON (1 :: Seconds) `shouldBe` Number 1
decode "1.0" `shouldBe` Just (1 :: Seconds)
it "converts with convertDuration" $ do
convertDuration (2 :: Minutes) `shouldBe` (120 :: NominalDiffTime)
convertDuration (60 :: Seconds) `shouldBe` (1 :: Minutes)
diffTimeSpec :: Spec
diffTimeSpec =
describe "DiffTime" $ do
it "JSON serializes as seconds" $ do
-- although we would prefer to use Seconds instead...
toJSON (1 :: DiffTime) `shouldBe` Number 1
decode "1.0" `shouldBe` Just (1 :: DiffTime)