git.iko.soy/rowtype-yoga/purescript-docs-search
on master help sign in
fix RCons
commit5d24954f8fa5986564ac5b6feab5c4f93043ed81 authorklntsky <klntsky@gmail.com> dateWed 26 Jun 2019, 00:33 (7 years ago) parent9ab05b1
2 files changed+51−9
src/Spago/Search/TypeParser.purs+6−9 test/Main.purs+45
src/Spago/Search/TypeParser.purs+6−9
@@ -280,14 +280,11 @@ decodeTuple cont err json =
280280 Right $ cont a b
281281 _ -> Left $ err unit
282282
283−data Triple a b c = T1 a | T2 b | T3 c
284−
285283decodeTriple
286− :: forall fst sec trd res
284+ :: forall fst sec res
287285 . DecodeJson fst
288286 => DecodeJson sec
289− => DecodeJson trd
290− => (fst -> sec -> trd -> res)
287+ => (fst -> sec -> sec -> res)
291288 -> (forall a. a -> String)
292289 -> Json
293290 -> Either String res
@@ -297,11 +294,11 @@ decodeTriple cont err json =
297294 Just arrOfJsons -> do
298295 let arrayOfVariants =
299296 arrOfJsons <#> \variantJson ->
300− T1 <$> decodeJson variantJson <|>
301− T2 <$> decodeJson variantJson <|>
302− T3 <$> decodeJson variantJson
297+ Left <$> decodeJson variantJson <|>
298+ Right <$> decodeJson variantJson <|>
299+ Right <$> decodeJson variantJson
303300 case arrayOfVariants of
304− [ Right (T1 a), Right (T2 b), Right (T3 c) ] ->
301+ [ Right (Left a), Right (Right b), Right (Right c) ] ->
305302 Right $ cont a b c
306303 _ -> Left $ err unit
307304
test/Main.purs+45
@@ -205,6 +205,7 @@ main = runTest do
205205 }
206206 ))
207207 (TypeVar "h")
208+
208209 test "TypeOp" do
209210 let typeOp = mkJson """
210211 {
@@ -312,6 +313,50 @@ main = runTest do
312313 name: "String"
313314 }
314315 ))
316+ test "RCons" do
317+
318+ let rcons = mkJson """
319+ {
320+ "annotation": [],
321+ "tag": "RCons",
322+ "contents": [
323+ "tail",
324+ {
325+ "annotation": [],
326+ "tag": "TypeApp",
327+ "contents": [
328+ {
329+ "annotation": [],
330+ "tag": "TypeConstructor",
331+ "contents": [
332+ [
333+ "Data",
334+ "Symbol"
335+ ],
336+ "SProxy"
337+ ]
338+ },
339+ {
340+ "annotation": [],
341+ "tag": "TypeVar",
342+ "contents": "t"
343+ }
344+ ]
345+ },
346+ {
347+ "annotation": [],
348+ "tag": "REmpty"
349+ }
350+ ]
351+ }
352+ """
353+
354+ assertRight (decodeJson rcons) $
355+ RCons
356+ "tail"
357+ (TypeApp (TypeConstructor $ QualifiedName { moduleName: [ "Data", "Symbol" ], name: "SProxy" })
358+ (TypeVar "t"))
359+ REmpty
315360
316361assertRight :: forall a. Show a => Eq a => Either String a -> a -> Aff Unit
317362assertRight eiActual expected =