@@ -14,7 +14,6 @@ module Text.Markdown.SlamDown.Syntax.FormField
1414
1515import Prelude
1616
17- import Data.Array as A
1817import Data.Eq (class Eq1 , eq1 )
1918import Data.Functor.Compose (Compose (..))
2019import Data.Identity (Identity (..))
@@ -23,10 +22,6 @@ import Data.Maybe as M
2322import Data.Newtype (unwrap )
2423import Data.Ord (class Ord1 , compare1 )
2524import Data.Traversable as TR
26- import Data.Tuple (uncurry )
27- import Partial.Unsafe (unsafePartial )
28- import Test.StrongCheck.Arbitrary as SCA
29- import Test.StrongCheck.Gen as Gen
3025import Text.Markdown.SlamDown.Syntax.TextBox (TextBox (..), TimePrecision (..), transTextBox , traverseTextBox ) as TB
3126import Text.Markdown.SlamDown.Syntax.Value (class Value , renderValue , stringValue ) as Value
3227
@@ -123,15 +118,6 @@ instance functorArbIdentity ∷ Functor ArbIdentity where
123118 map f (ArbIdentity x) =
124119 ArbIdentity $ f x
125120
126- instance arbitraryArbIdentity ∷ (SCA.Arbitrary a ) ⇒ SCA.Arbitrary (ArbIdentity a ) where
127- arbitrary =
128- ArbIdentity <$>
129- SCA .arbitrary
130-
131- instance coarbitraryArbIdentity ∷ (SCA.Coarbitrary a ) ⇒ SCA.Coarbitrary (ArbIdentity a ) where
132- coarbitrary (ArbIdentity x) =
133- SCA .coarbitrary x
134-
135121newtype ArbCompose f g a = ArbCompose (f (g a ))
136122
137123getArbCompose
@@ -146,141 +132,6 @@ instance functorArbCompose ∷ (Functor f, Functor g) ⇒ Functor (ArbCompose f
146132 ArbCompose $
147133 map (map f) x
148134
149- instance arbitraryArbCompose ∷ (SCA.Arbitrary (f (g a ))) ⇒ SCA.Arbitrary (ArbCompose f g a ) where
150- arbitrary =
151- ArbCompose <$>
152- SCA .arbitrary
153-
154- instance coarbitraryArbCompose ∷ (SCA.Coarbitrary (f (g a ))) ⇒ SCA.Coarbitrary (ArbCompose f g a ) where
155- coarbitrary (ArbCompose t) =
156- SCA .coarbitrary t
157-
158- unsafeElements ∷ ∀ a . L.List a → Gen.Gen a
159- unsafeElements =
160- Gen .elements
161- <$> (unsafePartial M .fromJust <<< L .head)
162- <*> identity
163-
164- instance arbitraryFormField ∷ (SCA.Arbitrary a , Eq a ) ⇒ SCA.Arbitrary (FormFieldP Expr a ) where
165- arbitrary = do
166- k ← Gen .chooseInt 0 3
167- case k of
168- 0 → TextBox <<< TB .transTextBox getArbCompose <$> SCA .arbitrary
169- 1 → do
170- xse ← genExpr $ distinctListOf1 SCA .arbitrary
171- case xse of
172- Literal xs → do
173- x ← Literal <$> unsafeElements xs
174- pure $ RadioButtons x xse
175- Unevaluated e → do
176- x ← Unevaluated <$> genUnevaluated
177- pure $ RadioButtons x xse
178- 2 → do
179- xse ← genExpr $ distinctListOf1 SCA .arbitrary
180- case xse of
181- Literal xs → do
182- ys ← Literal <$> distinctListOf (unsafeElements xs)
183- pure $ CheckBoxes ys xse
184- Unevaluated e → do
185- yse ← Unevaluated <$> genUnevaluated
186- pure $ CheckBoxes yse xse
187- _ → do
188- xse ← genExpr $ distinctListOf1 SCA .arbitrary
189- case xse of
190- Literal xs → do
191- mx ← genMaybe $ Literal <$> unsafeElements xs
192- pure $ DropDown mx xse
193- Unevaluated e → do
194- mx ← genMaybe $ Unevaluated <$> genUnevaluated
195- pure $ DropDown mx xse
196-
197- instance arbitraryFormFieldIdentity ∷ (SCA.Arbitrary a , Eq a ) ⇒ SCA.Arbitrary (FormFieldP Identity a ) where
198- arbitrary = do
199- k ← Gen .chooseInt 0 3
200- case k of
201- 0 → TextBox <<< TB .transTextBox (\(ArbCompose x) → Compose $ map getArbIdentity x) <$> SCA .arbitrary
202- 1 → do
203- xs ← distinctListOf1 $ getArbIdentity <$> SCA .arbitrary
204- x ← unsafeElements xs
205- pure $ RadioButtons x $ TR .sequence xs
206- 2 → do
207- xs ← map TR .sequence <<< distinctListOf1 $ getArbIdentity <$> SCA .arbitrary
208- ys ← TR .traverse (distinctListOf <<< unsafeElements) xs
209- pure $ CheckBoxes ys xs
210- _ → do
211- xs ← distinctListOf1 $ getArbIdentity <$> SCA .arbitrary
212- mx ← genMaybe $ unsafeElements xs
213- pure $ DropDown mx $ TR .sequence xs
214-
215-
216- genMaybe
217- ∷ ∀ a
218- . Gen.Gen a
219- → Gen.Gen (M.Maybe a )
220- genMaybe gen = do
221- b ← SCA .arbitrary
222- if b then M.Just <$> gen else pure M.Nothing
223-
224- instance coarbitraryFormFieldIdentity ∷ (SCA.Coarbitrary a ) ⇒ SCA.Coarbitrary (FormFieldP Identity a ) where
225- coarbitrary field =
226- case field of
227- TextBox tb → SCA .coarbitrary $ TB .transTextBox (unwrap >>> map (unwrap >>> ArbIdentity ) >>> ArbCompose ) tb
228- RadioButtons x xs → \gen → do
229- _← SCA .coarbitrary (ArbIdentity $ unwrap x) gen
230- SCA .coarbitrary (ArbIdentity $ unwrap xs) gen
231- CheckBoxes sel xs → \gen → do
232- _← SCA .coarbitrary (ArbIdentity $ unwrap sel) gen
233- SCA .coarbitrary (ArbIdentity $ unwrap xs) gen
234- DropDown mx xs → \gen → do
235- _← SCA .coarbitrary (ArbIdentity <<< unwrap <$> mx) gen
236- SCA .coarbitrary (ArbIdentity $ unwrap xs) gen
237-
238- listOf1
239- ∷ ∀ f a
240- . Monad f
241- ⇒ Gen.GenT f a
242- → Gen.GenT f (L.List a )
243- listOf1 =
244- map (L .fromFoldable <<< uncurry A .cons)
245- <<< Gen .arrayOf1
246-
247- listOf
248- ∷ ∀ f a
249- . (Monad f )
250- ⇒ Gen.GenT f a
251- → Gen.GenT f (L.List a )
252- listOf =
253- map L .fromFoldable
254- <<< Gen .arrayOf
255-
256- listOfLength
257- ∷ ∀ f a
258- . (Monad f )
259- ⇒ Int
260- → Gen.GenT f a
261- → Gen.GenT f (L.List a )
262- listOfLength i =
263- map L .fromFoldable
264- <<< Gen .vectorOf i
265-
266- distinctListOf1
267- ∷ ∀ f a
268- . Monad f
269- ⇒ Eq a
270- ⇒ Gen.GenT f a
271- → Gen.GenT f (L.List a )
272- distinctListOf1 =
273- map (map L .nub) listOf1
274-
275- distinctListOf
276- ∷ ∀ f a
277- . Monad f
278- ⇒ Eq a
279- ⇒ Gen.GenT f a
280- → Gen.GenT f (L.List a )
281- distinctListOf =
282- map (map L .nub) listOf
283-
284135data Expr a
285136 = Literal a
286137 | Unevaluated String
@@ -310,16 +161,3 @@ derive instance eq1 ∷ Eq1 Expr
310161
311162derive instance ord1Expr ∷ Ord1 Expr
312163derive instance ordExpr ∷ Ord a ⇒ Ord (Expr a )
313-
314- genExpr ∷ ∀ a . Gen.Gen a → Gen.Gen (Expr a )
315- genExpr g = do
316- b ← SCA .arbitrary
317- if b then Literal <$> g else Unevaluated <$> genUnevaluated
318-
319- genUnevaluated ∷ Gen.Gen String
320- genUnevaluated = do
321- x ← SCA .arbitrary
322- pure $ " " <> x <> " "
323-
324- instance arbitraryExpr ∷ (SCA.Arbitrary a ) ⇒ SCA.Arbitrary (Expr a ) where
325- arbitrary = genExpr SCA .arbitrary
0 commit comments