module SaturnSpec where

import qualified Saturn.Unstable.Parse as Parse
import qualified Saturn.Unstable.Render as Render
import qualified Saturn.Unstable.Type.ScheduleSpec as ScheduleSpec
import qualified Test.Hspec as Hspec
import qualified Test.QuickCheck as QuickCheck

spec :: Hspec.Spec
spec :: Spec
spec = String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
Hspec.describe String
"Saturn" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
Hspec.describe String
"round trips" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
Hspec.it String
"through string"
      (Property -> Spec)
-> ((Schedule -> Expectation) -> Property)
-> (Schedule -> Expectation)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen Schedule
-> (Schedule -> [Schedule])
-> (Schedule -> Expectation)
-> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> [a]) -> (a -> prop) -> Property
QuickCheck.forAllShrink Gen Schedule
ScheduleSpec.arbitrary Schedule -> [Schedule]
ScheduleSpec.shrink
      ((Schedule -> Expectation) -> Spec)
-> (Schedule -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$ \Schedule
schedule ->
        String -> Either ParseError Schedule
Parse.fromString (Schedule -> String
Render.toString Schedule
schedule) Either ParseError Schedule
-> Either ParseError Schedule -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`Hspec.shouldBe` Schedule -> Either ParseError Schedule
forall a b. b -> Either a b
Right Schedule
schedule

    String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
Hspec.it String
"through strict text"
      (Property -> Spec)
-> ((Schedule -> Expectation) -> Property)
-> (Schedule -> Expectation)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen Schedule
-> (Schedule -> [Schedule])
-> (Schedule -> Expectation)
-> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> [a]) -> (a -> prop) -> Property
QuickCheck.forAllShrink Gen Schedule
ScheduleSpec.arbitrary Schedule -> [Schedule]
ScheduleSpec.shrink
      ((Schedule -> Expectation) -> Spec)
-> (Schedule -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$ \Schedule
schedule ->
        Text -> Either ParseError Schedule
Parse.fromText (Schedule -> Text
Render.toText Schedule
schedule) Either ParseError Schedule
-> Either ParseError Schedule -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`Hspec.shouldBe` Schedule -> Either ParseError Schedule
forall a b. b -> Either a b
Right Schedule
schedule

    String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
Hspec.it String
"through lazy text"
      (Property -> Spec)
-> ((Schedule -> Expectation) -> Property)
-> (Schedule -> Expectation)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen Schedule
-> (Schedule -> [Schedule])
-> (Schedule -> Expectation)
-> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> [a]) -> (a -> prop) -> Property
QuickCheck.forAllShrink Gen Schedule
ScheduleSpec.arbitrary Schedule -> [Schedule]
ScheduleSpec.shrink
      ((Schedule -> Expectation) -> Spec)
-> (Schedule -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$ \Schedule
schedule ->
        Text -> Either ParseError Schedule
Parse.fromLazyText (Schedule -> Text
Render.toLazyText Schedule
schedule) Either ParseError Schedule
-> Either ParseError Schedule -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`Hspec.shouldBe` Schedule -> Either ParseError Schedule
forall a b. b -> Either a b
Right Schedule
schedule