Skip to content

Commit

Permalink
Merge pull request #205 from mumuki/feature-add-usesLoop-expectation
Browse files Browse the repository at this point in the history
Feature add uses loop expectation
  • Loading branch information
flbulgarelli authored Dec 3, 2018
2 parents 715795a + 98df269 commit 2d6cb38
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ The power of Mulang is grounded on more than 70 different kind of inspections:
| `usesIf` | any | is an `if` control structure used?
| `usesInheritance` | object oriented | is any superclass explicitly declared?
| `usesLambda` |
| `usesLoop` | procedural | are any of: repeat / for loop / foreach / while used?
| `usesMixins` | object oriented | is any mixins explicitly included?
| `usesNot` |
| `usesObjectComposition` | object oriented | is there a class that declares an attributes and sends a message to it?
Expand Down
3 changes: 3 additions & 0 deletions spec/ExpectationsCompilerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ spec = do
it "works with UsesRepeat" $ do
run (hs "f x = 2") "*" "UsesRepeat" `shouldBe` False

it "works with UsesLoop" $ do
run (js "function a() { a() }") "*" "UsesLoop" `shouldBe` False

it "works with UsesPatternMatching" $ do
run (hs "f x = 2") "*" "UsesPatternMatching" `shouldBe` False
run (hs "f [] = 2\nf _ = 3") "*" "UsesPatternMatching" `shouldBe` True
Expand Down
26 changes: 26 additions & 0 deletions spec/InspectorSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ spec = do

usesRepeat code `shouldBe` False

describe "usesLoop" $ do
it "is True when repeat is present" $ do
let code = SimpleFunction "f" [] (Sequence [Repeat (MuNumber 2) None, Return (MuNumber 2)])

usesLoop code `shouldBe` True

it "is True when foreach is present" $ do
let code = SimpleFunction "f" [] (Sequence [For [] None, Return (MuNumber 2)])

usesLoop code `shouldBe` True

it "is True when for is present" $ do
let code = js "function f() { for(;;); }"

usesLoop code `shouldBe` True

it "is True when while is present" $ do
let code = js "function f() { while(true); }"

usesLoop code `shouldBe` True

it "is False when none of the aforementioned are present" $ do
let code = js "function f(x){return 1;}"

usesLoop code `shouldBe` False

describe "declaresVariable" $ do
it "is True when declare a variable" $ do
let code = js "function f(){ var x = 2}"
Expand Down
1 change: 1 addition & 0 deletions src/Language/Mulang/Analyzer/ExpectationsCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ compileInspectionPrimitive = f
f "UsesIf" = simple usesIf
f "UsesInheritance" = simple usesInheritance
f "UsesLambda" = simple usesLambda
f "UsesLoop" = simple usesLoop
f "UsesMixins" = simple usesMixins
f "UsesNot" = simple usesNot
f "UsesObjectComposition" = simple usesObjectComposition
Expand Down
4 changes: 4 additions & 0 deletions src/Language/Mulang/Inspector/Procedural.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Language.Mulang.Inspector.Procedural (
usesSwitch,
usesForEach,
usesForLoop,
usesLoop,
declaresProcedure) where

import Language.Mulang.Ast
Expand Down Expand Up @@ -45,3 +46,6 @@ usesForLoop :: Inspection
usesForLoop = containsExpression f
where f (ForLoop _ _ _ _) = True
f _ = False

usesLoop :: Inspection
usesLoop e = usesRepeat e || usesWhile e || usesForLoop e || usesForEach e

0 comments on commit 2d6cb38

Please sign in to comment.