From ce9b3b8a13c99f1043f4a1f63194f6d46f514af1 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Sat, 18 Jun 2016 07:41:50 -0400 Subject: [PATCH] Store computed aliases on TermResults --- src/Unused/Types.hs | 3 +++ test/Unused/ParserSpec.hs | 8 ++++---- test/Unused/TypesSpec.hs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Unused/Types.hs b/src/Unused/Types.hs index 9793299..d5c68e6 100644 --- a/src/Unused/Types.hs +++ b/src/Unused/Types.hs @@ -15,6 +15,7 @@ module Unused.Types import qualified Data.Map.Strict as Map import Data.Csv +import qualified Data.List as L import GHC.Generics import Unused.Regex @@ -34,6 +35,7 @@ data Occurrences = Occurrences data TermResults = TermResults { trTerm :: String + , trTerms :: [String] , trMatches :: [TermMatch] , trTestOccurrences :: Occurrences , trAppOccurrences :: Occurrences @@ -63,6 +65,7 @@ resultsFromMatches :: [TermMatch] -> TermResults resultsFromMatches m = TermResults { trTerm = resultTerm terms + , trTerms = L.sort $ L.nub terms , trMatches = m , trAppOccurrences = appOccurrence , trTestOccurrences = testOccurrence diff --git a/test/Unused/ParserSpec.hs b/test/Unused/ParserSpec.hs index c215503..e49e7dc 100644 --- a/test/Unused/ParserSpec.hs +++ b/test/Unused/ParserSpec.hs @@ -18,10 +18,10 @@ spec = parallel $ , 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 r1Results = TermResults "method_name" ["method_name"] r1Matches (Occurrences 1 10) (Occurrences 2 6) (Occurrences 3 16) (Removal Low "used frequently") let r2Matches = [ TermMatch "other" "app/path/other.rb" 1 ] - let r2Results = TermResults "other" r2Matches (Occurrences 0 0) (Occurrences 1 1) (Occurrences 1 1) (Removal High "used once") + let r2Results = TermResults "other" ["other"] r2Matches (Occurrences 0 0) (Occurrences 1 1) (Occurrences 1 1) (Removal High "used once") (Right config) <- loadConfig @@ -35,7 +35,7 @@ spec = parallel $ , 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 r1Results = TermResults "method_name" ["method_name"] r1Matches (Occurrences 1 10) (Occurrences 2 6) (Occurrences 3 16) (Removal Low "used frequently") let result = parseResults [] $ SearchResults r1Matches @@ -55,7 +55,7 @@ spec = parallel $ let result = parseResults config $ SearchResults searchResults - let results = TermResults "admin?" searchResults (Occurrences 2 4) (Occurrences 1 3) (Occurrences 3 7) (Removal Low "used frequently") + let results = TermResults "admin?" ["admin?", "be_admin"] searchResults (Occurrences 2 4) (Occurrences 1 3) (Occurrences 3 7) (Removal Low "used frequently") result `shouldBe` Map.fromList [ ("admin?|be_admin", results) ] diff --git a/test/Unused/TypesSpec.hs b/test/Unused/TypesSpec.hs index a14c373..151c102 100644 --- a/test/Unused/TypesSpec.hs +++ b/test/Unused/TypesSpec.hs @@ -15,4 +15,4 @@ spec = parallel $ ] resultsFromMatches matches `shouldBe` - TermResults "ApplicationController" matches (Occurrences 1 10) (Occurrences 1 1) (Occurrences 2 11) (Removal NotCalculated "Likelihood not calculated") + TermResults "ApplicationController" ["ApplicationController"] matches (Occurrences 1 10) (Occurrences 1 1) (Occurrences 2 11) (Removal NotCalculated "Likelihood not calculated")