mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
fix empty list test
This commit is contained in:
parent
44778c72fe
commit
d8d3d252f1
1 changed files with 17 additions and 9 deletions
|
@ -7,6 +7,7 @@ interface Json
|
|||
imports [
|
||||
List,
|
||||
Str,
|
||||
Result.{ Result },
|
||||
Encode,
|
||||
Encode.{
|
||||
Encoder,
|
||||
|
@ -398,12 +399,18 @@ decodeList = \decodeElem -> Decode.custom \bytes, @Json {} ->
|
|||
when bytes is
|
||||
['[', ']'] -> { result: Ok [], rest: List.drop bytes 2 }
|
||||
['[', ..] ->
|
||||
when decodeElems (eatWhitespace (List.dropFirst bytes)) [] is
|
||||
Errored e rest -> { result: Err e, rest }
|
||||
Done vals rest ->
|
||||
when rest is
|
||||
[']', ..] -> { result: Ok vals, rest: List.dropFirst rest }
|
||||
_ -> { result: Err TooShort, rest }
|
||||
bytesWithoutWhitespace = eatWhitespace (List.dropFirst bytes)
|
||||
when bytesWithoutWhitespace is
|
||||
[']', ..] ->
|
||||
{ result: Ok [], rest: List.dropFirst bytesWithoutWhitespace }
|
||||
_ ->
|
||||
when decodeElems bytesWithoutWhitespace [] is
|
||||
Errored e rest ->
|
||||
{ result: Err e, rest }
|
||||
Done vals rest ->
|
||||
when rest is
|
||||
[']', ..] -> { result: Ok vals, rest: List.dropFirst rest }
|
||||
_ -> { result: Err TooShort, rest }
|
||||
|
||||
_ ->
|
||||
{ result: Err TooShort, rest: bytes }
|
||||
|
@ -510,10 +517,11 @@ expect
|
|||
# Test json array decode empty list
|
||||
expect
|
||||
input = Str.toUtf8 "[ ]"
|
||||
expected = []
|
||||
|
||||
actual : List U8
|
||||
actual = Decode.fromBytes input fromUtf8 |> Result.withDefault []
|
||||
actual : Result (List U8) _
|
||||
actual = Decode.fromBytes input fromUtf8
|
||||
|
||||
expected = Ok []
|
||||
|
||||
actual == expected
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue