semantic-source 0.1.0.2 → 0.2.0.0
raw patch · 5 files changed
+43/−39 lines, 5 filesdep −pathtypedep ~hedgehogdep ~tasty-hedgehog
Dependencies removed: pathtype
Dependency ranges changed: hedgehog, tasty-hedgehog
Files
- CHANGELOG.md +6/−0
- semantic-source.cabal +3/−4
- src/Source/Language.hs +26/−28
- test/Range/Test.hs +3/−2
- test/Source/Test.hs +5/−5
CHANGELOG.md view
@@ -1,3 +1,9 @@+# 0.2.0.0++- Finds languages for `FilePath`s.+- Drops dependency on `pathtype`.++ # 0.1.0.2 - Support ghc 9.2.
semantic-source.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: semantic-source-version: 0.1.0.2+version: 0.2.0.0 synopsis: Types and functionality for working with source code description: Types and functionality for working with source code (program text). homepage: https://github.com/github/semantic/tree/master/semantic-source#readme@@ -64,7 +64,6 @@ , containers ^>= 0.6.2 , hashable >= 1.2.7 && < 1.4 , lingo ^>= 0.5.0.3- , pathtype ^>= 0.8.1 , semilattices ^>= 0.0.0.3 , text ^>= 1.2.3.2 hs-source-dirs: src@@ -79,10 +78,10 @@ Source.Test build-depends: , base- , hedgehog ^>= 1+ , hedgehog >= 1 && < 1.2 , semantic-source , tasty >= 1.2 && <2- , tasty-hedgehog ^>= 1.0.0.1+ , tasty-hedgehog >= 1.0.0.1 && < 1.3 , tasty-hunit >= 0.10 && <1 , text
src/Source/Language.hs view
@@ -20,8 +20,6 @@ import qualified Data.Map.Strict as Map import qualified Data.Text as T import GHC.Generics (Generic)-import qualified System.Path as Path-import qualified System.Path.PartClass as Path.PartClass -- | The various languages we support. data Language@@ -96,47 +94,47 @@ extensionsForLanguage :: Language -> [String] extensionsForLanguage language = fmap T.unpack (maybe mempty Lingo.languageExtensions (Map.lookup (languageToText language) Lingo.languages)) -forPath :: Path.PartClass.AbsRel ar => Path.File ar -> Language+forPath :: FilePath -> Language forPath path = let spurious lang = lang `elem` [ "Hack" -- .php files , "GCC Machine Description" -- .md files , "XML" -- .tsx files ]- allResults = Lingo.languageName <$> Lingo.languagesForPath (Path.toString path)+ allResults = Lingo.languageName <$> Lingo.languagesForPath path in case filter (not . spurious) allResults of [result] -> textToLanguage result _ -> Unknown languageToText :: Language -> T.Text languageToText = \case- Unknown -> "Unknown"- CodeQL -> "CodeQL"- Go -> "Go"- Haskell -> "Haskell"- Java -> "Java"+ Unknown -> "Unknown"+ CodeQL -> "CodeQL"+ Go -> "Go"+ Haskell -> "Haskell"+ Java -> "Java" JavaScript -> "JavaScript"- JSON -> "JSON"- JSX -> "JSX"- Markdown -> "Markdown"- PHP -> "PHP"- Python -> "Python"- Ruby -> "Ruby"+ JSON -> "JSON"+ JSX -> "JSX"+ Markdown -> "Markdown"+ PHP -> "PHP"+ Python -> "Python"+ Ruby -> "Ruby" TypeScript -> "TypeScript"- TSX -> "TSX"+ TSX -> "TSX" textToLanguage :: T.Text -> Language textToLanguage = \case- "CodeQL" -> CodeQL- "Go" -> Go- "Haskell" -> Haskell- "Java" -> Java+ "CodeQL" -> CodeQL+ "Go" -> Go+ "Haskell" -> Haskell+ "Java" -> Java "JavaScript" -> JavaScript- "JSON" -> JSON- "JSX" -> JSX- "Markdown" -> Markdown- "PHP" -> PHP- "Python" -> Python- "Ruby" -> Ruby+ "JSON" -> JSON+ "JSX" -> JSX+ "Markdown" -> Markdown+ "PHP" -> PHP+ "Python" -> Python+ "Ruby" -> Ruby "TypeScript" -> TypeScript- "TSX" -> TSX- _ -> Unknown+ "TSX" -> TSX+ _ -> Unknown
test/Range/Test.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE OverloadedStrings #-} module Range.Test ( testTree ) where@@ -8,12 +9,12 @@ import qualified Hedgehog.Range as Range import Source.Range import qualified Test.Tasty as Tasty-import Test.Tasty.Hedgehog (testProperty)+import Test.Tasty.Hedgehog (testPropertyNamed) testTree :: Tasty.TestTree testTree = Tasty.testGroup "Source.Range" [ Tasty.testGroup "Semigroup"- [ testProperty "associativity" . property $ do+ [ testPropertyNamed "associativity" "Range_associativity" . property $ do (a, b, c) <- forAll ((,,) <$> range <*> range <*> range) a <> (b <> c) === (a <> b) <> c ]
test/Source/Test.hs view
@@ -11,7 +11,7 @@ import Source.Span import qualified Test.Tasty as Tasty import Test.Tasty.HUnit-import Test.Tasty.Hedgehog (testProperty)+import Test.Tasty.Hedgehog (testPropertyNamed) source :: MonadGen m => Range.Range Int -> m Source.Source@@ -22,23 +22,23 @@ testTree :: Tasty.TestTree testTree = Tasty.testGroup "Source.Source" [ Tasty.testGroup "lineRanges"- [ testProperty "produces 1 more range than there are newlines" . property $ do+ [ testPropertyNamed "produces 1 more range than there are newlines" "Source_lineRanges_produces_1_more_range_than_there_are_newlines" . property $ do source <- forAll (source (Range.linear 0 100)) summarize source length (Source.lineRanges source) === length (Text.splitOn "\r\n" (Source.toText source) >>= Text.splitOn "\r" >>= Text.splitOn "\n") - , testProperty "produces exhaustive ranges" . property $ do+ , testPropertyNamed "produces exhaustive ranges" "Source_lineRanges_produces_exhaustive_ranges" . property $ do source <- forAll (source (Range.linear 0 100)) summarize source foldMap (Source.slice source) (Source.lineRanges source) === source ] , Tasty.testGroup "totalSpan"- [ testProperty "covers single lines" . property $ do+ [ testPropertyNamed "covers single lines" "Source_totalSpan_covers_single_lines" . property $ do n <- forAll $ Gen.int (Range.linear 0 100) Source.totalSpan (Source.fromText (Text.replicate n "*")) === Span (Pos 1 1) (Pos 1 (max 1 (succ n))) - , testProperty "covers multiple lines" . property $ do+ , testPropertyNamed "covers multiple lines" "Source_totalSpan_covers_multiple_lines" . property $ do n <- forAll $ Gen.int (Range.linear 0 100) Source.totalSpan (Source.fromText (Text.intersperse '\n' (Text.replicate n "*"))) === Span (Pos 1 1) (Pos (max 1 n) (if n > 0 then 2 else 1)) ]