Skip to content

Commit 591ff8c

Browse files
Deprecate KDL.text => KDL.string (#25)
1 parent f6a6f64 commit 591ff8c

5 files changed

Lines changed: 64 additions & 58 deletions

File tree

src/KDL/Decoder/Arrow.hs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module KDL.Decoder.Arrow (
7171
ValueDecodeArrow,
7272
DecodeValue (..),
7373
any,
74+
string,
7475
text,
7576
number,
7677
bool,
@@ -424,7 +425,7 @@ argsAt name = withDecodeValue $ argsAtWith' name
424425
-- email "a@example.com" "b@example.com"
425426
-- """
426427
-- decoder = KDL.document $ proc () -> do
427-
-- KDL.argsAtWith "email" KDL.text -< ()
428+
-- KDL.argsAtWith "email" KDL.string -< ()
428429
-- KDL.decodeWith decoder config == Right ["a@example.com", "b@example.com"]
429430
-- @
430431
argsAtWith :: forall a b. (Typeable b) => Text -> ValueDecodeArrow a b -> NodeListDecodeArrow a [b]
@@ -470,7 +471,7 @@ dashChildrenAt name = withDecodeValue $ dashChildrenAtWith' name
470471
-- }
471472
-- """
472473
-- decoder = KDL.document $ proc () -> do
473-
-- KDL.dashChildrenAtWith "attendees" $ KDL.text -< ()
474+
-- KDL.dashChildrenAtWith "attendees" $ KDL.string -< ()
474475
-- KDL.decodeWith decoder config == Right [\"Alice", \"Bob"]
475476
-- @
476477
dashChildrenAtWith :: forall a b. (Typeable b) => Text -> ValueDecodeArrow a b -> NodeListDecodeArrow a [b]
@@ -665,7 +666,7 @@ arg = withDecodeValue argWith'
665666
-- decoder = KDL.document $ proc () -> do
666667
-- KDL.nodeWith "person" $ decodePerson -< ()
667668
-- decodePerson = proc () -> do
668-
-- name \<- KDL.argWith $ Text.toUpper \<$> KDL.text -< ()
669+
-- name \<- KDL.argWith $ Text.toUpper \<$> KDL.string -< ()
669670
-- vals \<- KDL.many $ KDL.argWith $ show \<$> KDL.valueDecoder @Int -< ()
670671
-- returnA -< (name, vals)
671672
-- KDL.decodeWith decoder config == Right (\"ALICE", ["1", "2", "3"])
@@ -910,11 +911,11 @@ instance DecodeValue Value where
910911
instance DecodeValue ValueData where
911912
valueDecoder = (.data_) <$> any
912913
instance DecodeValue Text where
913-
validValueTypeAnns _ = ["text"]
914-
valueDecoder = text
914+
validValueTypeAnns _ = ["string"]
915+
valueDecoder = string
915916
instance DecodeValue String where
916917
validValueTypeAnns _ = ["string"]
917-
valueDecoder = Text.unpack <$> text
918+
valueDecoder = Text.unpack <$> string
918919
instance DecodeValue Bool where
919920
validValueTypeAnns _ = ["bool", "boolean"]
920921
valueDecoder = bool
@@ -1018,11 +1019,16 @@ valueDataDecoderPrim schema f = DecodeArrow schema $ \_ -> Trans.lift . f =<< St
10181019
any :: DecodeArrow Value a Value
10191020
any = valueDataDecoderPrim (SchemaOr $ map SchemaOne [minBound .. maxBound]) pure
10201021

1021-
-- | Decode a KDL text value.
1022-
text :: DecodeArrow Value a Text
1023-
text = valueDataDecoderPrim (SchemaOne TextSchema) $ \case
1022+
-- | Decode a KDL string value.
1023+
string :: DecodeArrow Value a Text
1024+
string = valueDataDecoderPrim (SchemaOne TextSchema) $ \case
10241025
Value{data_ = String s} -> pure s
1025-
v -> decodeThrow DecodeError_ValueDecodeFail{expectedType = "text", value = v}
1026+
v -> decodeThrow DecodeError_ValueDecodeFail{expectedType = "string", value = v}
1027+
1028+
-- | Deprecated in favor of 'string'.
1029+
text :: DecodeArrow Value a Text
1030+
text = string
1031+
{-# DEPRECATED text "Use KDL.string instead" #-}
10261032

10271033
-- | Decode a KDL number value.
10281034
number :: DecodeArrow Value a Scientific

test/KDL/ApplicativeSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ spec = do
8585
KDL.SchemaOne . KDL.NodeArg $
8686
KDL.TypedValueSchema
8787
{ typeHint = typeRep $ Proxy @Text
88-
, validTypeAnns = ["text"]
88+
, validTypeAnns = ["string"]
8989
, dataSchema = KDL.SchemaOne KDL.TextSchema
9090
}
9191
}

test/KDL/Decoder/ArrowSpec.hs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ apiSpec = do
121121
KDL.decodeWith decoder config
122122
`shouldSatisfy` decodeErrorMsg
123123
[ "At: foo #0 > arg #0"
124-
, " Expected text, got: 1.0"
124+
, " Expected string, got: 1.0"
125125
]
126126

127127
-- Most behaviors tested with `nodeWith`
@@ -297,7 +297,7 @@ apiSpec = do
297297
KDL.decodeWith decoder config
298298
`shouldSatisfy` decodeErrorMsg
299299
[ "At: foo #0 > arg #0"
300-
, " Expected text, got: 1"
300+
, " Expected string, got: 1"
301301
]
302302

303303
-- Most behaviors tested with `argAt`
@@ -319,7 +319,7 @@ apiSpec = do
319319
forM_ testCases $ \anns -> do
320320
let config = "foo (test)a"
321321
decoder = KDL.document $ proc () -> do
322-
KDL.argAtWith' "foo" anns KDL.text -< ()
322+
KDL.argAtWith' "foo" anns KDL.string -< ()
323323
KDL.decodeWith decoder config `shouldBe` Right "a"
324324

325325
it "decodes argument without an annotation" $ do
@@ -331,13 +331,13 @@ apiSpec = do
331331
forM_ testCases $ \anns -> do
332332
let config = "foo a"
333333
decoder = KDL.document $ proc () -> do
334-
KDL.argAtWith' "foo" anns KDL.text -< ()
334+
KDL.argAtWith' "foo" anns KDL.string -< ()
335335
KDL.decodeWith decoder config `shouldBe` Right "a"
336336

337337
it "fails when argument has unexpected annotation" $ do
338338
let config = "foo (test)a"
339339
decoder = KDL.document $ proc () -> do
340-
KDL.argAtWith' "foo" ["VAL"] KDL.text -< ()
340+
KDL.argAtWith' "foo" ["VAL"] KDL.string -< ()
341341
KDL.decodeWith decoder config
342342
`shouldSatisfy` decodeErrorMsg
343343
[ "At: foo #0 > arg #0"
@@ -392,7 +392,7 @@ apiSpec = do
392392
forM_ testCases $ \anns -> do
393393
let config = "foo (test)a (test)b"
394394
decoder = KDL.document $ proc () -> do
395-
KDL.argsAtWith' "foo" anns KDL.text -< ()
395+
KDL.argsAtWith' "foo" anns KDL.string -< ()
396396
KDL.decodeWith decoder config `shouldBe` Right ["a", "b"]
397397

398398
it "decodes arguments without an annotation" $ do
@@ -404,13 +404,13 @@ apiSpec = do
404404
forM_ testCases $ \anns -> do
405405
let config = "foo a b"
406406
decoder = KDL.document $ proc () -> do
407-
KDL.argsAtWith' "foo" anns KDL.text -< ()
407+
KDL.argsAtWith' "foo" anns KDL.string -< ()
408408
KDL.decodeWith decoder config `shouldBe` Right ["a", "b"]
409409

410410
it "fails when argument has unexpected annotation" $ do
411411
let config = "foo (VAL)a (test)b"
412412
decoder = KDL.document $ proc () -> do
413-
KDL.argsAtWith' "foo" ["VAL"] KDL.text -< ()
413+
KDL.argsAtWith' "foo" ["VAL"] KDL.string -< ()
414414
KDL.decodeWith decoder config
415415
`shouldSatisfy` decodeErrorMsg
416416
[ "At: foo #0 > arg #1"
@@ -485,7 +485,7 @@ apiSpec = do
485485
forM_ testCases $ \anns -> do
486486
let config = "foo { - (test)a; - (test)b; }"
487487
decoder = KDL.document $ proc () -> do
488-
KDL.dashChildrenAtWith' "foo" anns KDL.text -< ()
488+
KDL.dashChildrenAtWith' "foo" anns KDL.string -< ()
489489
KDL.decodeWith decoder config `shouldBe` Right ["a", "b"]
490490

491491
it "decodes dash children without an annotation" $ do
@@ -497,13 +497,13 @@ apiSpec = do
497497
forM_ testCases $ \anns -> do
498498
let config = "foo { - a; - b; }"
499499
decoder = KDL.document $ proc () -> do
500-
KDL.dashChildrenAtWith' "foo" anns KDL.text -< ()
500+
KDL.dashChildrenAtWith' "foo" anns KDL.string -< ()
501501
KDL.decodeWith decoder config `shouldBe` Right ["a", "b"]
502502

503503
it "fails when child has unexpected annotation" $ do
504504
let config = "foo { - (test)a; }"
505505
decoder = KDL.document $ proc () -> do
506-
KDL.dashChildrenAtWith' "foo" ["VAL"] KDL.text -< ()
506+
KDL.dashChildrenAtWith' "foo" ["VAL"] KDL.string -< ()
507507
KDL.decodeWith decoder config
508508
`shouldSatisfy` decodeErrorMsg
509509
[ "At: foo #0 > - #0 > arg #0"
@@ -631,7 +631,7 @@ apiSpec = do
631631
it "decodes an argument" $ do
632632
let config = "foo bar"
633633
decoder = proc () -> do
634-
KDL.argWith KDL.text -< ()
634+
KDL.argWith KDL.string -< ()
635635
decodeNode "foo" decoder config `shouldBe` Right "bar"
636636

637637
-- Most behaviors tested with `argWith`
@@ -645,7 +645,7 @@ apiSpec = do
645645
forM_ testCases $ \anns -> do
646646
let config = "foo (test)a"
647647
decoder = proc () -> do
648-
KDL.argWith' anns KDL.text -< ()
648+
KDL.argWith' anns KDL.string -< ()
649649
decodeNode "foo" decoder config `shouldBe` Right "a"
650650

651651
it "decodes argument without an annotation" $ do
@@ -657,13 +657,13 @@ apiSpec = do
657657
forM_ testCases $ \anns -> do
658658
let config = "foo a"
659659
decoder = proc () -> do
660-
KDL.argWith' anns KDL.text -< ()
660+
KDL.argWith' anns KDL.string -< ()
661661
decodeNode "foo" decoder config `shouldBe` Right "a"
662662

663663
it "fails when argument has unexpected annotation" $ do
664664
let config = "foo (test)a"
665665
decoder = proc () -> do
666-
KDL.argWith' ["VAL"] KDL.text -< ()
666+
KDL.argWith' ["VAL"] KDL.string -< ()
667667
decodeNode "foo" decoder config
668668
`shouldSatisfy` decodeErrorMsg
669669
[ "At: foo #0 > arg #0"
@@ -896,21 +896,21 @@ apiSpec = do
896896
KDL.decodeWith decoder config
897897
`shouldBe` Right [val $ Number 1, val $ String "asdf", val $ Bool True]
898898

899-
describe "text" $ do
900-
it "decodes text value" $ do
899+
describe "string" $ do
900+
it "decodes string value" $ do
901901
let config = "foo asdf"
902902
decoder = KDL.document $ proc () -> do
903-
KDL.argAtWith "foo" KDL.text -< ()
903+
KDL.argAtWith "foo" KDL.string -< ()
904904
KDL.decodeWith decoder config `shouldBe` Right "asdf"
905905

906-
it "fails when value is not text" $ do
906+
it "fails when value is not string" $ do
907907
let config = "foo 1"
908908
decoder = KDL.document $ proc () -> do
909-
KDL.argAtWith "foo" KDL.text -< ()
909+
KDL.argAtWith "foo" KDL.string -< ()
910910
KDL.decodeWith decoder config
911911
`shouldSatisfy` decodeErrorMsg
912912
[ "At: foo #0 > arg #0"
913-
, " Expected text, got: 1"
913+
, " Expected string, got: 1"
914914
]
915915

916916
describe "number" $ do
@@ -970,7 +970,7 @@ apiSpec = do
970970
let config = "foo 123 hello"
971971
decoder = KDL.document $ proc () -> do
972972
KDL.nodeWith "foo" . KDL.many . KDL.argWith $
973-
KDL.oneOf [Left <$> KDL.number, Right <$> KDL.text]
973+
KDL.oneOf [Left <$> KDL.number, Right <$> KDL.string]
974974
-<
975975
()
976976
KDL.decodeWith decoder config `shouldBe` Right [Left 123, Right "hello"]
@@ -1059,7 +1059,7 @@ schemaSpec = do
10591059
KDL.SchemaOne . KDL.NodeArg $
10601060
KDL.TypedValueSchema
10611061
{ typeHint = typeRep $ Proxy @Text
1062-
, validTypeAnns = ["text"]
1062+
, validTypeAnns = ["string"]
10631063
, dataSchema = KDL.SchemaOne KDL.TextSchema
10641064
}
10651065
}

0 commit comments

Comments
 (0)