Skip to content

Commit

Permalink
Merge pull request #44 from jxxcarlson/bug/element-to-list
Browse files Browse the repository at this point in the history
Bug/element to list: fix infinite loop bug in ElementToList
  • Loading branch information
jxxcarlson authored Jul 20, 2024
2 parents 21ab2c7 + cafa20f commit 991a7f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Install/Library.elm
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ expressionToString (Node _ expression) =
RecordAccess child field ->
expressionToString child ++ "." ++ Node.value field

Literal str ->
"\"" ++ str ++ "\""

-- CaseExpression caseBlock ->
-- "case " ++ expressionToString caseBlock.expression ++ " of " ++ String.join " " (List.map caseToString caseBlock.cases)
-- LambdaExpression lambda ->
Expand Down
49 changes: 49 additions & 0 deletions tests/Install/ElementToListTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ all =
[ Run.testFix test1
, Run.expectNoErrorsTest "should not report error when the field already exists" src0 rule1
, Run.testFix test2
, Run.testFix test4
]


Expand Down Expand Up @@ -127,3 +128,51 @@ contributors : List Contributors
contributors =
[ Jxx, Matt, Laozi ]
"""



-- TEST 4


test4 =
{ description = "should add an element to a list of tuples in project"
, src = src4
, rule = rule4
, under = under4
, fixed = fixed4
, message = "Add 2 elements to the list"
}


src4 =
"""module Routes exposing (..)
type Route
= HomepageRoute
| Quotes
routesAndNames : List (Route, String)
routesAndNames =
[(HomepageRoute, "homepage")]
"""


rule4 =
makeRule "Routes" "routesAndNames" [ "(Quotes, \"quotes\")" ]


under4 =
"""[(HomepageRoute, "homepage")]"""


fixed4 =
"""module Routes exposing (..)
type Route
= HomepageRoute
| Quotes
routesAndNames : List (Route, String)
routesAndNames =
[(HomepageRoute, "homepage"), (Quotes, "quotes")]
"""

0 comments on commit 991a7f2

Please sign in to comment.