mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 12:55:54 +03:00
Store computed aliases on TermResults
This commit is contained in:
parent
a6e926e4d2
commit
ce9b3b8a13
@ -15,6 +15,7 @@ module Unused.Types
|
|||||||
|
|
||||||
import qualified Data.Map.Strict as Map
|
import qualified Data.Map.Strict as Map
|
||||||
import Data.Csv
|
import Data.Csv
|
||||||
|
import qualified Data.List as L
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
import Unused.Regex
|
import Unused.Regex
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ data Occurrences = Occurrences
|
|||||||
|
|
||||||
data TermResults = TermResults
|
data TermResults = TermResults
|
||||||
{ trTerm :: String
|
{ trTerm :: String
|
||||||
|
, trTerms :: [String]
|
||||||
, trMatches :: [TermMatch]
|
, trMatches :: [TermMatch]
|
||||||
, trTestOccurrences :: Occurrences
|
, trTestOccurrences :: Occurrences
|
||||||
, trAppOccurrences :: Occurrences
|
, trAppOccurrences :: Occurrences
|
||||||
@ -63,6 +65,7 @@ resultsFromMatches :: [TermMatch] -> TermResults
|
|||||||
resultsFromMatches m =
|
resultsFromMatches m =
|
||||||
TermResults
|
TermResults
|
||||||
{ trTerm = resultTerm terms
|
{ trTerm = resultTerm terms
|
||||||
|
, trTerms = L.sort $ L.nub terms
|
||||||
, trMatches = m
|
, trMatches = m
|
||||||
, trAppOccurrences = appOccurrence
|
, trAppOccurrences = appOccurrence
|
||||||
, trTestOccurrences = testOccurrence
|
, trTestOccurrences = testOccurrence
|
||||||
|
@ -18,10 +18,10 @@ spec = parallel $
|
|||||||
, TermMatch "method_name" "app/path/other.rb" 5
|
, TermMatch "method_name" "app/path/other.rb" 5
|
||||||
, TermMatch "method_name" "spec/path/foo_spec.rb" 10
|
, 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 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
|
(Right config) <- loadConfig
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ spec = parallel $
|
|||||||
, TermMatch "method_name" "app/path/other.rb" 5
|
, TermMatch "method_name" "app/path/other.rb" 5
|
||||||
, TermMatch "method_name" "spec/path/foo_spec.rb" 10
|
, 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
|
let result = parseResults [] $ SearchResults r1Matches
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ spec = parallel $
|
|||||||
|
|
||||||
let result = parseResults config $ SearchResults searchResults
|
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`
|
result `shouldBe`
|
||||||
Map.fromList [ ("admin?|be_admin", results) ]
|
Map.fromList [ ("admin?|be_admin", results) ]
|
||||||
|
|
||||||
|
@ -15,4 +15,4 @@ spec = parallel $
|
|||||||
]
|
]
|
||||||
|
|
||||||
resultsFromMatches matches `shouldBe`
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user