mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Ensure results work when no config can be loaded
Why? ==== If no config can be loaded correctly, unused should still function correctly, albeit with likely more false positives.
This commit is contained in:
parent
54e55c46a2
commit
9bf9499e67
@ -24,6 +24,7 @@ groupedTermsAndAliases as ms =
|
||||
aliases = map toAlias as
|
||||
|
||||
termsAndAliases :: [TermAlias] -> [String] -> [String]
|
||||
termsAndAliases [] = id
|
||||
termsAndAliases as =
|
||||
nub . map T.unpack . concatMap (allAliases aliases . T.pack)
|
||||
where
|
||||
|
21
test/Unused/AliasesSpec.hs
Normal file
21
test/Unused/AliasesSpec.hs
Normal file
@ -0,0 +1,21 @@
|
||||
module Unused.AliasesSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import Unused.Aliases
|
||||
import Unused.ResultsClassifier.Types (TermAlias(..))
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
||||
|
||||
spec :: Spec
|
||||
spec = parallel $
|
||||
describe "termsAndAliases" $ do
|
||||
it "returns the terms if no aliases are provided" $
|
||||
termsAndAliases [] ["method_1", "method_2"] `shouldBe` ["method_1", "method_2"]
|
||||
|
||||
it "adds aliases to the list of terms" $ do
|
||||
let predicateAlias = TermAlias "%s?" "be_%s"
|
||||
let pluralizeAlias = TermAlias "really_%s" "very_%s"
|
||||
|
||||
termsAndAliases [predicateAlias, pluralizeAlias] ["awesome?", "really_cool"]
|
||||
`shouldBe` ["awesome?", "be_awesome", "really_cool", "very_cool"]
|
@ -30,6 +30,18 @@ spec = parallel $
|
||||
result `shouldBe`
|
||||
Map.fromList [ ("method_name", r1Results), ("other", r2Results) ]
|
||||
|
||||
it "parses when no config is provided" $ do
|
||||
let r1Matches = [ TermMatch "method_name" "app/path/foo.rb" 1
|
||||
, TermMatch "method_name" "app/path/other.rb" 5
|
||||
, TermMatch "method_name" "spec/path/foo_spec.rb" 10
|
||||
]
|
||||
let r1Results = TermResults "method_name" r1Matches (Occurrences 1 10) (Occurrences 2 6) (Occurrences 3 16) (Removal Low "used frequently")
|
||||
|
||||
let result = parseResults [] $ SearchResults r1Matches
|
||||
|
||||
result `shouldBe`
|
||||
Map.fromList [ ("method_name", r1Results) ]
|
||||
|
||||
it "handles aliases correctly" $ do
|
||||
let r1Matches = [ TermMatch "admin?" "app/path/user.rb" 3 ]
|
||||
|
||||
|
@ -95,6 +95,7 @@ test-suite unused-test
|
||||
, Unused.TermSearch.InternalSpec
|
||||
, Unused.UtilSpec
|
||||
, Unused.Cache.FindArgsFromIgnoredPathsSpec
|
||||
, Unused.AliasesSpec
|
||||
, Paths_unused
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
|
||||
default-language: Haskell2010
|
||||
|
Loading…
Reference in New Issue
Block a user