diff options
author | Griffin Smith <root@gws.fyi> | 2020-02-08T22·24-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2020-02-08T22·24-0500 |
commit | 25a1c5ade32ee0dca41b8057f053972e4ab816d7 (patch) | |
tree | 31d252cb624ed7d6e97d542f6689234791896355 /test/Xanthous/Data | |
parent | 782d3880c8da35b48276a874d396d24ca6dc7004 (diff) |
Factor out an EntityAttributes type
Factor out a new EntityAttributes type from some of the methods of the Entity class, to avoid the proliferation of 1-argument boolean methods on the entity class that always have to be forwarded through the Entity instance for SomeEntity if they have defaults (forgetting to do which has wasted tons of my time up to this point). Currently blocksVision, blocksObject, and collision are all in there.
Diffstat (limited to 'test/Xanthous/Data')
-rw-r--r-- | test/Xanthous/Data/EntitiesSpec.hs | 28 | ||||
-rw-r--r-- | test/Xanthous/Data/EntityMap/GraphicsSpec.hs | 1 |
2 files changed, 28 insertions, 1 deletions
diff --git a/test/Xanthous/Data/EntitiesSpec.hs b/test/Xanthous/Data/EntitiesSpec.hs new file mode 100644 index 000000000000..e403503743c0 --- /dev/null +++ b/test/Xanthous/Data/EntitiesSpec.hs @@ -0,0 +1,28 @@ +-------------------------------------------------------------------------------- +module Xanthous.Data.EntitiesSpec (main, test) where +-------------------------------------------------------------------------------- +import Test.Prelude +-------------------------------------------------------------------------------- +import qualified Data.Aeson as JSON +-------------------------------------------------------------------------------- +import Xanthous.Data.Entities +-------------------------------------------------------------------------------- + +main :: IO () +main = defaultMain test + +test :: TestTree +test = testGroup "Xanthous.Data.Entities" + [ testGroup "Collision" + [ testProperty "JSON round-trip" $ \(c :: Collision) -> + JSON.decode (JSON.encode c) === Just c + , testGroup "JSON encoding examples" + [ testCase "Stop" $ JSON.encode Stop @?= "\"Stop\"" + , testCase "Combat" $ JSON.encode Combat @?= "\"Combat\"" + ] + ] + , testGroup "EntityAttributes" + [ testProperty "JSON round-trip" $ \(ea :: EntityAttributes) -> + JSON.decode (JSON.encode ea) === Just ea + ] + ] diff --git a/test/Xanthous/Data/EntityMap/GraphicsSpec.hs b/test/Xanthous/Data/EntityMap/GraphicsSpec.hs index 6b736be4ee21..9347a1c1b569 100644 --- a/test/Xanthous/Data/EntityMap/GraphicsSpec.hs +++ b/test/Xanthous/Data/EntityMap/GraphicsSpec.hs @@ -42,6 +42,5 @@ instance Brain TestEntity where step _ = pure instance Draw TestEntity instance Entity TestEntity where - blocksVision _ = False description _ = "" entityChar _ = "e" |