2019-09-01 19:54:27 +02:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
module Xanthous.MessageSpec ( main, test ) where
|
|
|
|
|
|
|
|
import Test.Prelude
|
|
|
|
import Xanthous.Messages
|
|
|
|
import Data.Aeson
|
|
|
|
import Text.Mustache
|
|
|
|
import Control.Lens.Properties
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = defaultMain test
|
|
|
|
|
|
|
|
test :: TestTree
|
|
|
|
test = testGroup "Xanthous.Messages"
|
|
|
|
[ testGroup "Message"
|
|
|
|
[ testGroup "JSON decoding"
|
|
|
|
[ testCase "Single"
|
|
|
|
$ decode "\"Test Single Template\""
|
|
|
|
@?= Just (Single
|
|
|
|
$ compileMustacheText "template" "Test Single Template"
|
|
|
|
^?! _Right)
|
|
|
|
, testCase "Choice"
|
|
|
|
$ decode "[\"Choice 1\", \"Choice 2\"]"
|
|
|
|
@?= Just
|
|
|
|
(Choice
|
|
|
|
[ compileMustacheText "template" "Choice 1" ^?! _Right
|
|
|
|
, compileMustacheText "template" "Choice 2" ^?! _Right
|
|
|
|
])
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, localOption (QuickCheckTests 50)
|
|
|
|
. localOption (QuickCheckMaxSize 10)
|
|
|
|
$ testGroup "MessageMap"
|
|
|
|
[ testGroup "instance Ixed"
|
|
|
|
[ testProperty "traversal laws" $ \k ->
|
|
|
|
isTraversal $ ix @MessageMap k
|
|
|
|
, testCase "preview when exists" $
|
|
|
|
let
|
|
|
|
Right tpl = compileMustacheText "foo" "bar"
|
|
|
|
msg = Single tpl
|
feat(xanthous): Describe *where* the item is in the inventory
When describing items in the inventory, both in detail and when
producing menus from those items, describe not just the item itself but
also *where* in the inventory the item is (either in the backpack, or
wielded in either or both of the hands). This uses a new
InventoryPosition datatype, and a method to get a list of items in the
inventory associated with their inventory position. When *removing*
items from the inventory (to wield, drop, or eat them), we want to make
sure we remove from the right position, so this also introduces
a `removeItemAtPosition` method to make that happen correctly.
Finally, some of the tests for this stuff was getting really slow - I
narrowed this down to runaway arbitrary generation for message
Templates, so I've tweaked the Arbitrary instance for that type to
generate smaller values.
Change-Id: I24e9948adae24b0ca9bf13955602108ca9079dcc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3228
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2021-06-20 21:35:08 +02:00
|
|
|
mm = Nested [("foo", Direct msg)]
|
2019-09-01 19:54:27 +02:00
|
|
|
in mm ^? ix ["foo"] @?= Just msg
|
|
|
|
]
|
|
|
|
, testGroup "lookupMessage"
|
|
|
|
[ testProperty "is equivalent to preview ix" $ \msgMap path ->
|
|
|
|
lookupMessage path msgMap === msgMap ^? ix path
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
, testGroup "Messages"
|
|
|
|
[ testCase "are all valid" $ messages `deepseq` pure ()
|
|
|
|
]
|
feat(xanthous): Describe *where* the item is in the inventory
When describing items in the inventory, both in detail and when
producing menus from those items, describe not just the item itself but
also *where* in the inventory the item is (either in the backpack, or
wielded in either or both of the hands). This uses a new
InventoryPosition datatype, and a method to get a list of items in the
inventory associated with their inventory position. When *removing*
items from the inventory (to wield, drop, or eat them), we want to make
sure we remove from the right position, so this also introduces
a `removeItemAtPosition` method to make that happen correctly.
Finally, some of the tests for this stuff was getting really slow - I
narrowed this down to runaway arbitrary generation for message
Templates, so I've tweaked the Arbitrary instance for that type to
generate smaller values.
Change-Id: I24e9948adae24b0ca9bf13955602108ca9079dcc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3228
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2021-06-20 21:35:08 +02:00
|
|
|
|
|
|
|
, testGroup "Template"
|
|
|
|
[ testGroup "eq"
|
|
|
|
[ testProperty "reflexive" $ \(tpl :: Template) -> tpl == tpl
|
|
|
|
]
|
|
|
|
]
|
2019-09-01 19:54:27 +02:00
|
|
|
]
|