File: GH117Spec.hs

package info (click to toggle)
haskell-constraints 0.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: haskell: 1,432; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module GH117Spec (main, spec) where

import Test.Hspec

#if __GLASGOW_HASKELL__ >= 902
import Data.Constraint
import Data.Constraint.Char
import Data.Proxy
import GHC.TypeLits

spec :: Spec
spec =
  describe "GH #117" $ do
    it "should evaluate `charToNat @'a'` to 97" $
      case charToNat @'a' of
        Sub (Dict :: Dict (KnownNat n)) ->
          natVal (Proxy @n) `shouldBe` 97
    it "should evaluate `natToChar @97` to 'a'" $
      case natToChar @97 of
        Sub (Dict :: Dict (KnownChar c)) ->
          charVal (Proxy @c) `shouldBe` 'a'
#else
spec :: Spec
spec = return ()
#endif

main :: IO ()
main = hspec spec