mirror of
https://github.com/NorfairKing/autodocodec.git
synced 2025-01-08 11:30:27 +03:00
Started on autodocodec-yaml
This commit is contained in:
parent
cc910db093
commit
949665a190
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2021 Tom Sydney Kerckhove
|
||||
Copyright (c) 2021 Tom Sydney Kerckhove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
2
autodocodec-yaml/.gitignore
vendored
Normal file
2
autodocodec-yaml/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.stack-work/
|
||||
*~
|
21
autodocodec-yaml/LICENSE
Normal file
21
autodocodec-yaml/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Tom Sydney Kerckhove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
65
autodocodec-yaml/autodocodec-yaml.cabal
Normal file
65
autodocodec-yaml/autodocodec-yaml.cabal
Normal file
@ -0,0 +1,65 @@
|
||||
cabal-version: 1.12
|
||||
|
||||
-- This file has been generated from package.yaml by hpack version 0.34.4.
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: autodocodec-yaml
|
||||
version: 0.0.0.0
|
||||
synopsis: Self-documenting encoder and decoder for yaml
|
||||
homepage: https://github.com/NorfairKing/autodocodec#readme
|
||||
bug-reports: https://github.com/NorfairKing/autodocodec/issues
|
||||
author: Tom Sydney Kerckhove
|
||||
maintainer: syd@cs-syd.eu
|
||||
copyright: 2021 Tom Sydney Kerckhove
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
build-type: Simple
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://github.com/NorfairKing/autodocodec
|
||||
|
||||
library
|
||||
exposed-modules:
|
||||
Autodocodec.Yaml
|
||||
Autodocodec.Yaml.Document
|
||||
other-modules:
|
||||
Paths_autodocodec_yaml
|
||||
hs-source-dirs:
|
||||
src
|
||||
build-depends:
|
||||
autodocodec
|
||||
, base >=4.7 && <5
|
||||
, safe-coloured-text
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite autodocodec-yaml-test
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
other-modules:
|
||||
Autodocodec.Yaml.DocumentSpec
|
||||
Paths_autodocodec_yaml
|
||||
hs-source-dirs:
|
||||
test/
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
build-tool-depends:
|
||||
sydtest-discover:sydtest-discover
|
||||
build-depends:
|
||||
aeson
|
||||
, autodocodec
|
||||
, autodocodec-aeson
|
||||
, autodocodec-yaml
|
||||
, base >=4.7 && <5
|
||||
, bytestring
|
||||
, genvalidity
|
||||
, genvalidity-scientific
|
||||
, genvalidity-sydtest
|
||||
, genvalidity-text
|
||||
, safe-coloured-text
|
||||
, scientific
|
||||
, sydtest
|
||||
, sydtest-aeson
|
||||
, text
|
||||
default-language: Haskell2010
|
45
autodocodec-yaml/package.yaml
Normal file
45
autodocodec-yaml/package.yaml
Normal file
@ -0,0 +1,45 @@
|
||||
name: autodocodec-yaml
|
||||
version: 0.0.0.0
|
||||
github: "NorfairKing/autodocodec"
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: "Tom Sydney Kerckhove"
|
||||
maintainer: "syd@cs-syd.eu"
|
||||
copyright: "2021 Tom Sydney Kerckhove"
|
||||
synopsis: Self-documenting encoder and decoder for yaml
|
||||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
dependencies:
|
||||
- autodocodec
|
||||
- safe-coloured-text
|
||||
- yaml
|
||||
|
||||
tests:
|
||||
autodocodec-yaml-test:
|
||||
main: Spec.hs
|
||||
source-dirs: test/
|
||||
build-tools: sydtest-discover
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
- -Wall
|
||||
dependencies:
|
||||
- aeson
|
||||
- autodocodec
|
||||
- autodocodec-aeson
|
||||
- autodocodec-yaml
|
||||
- bytestring
|
||||
- genvalidity
|
||||
- genvalidity-scientific
|
||||
- genvalidity-sydtest
|
||||
- genvalidity-text
|
||||
- safe-coloured-text
|
||||
- scientific
|
||||
- sydtest
|
||||
- sydtest-aeson
|
||||
- text
|
7
autodocodec-yaml/src/Autodocodec/Yaml.hs
Normal file
7
autodocodec-yaml/src/Autodocodec/Yaml.hs
Normal file
@ -0,0 +1,7 @@
|
||||
module Autodocodec.Yaml
|
||||
( -- * To makes sure we definitely export everything.
|
||||
module Autodocodec.Yaml.Document,
|
||||
)
|
||||
where
|
||||
|
||||
import Autodocodec.Yaml.Document
|
14
autodocodec-yaml/src/Autodocodec/Yaml/Document.hs
Normal file
14
autodocodec-yaml/src/Autodocodec/Yaml/Document.hs
Normal file
@ -0,0 +1,14 @@
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
|
||||
module Autodocodec.Yaml.Document where
|
||||
|
||||
import Autodocodec
|
||||
import Text.Colour
|
||||
|
||||
schemaChunksViaCodec :: forall a. HasCodec a => [Chunk]
|
||||
schemaChunksViaCodec = schemaChunksVia (codec @a)
|
||||
|
||||
schemaChunksVia :: Codec input output -> [Chunk]
|
||||
schemaChunksVia _ = []
|
71
autodocodec-yaml/test/Autodocodec/Yaml/DocumentSpec.hs
Normal file
71
autodocodec-yaml/test/Autodocodec/Yaml/DocumentSpec.hs
Normal file
@ -0,0 +1,71 @@
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
|
||||
module Autodocodec.Yaml.DocumentSpec (spec) where
|
||||
|
||||
import Autodocodec
|
||||
import Autodocodec.Yaml
|
||||
import Data.Data
|
||||
import Data.GenValidity
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.Scientific
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
import Data.Word
|
||||
import GHC.Generics (Generic)
|
||||
import Test.Syd
|
||||
import Test.Syd.Validity.Utils
|
||||
import Text.Colour
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
yamlSchemaSpec @Bool "bool"
|
||||
yamlSchemaSpec @Char "char"
|
||||
yamlSchemaSpec @Text "text"
|
||||
yamlSchemaSpec @LT.Text "lazy-text"
|
||||
yamlSchemaSpec @String "string"
|
||||
yamlSchemaSpec @Scientific "scientific"
|
||||
yamlSchemaSpec @Int "int"
|
||||
yamlSchemaSpec @Int8 "int8"
|
||||
yamlSchemaSpec @Int16 "int16"
|
||||
yamlSchemaSpec @Int32 "int32"
|
||||
yamlSchemaSpec @Int64 "int64"
|
||||
yamlSchemaSpec @Word "word"
|
||||
yamlSchemaSpec @Word8 "word8"
|
||||
yamlSchemaSpec @Word16 "word16"
|
||||
yamlSchemaSpec @Word32 "word32"
|
||||
yamlSchemaSpec @Word64 "word64"
|
||||
yamlSchemaSpec @(Maybe Text) "maybe-text"
|
||||
yamlSchemaSpec @(Either Bool Text) "either-bool-text"
|
||||
yamlSchemaSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
yamlSchemaSpec @[Text] "list-text"
|
||||
yamlSchemaSpec @Example "example"
|
||||
|
||||
data Example = Example
|
||||
{ exampleText :: !Text,
|
||||
exampleBool :: !Bool
|
||||
}
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
instance Validity Example
|
||||
|
||||
instance GenValid Example where
|
||||
genValid = genValidStructurally
|
||||
shrinkValid = shrinkValidStructurally
|
||||
|
||||
instance HasCodec Example where
|
||||
codec =
|
||||
object $
|
||||
Example
|
||||
<$> field "text" .= exampleText
|
||||
<*> field "bool" .= exampleBool
|
||||
|
||||
yamlSchemaSpec :: forall a. (Show a, Eq a, Typeable a, GenValid a, HasCodec a) => FilePath -> Spec
|
||||
yamlSchemaSpec filePath = do
|
||||
it ("outputs the same schema as before for " <> nameOf @a) $
|
||||
pureGoldenByteStringFile ("test_resources/schema/" <> filePath <> ".json") (renderChunksBS With24BitColours $ schemaChunksViaCodec @a)
|
1
autodocodec-yaml/test/Spec.hs
Normal file
1
autodocodec-yaml/test/Spec.hs
Normal file
@ -0,0 +1 @@
|
||||
{-# OPTIONS_GHC -F -pgmF sydtest-discover #-}
|
0
autodocodec-yaml/test_resources/schema/bool.json
Normal file
0
autodocodec-yaml/test_resources/schema/bool.json
Normal file
0
autodocodec-yaml/test_resources/schema/char.json
Normal file
0
autodocodec-yaml/test_resources/schema/char.json
Normal file
0
autodocodec-yaml/test_resources/schema/example.json
Normal file
0
autodocodec-yaml/test_resources/schema/example.json
Normal file
0
autodocodec-yaml/test_resources/schema/int.json
Normal file
0
autodocodec-yaml/test_resources/schema/int.json
Normal file
0
autodocodec-yaml/test_resources/schema/int16.json
Normal file
0
autodocodec-yaml/test_resources/schema/int16.json
Normal file
0
autodocodec-yaml/test_resources/schema/int32.json
Normal file
0
autodocodec-yaml/test_resources/schema/int32.json
Normal file
0
autodocodec-yaml/test_resources/schema/int64.json
Normal file
0
autodocodec-yaml/test_resources/schema/int64.json
Normal file
0
autodocodec-yaml/test_resources/schema/int8.json
Normal file
0
autodocodec-yaml/test_resources/schema/int8.json
Normal file
0
autodocodec-yaml/test_resources/schema/string.json
Normal file
0
autodocodec-yaml/test_resources/schema/string.json
Normal file
0
autodocodec-yaml/test_resources/schema/text.json
Normal file
0
autodocodec-yaml/test_resources/schema/text.json
Normal file
0
autodocodec-yaml/test_resources/schema/word.json
Normal file
0
autodocodec-yaml/test_resources/schema/word.json
Normal file
0
autodocodec-yaml/test_resources/schema/word16.json
Normal file
0
autodocodec-yaml/test_resources/schema/word16.json
Normal file
0
autodocodec-yaml/test_resources/schema/word32.json
Normal file
0
autodocodec-yaml/test_resources/schema/word32.json
Normal file
0
autodocodec-yaml/test_resources/schema/word64.json
Normal file
0
autodocodec-yaml/test_resources/schema/word64.json
Normal file
0
autodocodec-yaml/test_resources/schema/word8.json
Normal file
0
autodocodec-yaml/test_resources/schema/word8.json
Normal file
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2021 Tom Sydney Kerckhove
|
||||
Copyright (c) 2021 Tom Sydney Kerckhove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -2,7 +2,7 @@ resolver: nightly-2021-05-10
|
||||
packages:
|
||||
- autodocodec
|
||||
- autodocodec-aeson
|
||||
# - autodocodec-yaml
|
||||
- autodocodec-yaml
|
||||
extra-deps:
|
||||
|
||||
- github: NorfairKing/validity
|
||||
|
Loading…
Reference in New Issue
Block a user