Skip to content

Commit

Permalink
Expand coverage of Elm core libraries for Elm compiler
Browse files Browse the repository at this point in the history
Expand the coverage of the Elm core libraries for functions used by the Pine module in the Elm compiler: Add test scenarios and implementations for declarations from the 'List' and 'String' modules.
  • Loading branch information
Viir committed Jan 1, 2024
1 parent f228f0a commit b82f41c
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,21 @@ filter isGood list =
foldr (\\x xs -> if isGood x then cons x xs else xs) [] list
filterMap : (a -> Maybe b) -> List a -> List b
filterMap f xs =
foldr (maybeCons f) [] xs
maybeCons : (a -> Maybe b) -> a -> List b -> List b
maybeCons f mx xs =
case f mx of
Just x ->
cons x xs
Nothing ->
xs
length : List a -> Int
length list =
Pine_kernel.length list
Expand All @@ -610,6 +625,11 @@ member x xs =
any ((==) x) xs
all : (a -> Bool) -> List a -> Bool
all isOkay list =
not (any (not << isOkay) list)
any : (a -> Bool) -> List a -> Bool
any isOkay list =
case list of
Expand All @@ -624,6 +644,31 @@ any isOkay list =
any isOkay xs
minimum : List comparable -> Maybe comparable
minimum list =
case list of
x :: xs ->
Just (foldl min x xs)
_ ->
Nothing
maximum : List comparable -> Maybe comparable
maximum list =
case list of
x :: xs ->
Just (foldl max x xs)
_ ->
Nothing
sum : List number -> number
sum numbers =
foldl (+) 0 numbers
append : List a -> List a -> List a
append xs ys =
concat [ xs, ys ]
Expand Down Expand Up @@ -1275,6 +1320,20 @@ dropWhileList predicate stringList =
else
stringList
padLeft : Int -> Char -> String -> String
padLeft n char string =
repeat (n - length string) (fromChar char) ++ string
lines : String -> List String
lines string =
string
|> replace "\\r\\n" "\\n"
|> replace "\\r" "\\n"
|> split "\\n"
"""
, """
module Array exposing (..)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[3,12]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.filterMap String.toInt [ "3", "hi", "12", "4th", "May" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[True,False]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let
isEven n =
modBy 2 n == 0
in
[ List.all isEven [ 0, 4, 6 ]
, List.all isEven [ 0, 3, 6 ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just 17
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.minimum [ 31, 17, 41, 37 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just 41
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.maximum [ 31, 17, 41, 37 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
41
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.sum [ 11, 13, 17 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"test"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String.padLeft 3 '-' "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"---test"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String.padLeft 7 '-' "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["alfa","beta"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String.lines "alfa\nbeta"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["alfa","beta"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String.lines "alfa\rbeta"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["alfa","beta"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String.lines "alfa\r\nbeta"

0 comments on commit b82f41c

Please sign in to comment.