Open lukewilliamboswell opened 4 months ago
$ roc test platform/MultipartFormData.roc ── EXPECT FAILED in platform/MultipartFormData.roc ───────────────────────────── This expectation failed: 35│> expect 36│> input = Str.toUtf8 "Content-Disposition: form-data; name=\"sometext\"" 37│> actual = parseContentDisposition input 38│> expected = Ok { 39│> disposition : Str.toUtf8 "form-data; name=\"sometext\"", 40│> rest : [], 41│> } 42│> actual == expected When it failed, these variables had these values: input : List U8 input = [67, 111, 110, 116, 101, 110, 116, 45, 68, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 58, 32, 102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 111, 109, 101, 116, 101, 120, 116, 34] actual : Result { disposition : List U8, rest : List U8, } {} actual = Ok { disposition: [102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 111, 109, 101, 116, 101, 120, 116, 34], rest: [] } expected : [ Err {}, Ok { disposition : List U8, rest : List U8, }, ] expected = Ok { disposition: [102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 111, 109, 101, 116, 101, 120, 116, 34], rest: [] } 1 failed and 0 passed in 430 ms.
module [] parseContentDisposition : List U8 -> Result { disposition : List U8, rest : List U8 } {} parseContentDisposition = \bytes -> search = Str.toUtf8 "Content-Disposition:" if List.startsWith bytes search then List.findFirstIndex bytes \b -> b == '\r' |> Result.mapErr \NotFound -> {} |> Result.try \idx -> Ok { disposition : bytes |> List.sublist {start : 0, len : idx} |> List.dropFirst (List.len search), rest : List.dropFirst bytes idx, } else Err {} expect input = Str.toUtf8 "Content-Disposition: form-data; name=\"sometext\"" actual = parseContentDisposition input expected = Ok { disposition : Str.toUtf8 "form-data; name=\"sometext\"", rest : [], } actual == expected
$ roc repl The rockin' roc repl ──────────────────────── Enter an expression, or :help, or :q to quit. » … actual = Ok { disposition: [102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 111, 109, 101, 116, 101, 120, 116, 34], rest: [] } … expected = Ok { disposition: [102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 111, 109, 101, 116, 101, 120, 116, 34], rest: [] } … actual == expected Bool.true : Bool