Skip to content
This repository was archived by the owner on May 2, 2020. It is now read-only.

Commit d84d693

Browse files
committed
Fix maxLength bug
1 parent 5fef2d6 commit d84d693

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

hjsonschema.cabal

+45
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,51 @@ library
8181
, text >= 1.1
8282
, vector >= 0.10
8383

84+
test-suite spec
85+
hs-source-dirs:
86+
test
87+
src
88+
main-is: Spec.hs
89+
type: exitcode-stdio-1.0
90+
default-language: Haskell2010
91+
ghc-options:
92+
-Wall
93+
default-extensions:
94+
DeriveGeneric
95+
NoImplicitPrelude
96+
OverloadedStrings
97+
ScopedTypeVariables
98+
other-modules:
99+
Import
100+
JSONSchema.Validator.Draft4.String
101+
102+
JSONSchema.Validator.Draft4.StringSpec
103+
build-depends:
104+
base >= 4.7 && < 5
105+
-- 0.11 is for `.:!`:
106+
, aeson >= 0.11
107+
, bytestring >= 0.10
108+
, containers >= 0.5
109+
, file-embed >= 0.0.8
110+
, filepath >= 1.3
111+
, hashable >= 1.2
112+
, hjsonpointer >= 1.1
113+
-- 0.4.30 is for parseUrlThrow:
114+
, http-client >= 0.4.30
115+
, http-client-tls >= 0.3
116+
, http-types >= 0.8
117+
, pcre-heavy >= 1.0
118+
, profunctors >= 5.0
119+
, protolude >= 0.1.10
120+
, QuickCheck >= 2.8
121+
, safe-exceptions >= 0.1.6
122+
, scientific >= 0.3
123+
, unordered-containers >= 0.2
124+
, text >= 1.1
125+
, vector >= 0.10
126+
127+
, hspec >= 2.2
128+
84129
test-suite local
85130
hs-source-dirs:
86131
test

src/JSONSchema/Validator/Draft4/String.hs

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ data MaxLengthInvalid
2222
= MaxLengthInvalid MaxLength Text
2323
deriving (Eq, Show)
2424

25-
-- | The spec requires @"maxLength"@ to be non-negative.
2625
maxLengthVal :: MaxLength -> Text -> Maybe MaxLengthInvalid
2726
maxLengthVal a@(MaxLength n) x
28-
| n <= 0 = Nothing
2927
| T.length x > n = Just (MaxLengthInvalid a x)
3028
| otherwise = Nothing
3129

@@ -45,10 +43,8 @@ data MinLengthInvalid
4543
= MinLengthInvalid MinLength Text
4644
deriving (Eq, Show)
4745

48-
-- | The spec requires @"minLength"@ to be non-negative.
4946
minLengthVal :: MinLength -> Text -> Maybe MinLengthInvalid
5047
minLengthVal a@(MinLength n) x
51-
| n <= 0 = Nothing
5248
| T.length x < n = Just (MinLengthInvalid a x)
5349
| otherwise = Nothing
5450

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module JSONSchema.Validator.Draft4.StringSpec (spec) where
2+
3+
import Protolude
4+
5+
import Test.Hspec
6+
7+
import JSONSchema.Validator.Draft4.String
8+
9+
spec :: Spec
10+
spec = do
11+
describe "maxLengthVal" $ do
12+
context "with 0" $ do
13+
it "accepts the empty string" $ do
14+
maxLengthVal (MaxLength 0) "" `shouldBe` Nothing
15+
16+
it "rejects other strings" $ do
17+
maxLengthVal (MaxLength 0) "foo" `shouldBe` Just (MaxLengthInvalid (MaxLength 0) "foo")

test/Spec.hs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{-# OPTIONS_GHC -fforce-recomp -F -pgmF hspec-discover #-}

0 commit comments

Comments
 (0)