packages feed

htoml-megaparsec 1.0.1.6 → 1.0.1.7

raw patch · 7 files changed

+32/−33 lines, 7 filesdep +hspecPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: hspec

API changes (from Hackage documentation)

- Text.Toml: checkTomlDoc :: String -> Text -> Either TomlError ()
- Text.Toml.Parser: tomlCheck :: (TomlM m) => Parser m ()

Files

benchmarks/Benchmarks.hs view
@@ -8,10 +8,6 @@ import           Text.Toml import           Text.Toml.Types () -eitherToMaybe :: Either a b -> Maybe b-eitherToMaybe Left{}    = Nothing-eitherToMaybe (Right x) = Just x- main :: IO () main = do     exampleToml  <- readFile "./benchmarks/example.toml"@@ -28,11 +24,6 @@       , bgroup "file"         [ bench "example"     $ whnf (parseTomlDoc "") exampleToml         , bench "repeated-4x" $ whnf (parseTomlDoc "") repeatedToml-        ]--      , bgroup "file-check"-        [ bench "example"     $ whnf (checkTomlDoc "") exampleToml-        , bench "repeated-4x" $ whnf (checkTomlDoc "") repeatedToml         ]        ]
htoml-megaparsec.cabal view
@@ -1,5 +1,5 @@-name:                     htoml-megaparsec-version:                  1.0.1.6+name:                    htoml-megaparsec+version:                  1.0.1.7 synopsis:                 Parser for TOML files description:              TOML is an obvious and minimal format for config files.                           This package provides a TOML parser@@ -57,11 +57,13 @@   other-modules:          BurntSushi                         , JSON                         , Text.Toml.Parser.Spec+                        , Text.TomlSpec   type:                   exitcode-stdio-1.0   default-language:       Haskell2010   build-depends:          base                         , megaparsec                         , containers+                        , hspec                         , unordered-containers                         , vector                         , aeson
src/Text/Toml.hs view
@@ -6,11 +6,8 @@ import           Text.Megaparsec import           Text.Toml.Parser --- | Parse a 'Text' that results in 'Either' a 'String'+-- | Parse a 'Text' that results in 'Either' a 'TomlError' -- containing the error message, or an internal representation -- of the document as a 'Table'. parseTomlDoc :: String -> Text -> Either TomlError Table parseTomlDoc = flip evalState mempty .* runParserT tomlDoc--checkTomlDoc :: String -> Text -> Either TomlError ()-checkTomlDoc = flip evalState mempty .* runParserT tomlCheck
src/Text/Toml/Parser.hs view
@@ -35,6 +35,7 @@ import           Text.Toml.Types  -- Imported last to fix redundancy warning+import           Debug.Trace import           Prelude                hiding (concat, takeWhile)  @@ -44,17 +45,6 @@ parseOnly :: Parser Toml a -> Text -> Either TomlError a parseOnly parser = flip evalState mempty . runParserT parser "noneSrc" --- | Checks a complete document formatted according to the TOML spec.-tomlCheck :: (TomlM m) => Parser m ()-tomlCheck = do-    skipBlanks-    table-    many namedSection-    -- Ensure the input is completely consumed-    eof-    -- make a set of named sections.-    pure ()- -- | Parses a complete document formatted according to the TOML spec. tomlDoc :: (TomlM m) => Parser m Table tomlDoc = do@@ -78,7 +68,8 @@ inlineTable :: (TomlM m) => Parser m Node inlineTable = do     pairs <- between (char '{') (char '}') (skipSpaces *> separatedValues <* skipSpaces)-    case maybeDupe (map fst pairs) of+    optional (char '\n')+    case maybeDupe (traceShowId $ map fst pairs) of       Just k  -> throwParser $ "Cannot redefine key " ++ unpack k       Nothing -> return $ VTable $ M.fromList pairs   where
test/Test.hs view
@@ -1,14 +1,17 @@ module Main where -import           Prelude               hiding (readFile)  -- needed for GHCi, see `.ghci`+import           Prelude               hiding (readFile) import           Test.Tasty            (defaultMain, testGroup)  import qualified BurntSushi+import           Test.Hspec import           Text.Toml.Parser.Spec+import           Text.TomlSpec   main :: IO () main = do+  hspec hspecTests   parserSpec <- tomlParserSpec   bsTests <- BurntSushi.tests 
test/Text/Toml/Parser/Spec.hs view
@@ -2,14 +2,13 @@  module Text.Toml.Parser.Spec where -import           Test.Tasty          (TestTree)-import           Test.Tasty.Hspec- import           Data.HashMap.Strict (fromList) import           Data.Time.Calendar  (Day (..)) import           Data.Time.Clock     (UTCTime (..)) import qualified Data.Vector         as V-+import           Test.Tasty          (TestTree)+import           Test.Tasty.Hspec+import           Text.Toml import           Text.Toml.Parser  @@ -18,7 +17,6 @@  mkVArray :: [Node] -> Node mkVArray  = VArray . V.fromList-  tomlParserSpec :: IO TestTree tomlParserSpec = testSpec "Parser Hspec suite" $ do
+ test/Text/TomlSpec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE OverloadedStrings #-}++module Text.TomlSpec (hspecTests) where++import           Data.List.NonEmpty+import qualified Data.Set           as Set+import           Data.Text          (Text)+import           Test.Hspec+import           Text.Megaparsec+import           Text.Toml++hspecTests :: Spec+hspecTests = do+  describe "parser" $ do+    it "should not parse re-assignment of key" $ do+      let actual = parseTomlDoc "noSrc" "q={k=42, k=43}"+      actual `shouldBe` Left (FancyError ((SourcePos "noSrc" (mkPos 1) (mkPos 15)) :| []) (Set.fromList [(ErrorFail "Cannot redefine key k")]))