Skip to content

Commit

Permalink
Expand Elm Interactive test coverage for deconstruction and List.sortBy
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed May 5, 2024
1 parent f9cce41 commit 2272636
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/elm-stuff/
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module DemoSyntax exposing (..)

import Syntax


type alias NodeContent =
{ alfa : Int
, beta : String
}


demoRange : Syntax.Range
demoRange =
{ start = { row = 1, column = 1 }
, end = { row = 1, column = 2 }
}


sumNodeContentAlfa : List (Syntax.Node NodeContent) -> Int
sumNodeContentAlfa nodes =
case nodes of
[] ->
0

node :: rest ->
let
(Syntax.Node _ content) =
node
in
content.alfa + sumNodeContentAlfa rest


concatNodeContentBeta : List (Syntax.Node NodeContent) -> String
concatNodeContentBeta nodes =
case nodes of
[] ->
""

node :: rest ->
let
(Syntax.Node _ content) =
node
in
content.beta ++ "-" ++ concatNodeContentBeta rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Syntax exposing (..)

{-| Some types from <https://github.com/Viir/elm-syntax/tree/f7d9be0a1f346b22dfaa7b55679659874c72714b/src/Elm/Syntax>
-}


{-| Base representation for a syntax node in a source file.
-}
type Node a
= Node Range a


{-| Source location
-}
type alias Location =
{ row : Int
, column : Int
}


{-| Range for a piece of code with a start and end
-}
type alias Range =
{ start : Location
, end : Location
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"abc-def-"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let
syntaxNodes : List (Syntax.Node DemoSyntax.NodeContent)
syntaxNodes =
[ Syntax.Node
{ start = { row = 1, column = 1 }, end = { row = 1, column = 2 } }
{ alfa = 123, beta = "abc" }
, Syntax.Node
{ start = { row = 1, column = 3 }, end = { row = 1, column = 4 } }
{ alfa = 456, beta = "def" }
]
in
DemoSyntax.concatNodeContentBeta syntaxNodes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-19,-7,5,11]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.sortBy identity [ 11, -7, 5, -19 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[(1,["c"]),(0,["a","b"])]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List.sortBy (\( _, dependencies ) -> List.length dependencies) [ (0, ["a","b"]), (1, ["c"]) ]

0 comments on commit 2272636

Please sign in to comment.