-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathSpec.hs
More file actions
71 lines (61 loc) · 2.3 KB
/
Spec.hs
File metadata and controls
71 lines (61 loc) · 2.3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-cse-iterations=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-pir=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-uplc=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-optimize #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-simplifier-beta #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-simplifier-evaluate-builtins #-}
module Bounded.Spec where
import PlutusTx
import PlutusTx.Test (goldenPirReadable)
import Test.Tasty.Extras
import PlutusTx.Bounded
import PlutusTx.Prelude
import PlutusTx.Plugin (plc)
import Data.Proxy (Proxy (..))
data SomeVeryLargeEnum
= E1
| E2
| E3
| E4
| E5
| E6
| E7
| E8
| E9
| E10
deriveBounded ''SomeVeryLargeEnum
data SingleConstructor a = SingleConstructor Bool a ()
deriveBounded ''SingleConstructor
newtype PhantomADT e = PhantomADT ()
deriveBounded ''PhantomADT
minAndMax :: Bounded a => (a, a)
minAndMax = (minBound,maxBound)
compiledSomeVeryLargeEnum :: CompiledCode (SomeVeryLargeEnum, SomeVeryLargeEnum)
compiledSomeVeryLargeEnum = plc (Proxy @"compiledSomeVeryLargeEnum") minAndMax
compiledSingleConstructor :: CompiledCode (SingleConstructor Ordering, SingleConstructor Ordering)
compiledSingleConstructor = plc (Proxy @"compiledSingleConstructor") minAndMax
{- here cannot use Ordering or Either as the phantom type because of
pir compile error (unrelated to Bounded):
GHC Core to PLC plugin: Error: Error from the PIR compiler:
Error during compilation: Type bindings cannot appear in recursive let, use datatypebind instead
See https://github.com/IntersectMBO/plutus/issues/7498
-}
compiledPhantomADT :: CompiledCode (PhantomADT Bool, PhantomADT Bool)
compiledPhantomADT = plc (Proxy @"compiledPhantomADT") minAndMax
tests :: TestNested
tests =
testNested
"Bounded"
[ testNestedGhc
[ goldenPirReadable "SomeVeryLargeEnum" compiledSomeVeryLargeEnum
, goldenPirReadable "SingleConstructor" compiledSingleConstructor
, goldenPirReadable "PhantomADT" compiledPhantomADT
]
]