Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit b5c40a4

Browse files
committed
SD-1651 (second try) (#65)
* update build * fix warning * Support spaces in form field items
1 parent ef6630d commit b5c40a4

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"purescript": "^0.8.2"
4+
"purescript": "^0.8.5"
55
}
66
}

src/Text/Markdown/SlamDown/Eval.purs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ eval fs = everywhereM b i
6262
quoteTextBox = SD.transTextBox (runIdentity >>> SD.Literal >>> M.Just >>> Compose)
6363

6464
f (SD.RadioButtons sel opts) = do
65-
sel' <- evalExpr fs.value sel
66-
opts' <- evalExpr fs.list opts
65+
sel' evalExpr fs.value sel
66+
opts' evalExpr fs.list opts
6767
pure $ SD.RadioButtons sel' (mergeSelection sel' opts')
6868

6969
f (SD.CheckBoxes checkeds vals) = do
@@ -90,4 +90,3 @@ eval fs = everywhereM b i
9090
getValues e. SD.Expr (L.List e) L.List e
9191
getValues (SD.Literal vs) = vs
9292
getValues _ = L.Nil
93-

src/Text/Markdown/SlamDown/Parser/Inline.purs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ inlines = L.many inline2 <* PS.eof
177177
f is = SD.Strong $ L.singleton $ SD.Emph is
178178

179179
space P.Parser String (SD.Inline a)
180-
space = (toSpace <<< (S.fromChar <$>)) <$> L.some (PS.satisfy PU.isWhitespace)
180+
space = (toSpace <<< (S.fromChar <$> _)) <$> L.some (PS.satisfy PU.isWhitespace)
181181
where
182182
toSpace cs
183183
| "\n" `elem` cs =
@@ -305,7 +305,7 @@ inlines = L.many inline2 <* PS.eof
305305
where
306306
literalRadioButtons = do
307307
ls ← L.some $ PC.try do
308-
let item = SD.stringValue <$> manyOf \c → not $ c `elem` ['(',')',' ','!','`']
308+
let item = SD.stringValue <<< S.trim <$> manyOf \c → not $ c `elem` ['(',')','!','`']
309309
PU.skipSpaces
310310
b ← (PS.string "(x)" *> pure true) <|> (PS.string "()" *> pure false)
311311
PU.skipSpaces
@@ -317,10 +317,6 @@ inlines = L.many inline2 <* PS.eof
317317
_ → P.fail "Invalid number of selected radio buttons"
318318
pure $ SD.RadioButtons (SD.Literal sel) (SD.Literal (map snd ls))
319319

320-
321-
hole b. b
322-
hole = Unsafe.Coerce.unsafeCoerce "hole"
323-
324320
evaluatedRadioButtons = do
325321
SD.RadioButtons
326322
<$> PU.parens unevaluated
@@ -331,7 +327,7 @@ inlines = L.many inline2 <* PS.eof
331327
where
332328
literalCheckBoxes = do
333329
ls ← L.some $ PC.try do
334-
let item = SD.stringValue <$> manyOf \c → not $ c `elem` ['[',']',' ','!','`']
330+
let item = SD.stringValue <<< S.trim <$> manyOf \c → not $ c `elem` ['[',']','!','`']
335331
PU.skipSpaces
336332
b ← (PS.string "[x]" *> pure true) <|> (PS.string "[]" *> pure false)
337333
PU.skipSpaces
@@ -346,7 +342,7 @@ inlines = L.many inline2 <* PS.eof
346342

347343
dropDown P.Parser String (SD.FormField a)
348344
dropDown = do
349-
let item = SD.stringValue <$> manyOf \c → not $ c `elem` ['{','}',',',' ','!','`','(',')']
345+
let item = SD.stringValue <<< S.trim <$> manyOf \c → not $ c `elem` ['{','}',',','!','`','(',')']
350346
ls ← PU.braces $ expr id $ (PC.try (PU.skipSpaces *> item)) `PC.sepBy` (PU.skipSpaces *> PS.string ",")
351347
sel ← PC.optionMaybe $ PU.skipSpaces *> (PU.parens $ expr id $ item)
352348
return $ SD.DropDown sel ls
@@ -456,4 +452,3 @@ unevaluated = do
456452
PS.string "!"
457453
ticks ← someOf (\x → S.fromChar x == "`")
458454
SD.Unevaluated <<< S.fromCharArray <<< L.fromList <$> PC.manyTill PS.anyChar (PS.string ticks)
459-

src/Text/Markdown/SlamDown/Syntax/FormField.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ instance arbitraryFormField ∷ (SC.Arbitrary a, Eq a) ⇒ SC.Arbitrary (FormFie
134134
case xse of
135135
Literal xs → do
136136
x ← do
137-
def SC.arbitrary
137+
let def = Data.Maybe.Unsafe.fromJust (L.head xs)
138138
Literal <$> Gen.elements def xs
139139
pure $ RadioButtons x xse
140140
Unevaluated e → do
@@ -154,7 +154,7 @@ instance arbitraryFormField ∷ (SC.Arbitrary a, Eq a) ⇒ SC.Arbitrary (FormFie
154154
case xse of
155155
Literal xs → do
156156
mx ← genMaybe do
157-
def SC.arbitrary
157+
let def = Data.Maybe.Unsafe.fromJust (L.head xs)
158158
Literal <$> Gen.elements def xs
159159
pure $ DropDown mx xse
160160
Unevaluated e → do
@@ -169,7 +169,7 @@ instance arbitraryFormFieldIdentity ∷ (SC.Arbitrary a, Eq a) ⇒ SC.Arbitrary
169169
1do
170170
xs ← distinctListOf $ getArbIdentity <$> SC.arbitrary
171171
x ← do
172-
def <- getArbIdentity <$> SC.arbitrary
172+
let def = Data.Maybe.Unsafe.fromJust (L.head xs)
173173
Gen.elements def xs
174174
pure $ RadioButtons x $ TR.sequence xs
175175
2do
@@ -179,7 +179,7 @@ instance arbitraryFormFieldIdentity ∷ (SC.Arbitrary a, Eq a) ⇒ SC.Arbitrary
179179
_ → do
180180
xs ← distinctListOf $ getArbIdentity <$> SC.arbitrary
181181
mx ← genMaybe do
182-
def <- getArbIdentity <$> SC.arbitrary
182+
let def = Data.Maybe.Unsafe.fromJust (L.head xs)
183183
Gen.elements def xs
184184
pure $ DropDown mx $ TR.sequence xs
185185

test/src/Test/Main.purs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Data.Array as A
1717
import Data.Char as CH
1818
import Data.String as S
1919

20+
import Data.Tuple (uncurry)
21+
2022
import Text.Markdown.SlamDown.Syntax as SD
2123
import Text.Markdown.SlamDown.Eval as SDE
2224
import Text.Markdown.SlamDown.Parser as SDP
@@ -32,7 +34,28 @@ type TestEffects e =
3234
| e
3335
)
3436

35-
testDocument e. SD.SlamDown Eff (TestEffects e) Unit
37+
newtype NonEmptyString = NonEmptyString String
38+
derive instance eqNonEmptyStringEq NonEmptyString
39+
40+
genChar Gen.Gen Char
41+
genChar = Gen.elements '-' $ L.toList $ S.toCharArray "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*"
42+
43+
instance arbitraryNonEmptyStringSC.Arbitrary NonEmptyString where
44+
arbitrary =
45+
Gen.arrayOf1 genChar
46+
<#> uncurry A.cons
47+
>>> S.fromCharArray
48+
>>> S.trim
49+
>>> NonEmptyString
50+
51+
instance showNonEmptyStringShow NonEmptyString where
52+
show (NonEmptyString str) = str
53+
54+
instance valueNonEmptyStringSD.Value NonEmptyString where
55+
stringValue = NonEmptyString
56+
renderValue (NonEmptyString str) = str
57+
58+
testDocument e. SD.SlamDownP NonEmptyString Eff (TestEffects e) Unit
3659
testDocument sd = do
3760

3861
let printed = SDPR.prettyPrintMd sd
@@ -266,9 +289,9 @@ smallArrayOf g = do
266289
len ← Gen.chooseInt 1.0 2.0
267290
Gen.vectorOf len g
268291

269-
newtype TestSlamDown = TestSlamDown SD.SlamDown
292+
newtype TestSlamDown = TestSlamDown (SD.SlamDownP NonEmptyString)
270293

271-
runTestSlamDown TestSlamDown SD.SlamDown
294+
runTestSlamDown TestSlamDown SD.SlamDownP NonEmptyString
272295
runTestSlamDown (TestSlamDown sd) = sd
273296

274297
instance arbSlamDownSC.Arbitrary TestSlamDown where

0 commit comments

Comments
 (0)