microlens-aeson 2.1.1 → 2.1.1.1
raw patch · 7 files changed
+96/−155 lines, 7 filesdep +microlens-aesondep +tastydep +tasty-hunitdep −directorydep −doctestdep −filepathdep ~aesondep ~basedep ~bytestringsetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: microlens-aeson, tasty, tasty-hunit
Dependencies removed: directory, doctest, filepath, generic-deriving, semigroups, simple-reflect
Dependency ranges changed: aeson, base, bytestring, microlens, text, unordered-containers, vector
API changes (from Hackage documentation)
- Lens.Micro.Aeson: _Number :: AsNumber t => Traversal' t Scientific
+ Lens.Micro.Aeson: _Number :: (AsNumber t, AsPrimitive t) => Traversal' t Scientific
- Lens.Micro.Aeson: _Primitive :: AsPrimitive t => Traversal' t Primitive
+ Lens.Micro.Aeson: _Primitive :: (AsPrimitive t, AsValue t) => Traversal' t Primitive
Files
- .travis.yml +6/−3
- README.md +4/−0
- Setup.hs +2/−0
- Setup.lhs +0/−55
- microlens-aeson.cabal +20/−24
- test/Test.hs +64/−0
- tests/doctests.hsc +0/−73
.travis.yml view
@@ -13,8 +13,7 @@ # The different configurations we want to test. You could also do things like # change flags or use --stack-yaml to point to a different file. env:-- ARGS="--resolver lts-5.2"-- ARGS="--resolver nightly-2015-12-16"+- ARGS="--resolver nightly-2016-08-01" before_install: # Download and unpack the stack executable@@ -25,7 +24,11 @@ # This line does all of the work: installs GHC if necessary, build the library, # executables, and test suites, and runs the test suites. --no-terminal works # around some quirks in Travis's terminal implementation.-script: stack $ARGS --no-terminal --install-ghc test+script: stack $ARGS --no-terminal --install-ghc test --coverage++after_script:+ - travis_retry curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.4.0/shc-linux-x64-8.0.1.tar.bz2 | tar -xj+ - ./shc microlens-aeson microlens-aeson-test # Caching so the next build will be fast too. cache:
README.md view
@@ -2,6 +2,10 @@ =============== [](https://travis-ci.org/fosskers/microlens-aeson)+[](https://coveralls.io/github/fosskers/microlens-aeson?branch=master)+[](https://hackage.haskell.org/package/microlens-aeson)+[](http://stackage.org/nightly/package/microlens-aeson)+[](http://stackage.org/lts/package/microlens-aeson) `microlens-aeson` provides Traversals for the [Aeson](http://hackage.haskell.org/package/aeson) library's `Value` type,
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
− Setup.lhs
@@ -1,55 +0,0 @@-#!/usr/bin/runhaskell-\begin{code}-{-# OPTIONS_GHC -Wall #-}-module Main (main) where--import Data.List ( nub )-import Data.Version ( showVersion )-import Distribution.Package ( PackageName(PackageName), Package, PackageId, InstalledPackageId, packageVersion, packageName )-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )-import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )-import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose, copyFiles )-import Distribution.Simple.BuildPaths ( autogenModulesDir )-import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref))-import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )-import Distribution.Text ( display )-import Distribution.Verbosity ( Verbosity, normal )-import System.FilePath ( (</>) )--main :: IO ()-main = defaultMainWithHooks simpleUserHooks- { buildHook = \pkg lbi hooks flags -> do- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi- buildHook simpleUserHooks pkg lbi hooks flags- , postHaddock = \args flags pkg lbi -> do- copyFiles normal (haddockOutputDir flags pkg) []- postHaddock simpleUserHooks args flags pkg lbi- }--haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath-haddockOutputDir flags pkg = destDir where- baseDir = case haddockDistPref flags of- NoFlag -> "."- Flag x -> x- destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)--generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()-generateBuildModule verbosity pkg lbi = do- let dir = autogenModulesDir lbi- createDirectoryIfMissingVerbose verbosity True dir- withLibLBI pkg lbi $ \_ libcfg -> do- withTestLBI pkg lbi $ \suite suitecfg -> do- rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines- [ "module Build_" ++ testName suite ++ " where"- , "deps :: [String]"- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))- ]- where- formatdeps = map (formatone . snd)- formatone p = case packageName p of- PackageName n -> n ++ "-" ++ showVersion (packageVersion p)--testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]-testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys--\end{code}
microlens-aeson.cabal view
@@ -1,6 +1,6 @@ name: microlens-aeson category: Numeric-version: 2.1.1+version: 2.1.1.1 license: MIT cabal-version: >= 1.8 license-file: LICENSE@@ -13,7 +13,7 @@ Copyright (C) 2012 Paul Wilson Copyright (C) 2013 Edward A. Kmett Copyright (C) 2015 Colin Woodbury-build-type: Custom+build-type: Simple synopsis: Law-abiding lenses for Aeson, using microlens. description: Law-abiding lenses for Aeson, using microlens. @@ -31,14 +31,9 @@ type: git location: git://github.com/fosskers/microlens-aeson.git --- You can disable the doctests test suite with -f-test-doctests-flag test-doctests- default: True- manual: True- library build-depends:- aeson >= 0.7.0.5 && < 0.12+ aeson >= 0.7.0.5 && < 1.1 , attoparsec >= 0.10 && < 0.14 , base >= 4.5 && < 5 , bytestring >= 0.9 && < 0.11@@ -57,20 +52,21 @@ ghc-options: -Wall -fwarn-tabs -O2 hs-source-dirs: src -test-suite doctests- type: exitcode-stdio-1.0- main-is: doctests.hs- ghc-options: -Wall -threaded- hs-source-dirs: tests+test-suite microlens-aeson-test+ type: exitcode-stdio-1.0 - if !flag(test-doctests)- buildable: False- else- build-depends:- base- , directory >= 1.0- , doctest >= 0.9.1- , filepath- , generic-deriving- , semigroups >= 0.9- , simple-reflect >= 0.3.1+ build-depends: base >=4.9 && <4.10+ , tasty >= 0.10.1.2+ , tasty-hunit >= 0.9.2+ , text >=1.2 && <1.3+ , microlens-aeson+ , microlens+ , bytestring+ , vector+ , aeson+ , unordered-containers++ hs-source-dirs: test+ main-is: Test.hs+ default-language: Haskell2010+ ghc-options: -Wall -threaded
+ test/Test.hs view
@@ -0,0 +1,64 @@+--{-# LANGUAGE OverloadedStrings #-}++module Main where++import Data.Aeson+import Data.ByteString.Char8 as Strict.Char8+import Data.ByteString.Lazy.Char8 as Lazy+import qualified Data.Vector as Vector+import Lens.Micro+import Lens.Micro.Aeson+import Test.Tasty+import Test.Tasty.HUnit+import qualified Data.HashMap.Strict as HMS+import qualified Data.Text as T++---++main :: IO ()+main = defaultMain suite++suite :: TestTree+suite = testGroup "Unit Tests"+ [ testGroup "Scientific Traversals"+ [ testCase "" $ ("[1, \"x\"]" ^? nth 0 . _Number) @?= Just 1.0+ , testCase "" $ ("[1, \"x\"]" ^? nth 1 . _Number) @?= Nothing+ , testCase "" $ ("[10.2]" ^? nth 0 . _Double) @?= Just 10.2+ , testCase "" $ ("[10]" ^? nth 0 . _Integer) @?= Just 10+ , testCase "" $ ("[10.5]" ^? nth 0 . _Integer) @?= Just 10+ , testCase "" $ ("42" ^? _Integer) @?= Just 42+ ]+ , testGroup "Conversion Traversals"+ [ testCase "" $ ("[10]" ^? nth 0 . _Integral) @?= Just 10+ , testCase "" $ ("[10.5]" ^? nth 0 . _Integral) @?= Just 10+ ]+ , testGroup "Nulls and Primitives"+ [ testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 0 . _Primitive) @?= Just (NumberPrim 1.0)+ , testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 1 . _Primitive) @?= Just (StringPrim $ T.pack "x")+ , testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 2 . _Primitive) @?= Just NullPrim+ , testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 3 . _Primitive) @?= Just (BoolPrim True)+ , testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 4 . _Primitive) @?= Just (BoolPrim False)+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": true}" ^? key (T.pack "a") . _String) @?= Just (T.pack "xyz")+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": true}" ^? key (T.pack "b") . _String) @?= Nothing+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": true}" ^? key (T.pack "b") . _Bool) @?= Just True+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": true}" ^? key (T.pack "a") . _Bool) @?= Nothing+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": null}" ^? key (T.pack "b") . _Null) @?= Just ()+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": null}" ^? key (T.pack "a") . _Null) @?= Nothing+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": null}" ^? key (T.pack "a") . nonNull) @?= Just (String $ T.pack "xyz")+ , testCase "" $ ("{\"a\": {}, \"b\": null}" ^? key (T.pack "a") . nonNull) @?= Just (Object (HMS.fromList []))+ , testCase "" $ ("{\"a\": \"xyz\", \"b\": null}" ^? key (T.pack "b") . nonNull) @?= Nothing+ ]+ , testGroup "Non-primitive Traversals"+ [ testCase "" $ ("{\"a\": {}, \"b\": null}" ^? key (T.pack "a") . _Object) @?= Just (HMS.fromList [])+ , testCase "" $ ("{\"a\": {}, \"b\": null}" ^? key (T.pack "b") . _Object) @?= Nothing+ , testCase "" $ ("{\"a\": 100, \"b\": 200}" ^? key (T.pack "a")) @?= Just (Number 100.0)+ , testCase "" $ ("[1,2,3]" ^? key (T.pack "a")) @?= Nothing+ , testCase "" $ ("{\"a\": 4, \"b\": 7}" ^.. members) @?= [Number 4.0,Number 7.0]+ , testCase "" $ ("{\"a\": 4, \"b\": 7}" & members . _Number %~ (* 10)) @?= "{\"a\":40,\"b\":70}"+ , testCase "" $ ("[1,2,3]" ^? nth 1) @?= Just (Number 2.0)+ , testCase "" $ ("{\"a\": 100, \"b\": 200}" ^? nth 1) @?= Nothing+ , testCase "" $ ("[1,2,3]" & nth 1 .~ Number 20) @?= "[1,20,3]"+ , testCase "" $ ("[1,2,3]" ^.. values) @?= [Number 1.0,Number 2.0,Number 3.0]+ , testCase "" $ ("[1,2,3]" & values . _Number %~ (* 10)) @?= "[10,20,30]"+ ]+ ]
− tests/doctests.hsc
@@ -1,73 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE ForeignFunctionInterface #-}--------------------------------------------------------------------------------- |--- Module : Main (doctests)--- Copyright : (C) 2012-13 Edward Kmett--- License : BSD-style (see the file LICENSE)--- Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : provisional--- Portability : portable------ This module provides doctests for a project based on the actual versions--- of the packages it was built with. It requires a corresponding Setup.lhs--- to be added to the project-------------------------------------------------------------------------------module Main where--import Build_doctests (deps)-import Control.Applicative-import Control.Monad-import Data.List-import System.Directory-import System.FilePath-import Test.DocTest--##if defined(mingw32_HOST_OS)-##if defined(i386_HOST_ARCH)-##define USE_CP-import Control.Applicative-import Control.Exception-import Foreign.C.Types-foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool-foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt-##elif defined(x86_64_HOST_ARCH)-##define USE_CP-import Control.Applicative-import Control.Exception-import Foreign.C.Types-foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool-foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt-##endif-##endif---- | Run in a modified codepage where we can print UTF-8 values on Windows.-withUnicode :: IO a -> IO a-##ifdef USE_CP-withUnicode m = do- cp <- c_GetConsoleCP- (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp-##else-withUnicode m = m-##endif--main :: IO ()-main = withUnicode $ getSources >>= \sources -> doctest $- "-isrc"- : "-idist/build/autogen"- : "-optP-include"- : "-optPdist/build/autogen/cabal_macros.h"- : "-hide-all-packages"- : map ("-package="++) deps ++ sources--getSources :: IO [FilePath]-getSources = filter (isSuffixOf ".hs") <$> go "src"- where- go dir = do- (dirs, files) <- getFilesAndDirectories dir- (files ++) . concat <$> mapM go dirs--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do- c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir- (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c