Skip to content

Commit

Permalink
fix it?
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbrice committed Jan 4, 2024
1 parent d669f8a commit 8dcbf38
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,12 @@ jobs:
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_string_variants}" >> cabal.project
echo "package string-variants" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
echo "tests: True" >> cabal.project
echo "allow-newer:" >> cabal.project
echo " refined:aeson" >> cabal.project
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(string-variants)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
Expand Down
16 changes: 7 additions & 9 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ extra-source-files:

license: MIT

tested-with: ==9.2.8 || ==9.4.8 || ==9.6.3
tested-with: GHC ==9.2.8 || ==9.4.8 || ==9.6.3
# FIXME(jadel): maybe instances should be in a separate package but whatever
dependencies:
- aeson >= 2.0.0.0
- base >= 4.16 && <5
- bytestring
- mono-traversable
- QuickCheck
- string-conversions
- template-haskell
- refinery
- refined
- text

library:
source-dirs: src
dependencies:
- QuickCheck
- bytestring
- mono-traversable
- refined
- string-conversions

# Test suite
tests:
Expand All @@ -44,9 +44,7 @@ tests:
- HUnit
- hedgehog
- hspec
- hspec-core
- hspec-hedgehog
- hspec-expectations
- string-variants
build-tools:
- hspec-discover
Expand Down
13 changes: 2 additions & 11 deletions string-variants.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.2.
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

Expand All @@ -16,7 +16,7 @@ license: MIT
license-file: LICENSE
build-type: Simple
tested-with:
GHC ==9.4.8 || ==9.6.3
GHC ==9.2.8 || ==9.4.8 || ==9.6.3
extra-source-files:
CHANGELOG.md

Expand Down Expand Up @@ -81,7 +81,6 @@ library
, bytestring
, mono-traversable
, refined
, refinery
, string-conversions
, template-haskell
, text
Expand Down Expand Up @@ -139,19 +138,11 @@ test-suite test
hspec-discover:hspec-discover
build-depends:
HUnit
, QuickCheck
, aeson >=2.0.0.0
, base >=4.16 && <5
, bytestring
, hedgehog
, hspec
, hspec-core
, hspec-expectations
, hspec-hedgehog
, mono-traversable
, refined
, refinery
, string-conversions
, string-variants
, template-haskell
, text
Expand Down
21 changes: 8 additions & 13 deletions test/Specs/JsonEncodingSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

module Specs.JsonEncodingSpec (spec) where

import Prelude
import Test.Hspec

#if MIN_VERSION_aeson(2,2,0)
import Data.Aeson
import Data.StringVariants.NonEmptyText
import Data.StringVariants.NonEmptyText.Internal
import Data.StringVariants.NullableNonEmptyText
import GHC.Generics
#endif
import Prelude
import Test.Hspec

data Person = Person {name :: NonEmptyText 6, catchphrase :: NullableNonEmptyText 15}
deriving stock (Eq, Generic, Show)
deriving anyclass (FromJSON, ToJSON)

spec :: Spec
#if MIN_VERSION_aeson(2,2,0)
spec = describe "FromJSON instances" $ do
describe "NonEmptyText" $ do
it "rejects strings that are too long" $
Expand All @@ -40,6 +40,7 @@ spec = describe "FromJSON instances" $ do
it "rejects strings that are too long" $
assertParseFailure $
object ["name" .= String "Daniel", "catchphrase" .= replicate 16 'a']
#if MIN_VERSION_aeson(2,2,0)
it "accepts missing properties" $
object ["name" .= String "Daniel"]
`shouldParseAs`
Expand All @@ -48,6 +49,7 @@ spec = describe "FromJSON instances" $ do
object ["name" .= String "Daniel", "catchphrase" .= Null]
`shouldParseAs`
Person (NonEmptyText "Daniel") (NullableNonEmptyText Nothing)
#endif
it "accepts empty strings" $
object ["name" .= String "Daniel", "catchphrase" .= String ""]
`shouldParseAs`
Expand All @@ -68,10 +70,3 @@ spec = describe "FromJSON instances" $ do
shouldParseAs :: HasCallStack => Value -> Person -> IO ()
shouldParseAs val person =
decode (encode val) `shouldBe` Just person

data Person = Person {name :: NonEmptyText 6, catchphrase :: NullableNonEmptyText 15}
deriving stock (Eq, Generic, Show)
deriving anyclass (FromJSON, ToJSON)
#else
spec = pure ()
#endif

0 comments on commit 8dcbf38

Please sign in to comment.