packages feed

xdg-desktop-entry 0.1.1.1 → 0.1.1.2

raw patch · 3 files changed

+91/−22 lines, 3 filesdep +hspecdep +inidep +temporarydep −ConfigFiledep ~basedep ~directorydep ~eitherPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: hspec, ini, temporary, text, unordered-containers, xdg-desktop-entry

Dependencies removed: ConfigFile

Dependency ranges changed: base, directory, either, filepath, multimap, safe, transformers, unix

API changes (from Hackage documentation)

- System.Environment.XDG.DesktopEntry: readDesktopEntry :: FilePath -> IO (Either (CPErrorData, String) DesktopEntry)
+ System.Environment.XDG.DesktopEntry: readDesktopEntry :: FilePath -> IO (Either String DesktopEntry)

Files

src/System/Environment/XDG/DesktopEntry.hs view
@@ -37,17 +37,19 @@ import           Control.Monad import           Control.Monad.IO.Class import           Control.Monad.Trans.Except+import           Data.Bifunctor (bimap) import           Data.Char-import qualified Data.ConfigFile as CF+import qualified Data.Ini as Ini import           Data.Either import           Data.Either.Combinators+import qualified Data.HashMap.Strict as HM import qualified Data.MultiMap as MM import           Data.List import           Data.Maybe+import           Data.Text (pack, unpack) import           Safe import           System.Directory import           System.FilePath.Posix-import           System.Posix.Files import           Text.Printf import           Text.Read (readMaybe) @@ -176,10 +178,14 @@           (soFar ++) <$> listDesktopEntries "desktop" directory  -- | Read a desktop entry from a file.-readDesktopEntry :: FilePath -> IO (Either (CF.CPErrorData, String) DesktopEntry)+readDesktopEntry :: FilePath -> IO (Either String DesktopEntry) readDesktopEntry filePath = runExceptT $ do-  result <- (join $ liftIO $ CF.readfile CF.emptyCP filePath) >>=-            flip CF.items "Desktop Entry"+  -- let foo1 = join . fmap except . liftIO $ Ini.readIniFile filePath+  -- let bar :: ExceptT String IO (HM.HashMap Text [(Text, Text)]) = map Ini.iniSections . liftIO $ Ini.readIniFile filePath+  -- sections <- fmap Ini.iniSections . join . fmap except . liftIO $ Ini.readIniFile filePath+  sections <- liftIO (Ini.readIniFile filePath) >>= fmap Ini.iniSections . except+  result <- maybe (throwE "Section [Desktop Entry] not found") (pure . fmap (bimap unpack unpack)) $+              HM.lookup (pack "Desktop Entry") sections   return DesktopEntry          { deType = fromMaybe Application $ lookup "Type" result >>= readMaybe          , deFilename = filePath
+ test/Main.hs view
@@ -0,0 +1,44 @@+import Data.Either (isLeft)+import Data.Foldable (for_)+import System.Environment.XDG.DesktopEntry+import System.FilePath ((</>))+import System.IO.Temp (withSystemTempDirectory)+import Test.Hspec++fileContent :: [String]+fileContent = [+    "[Desktop Entry]\n\+    \Icon=1",++    "[Desktop Entry]\n\+    \icon=2",++    "[desktop entry]\n\+    \Icon=3"+  ]++main :: IO ()+main = withSystemTempDirectory "xdg-desktop-entry" $ \dir -> do+  let filepath :: Int -> String+      filepath i = dir </> show i+  for_ (zip [0::Int ..] fileContent) $ \(i, content) -> do+    print i+    writeFile (filepath i) content+  hspec $ do+    describe "deAtt" $ do+      it "content0 should work" $ do+        deResultE <- readDesktopEntry $ filepath 0+        case deResultE of+          Left e -> expectationFailure $ show e+          Right deResult ->+            deIcon deResult `shouldBe` Just "1"+      it "content1 should not work" $ do+        deResultE <- readDesktopEntry $ filepath 1+        print deResultE+        case deResultE of+          Left e -> expectationFailure $ show e+          Right deResult ->+            deIcon deResult `shouldBe` Nothing+      it "content2 should not work" $ do+        deResultE <- readDesktopEntry $ filepath 2+        isLeft deResultE `shouldBe` True
xdg-desktop-entry.cabal view
@@ -1,31 +1,50 @@ cabal-version:       2.4--- Initial package description 'xdg-desktop-entry.cabal' generated by--- 'cabal init'.  For further documentation, see--- http://haskell.org/cabal/users-guide/- name:                xdg-desktop-entry-version:             0.1.1.1+version:             0.1.1.2 synopsis:            Parse files conforming to the xdg desktop entry spec--- description:--- bug-reports:+description:         Parse files conforming to the xdg desktop entry spec.+bug-reports:         https://github.com/taffybar/xdg-desktop-entry/issues+homepage:            https://github.com/taffybar/xdg-desktop-entry license:             BSD-3-Clause license-file:        LICENSE author:              Ivan Malison maintainer:          IvanMalison@gmail.com -- copyright: category:            System-extra-source-files:  CHANGELOG.md+extra-doc-files:  CHANGELOG.md+tested-with:         GHC == 8.8.4 || == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.4 || == 9.8.1 +source-repository head+  type:     git+  location: https://github.com/taffybar/xdg-desktop-entry.git+ library   exposed-modules:     System.Environment.XDG.DesktopEntry-  build-depends:       base >=4.12 && < 5,-                       ConfigFile,-                       directory,-                       either,-                       filepath,-                       multimap,-                       transformers,-                       safe,-                       unix,+  build-depends:       base >=4.13 && < 5,+                       directory >= 1.3.6 && < 1.4,+                       either >= 5.0.1.1 && < 5.1,+                       filepath >= 1.4.2 && < 1.6,+                       ini >= 0.4.1 && < 0.4.3,+                       multimap >= 1.2.1 && < 1.3,+                       safe >= 0.3.19 && < 0.4,+                       text >= 1.2.4 && < 2.2,+                       transformers >= 0.5.6 && < 0.6.2,+                       unix >= 2.7.2 && < 2.9,+                       unordered-containers >= 0.2.10 && < 0.3   hs-source-dirs:      src   default-language:    Haskell2010+  ghc-options:         -Wall++test-suite test+  type:             exitcode-stdio-1.0+  main-is:          Main.hs+  hs-source-dirs:   test+  build-depends:+                    base+                  , filepath+                  , hspec+                  , temporary+                  , unix+                  , xdg-desktop-entry+  default-language: Haskell2010+  ghc-options:      -Wall