Skip to content

Commit

Permalink
Add rule for concept exercise lucians-luscious-lasagna
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegillet committed Nov 23, 2023
1 parent 56e8a21 commit ca9ea44
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Exercise/LuciansLusciousLasagna.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Exercise.LuciansLusciousLasagna exposing (reuseFunctions, ruleConfig)

import Analyzer exposing (CalledExpression(..), CalledFrom(..), Find(..))
import Comment exposing (Comment, CommentType(..))
import Dict
import Review.Rule exposing (Rule)
import RuleConfig exposing (AnalyzerRule(..), RuleConfig)


ruleConfig : RuleConfig
ruleConfig =
{ restrictToFiles = Just [ "src/LuciansLusciousLasagna.elm" ]
, rules =
[ CustomRule reuseFunctions
(Comment "elm.lucians-luscious-lasagna.reuse_functions" Essential Dict.empty)
]
}


reuseFunctions : Comment -> Rule
reuseFunctions =
Analyzer.functionCalls
{ calledFrom = TopFunction "elapsedTimeInMinutes"
, findExpressions = [ FromSameModule "preparationTimeInMinutes" ]
, find = Some
}
2 changes: 2 additions & 0 deletions src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Exercise.BlorkemonCards
import Exercise.CustomSet
import Exercise.GottaSnatchEmAll
import Exercise.ListOps
import Exercise.LuciansLusciousLasagna
import Exercise.MariosMarvellousLasagna
import Exercise.MazeMaker
import Exercise.Strain
Expand Down Expand Up @@ -47,6 +48,7 @@ ruleConfigs =
, Exercise.TisburyTreasureHunt.ruleConfig
, Exercise.GottaSnatchEmAll.ruleConfig
, Exercise.AnnalynsInfiltration.ruleConfig
, Exercise.LuciansLusciousLasagna.ruleConfig

-- Practice Exercises
, Exercise.Strain.ruleConfig
Expand Down
69 changes: 69 additions & 0 deletions tests/Exercise/LuciansLusciousLasagnaTest.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module Exercise.LuciansLusciousLasagnaTest exposing (tests)

import Comment exposing (Comment, CommentType(..))
import Dict
import Exercise.LuciansLusciousLasagna as LuciansLusciousLasagna
import Review.Rule exposing (Rule)
import Review.Test
import RuleConfig
import Test exposing (Test, describe, test)
import TestHelper


tests : Test
tests =
describe "LuciansLusciousLasagnaTest"
[ exemplar
, doesNotReuseFunction
]


rules : List Rule
rules =
LuciansLusciousLasagna.ruleConfig |> .rules |> List.map RuleConfig.analyzerRuleToRule


exemplar : Test
exemplar =
test "should not report anything for the exemplar" <|
\() ->
TestHelper.expectNoErrorsForRules rules
"""
module LuciansLusciousLasagna exposing (elapsedTimeInMinutes, expectedMinutesInOven, preparationTimeInMinutes)
expectedMinutesInOven =
40
preparationTimeInMinutes layers =
2 * layers
elapsedTimeInMinutes layers passedAlready =
passedAlready + preparationTimeInMinutes layers
"""


doesNotReuseFunction : Test
doesNotReuseFunction =
let
comment =
Comment "elm.lucians-luscious-lasagna.reuse_functions" Essential Dict.empty
in
test "canFreePrisoner doesn't use boolean operators" <|
\() ->
"""
module LuciansLusciousLasagna exposing (elapsedTimeInMinutes, expectedMinutesInOven, preparationTimeInMinutes)
expectedMinutesInOven =
40
preparationTimeInMinutes layers =
2 * layers
elapsedTimeInMinutes layers passedAlready =
passedAlready + 2 * layers
"""
|> Review.Test.run (LuciansLusciousLasagna.reuseFunctions comment)
|> Review.Test.expectErrors
[ TestHelper.createExpectedErrorUnder comment "elapsedTimeInMinutes"
|> Review.Test.atExactly { start = { row = 10, column = 1 }, end = { row = 10, column = 21 } }
]

0 comments on commit ca9ea44

Please sign in to comment.