1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
{-# LANGUAGE OverloadedStrings #-}
{-|
Module : HsLua.UtilTests
Copyright : © 2017-2024 Albert Krewinkel
License : MIT
Maintainer : Albert Krewinkel <tarleb@hslua.org>
Stability : stable
Portability : portable
Tests for utility types and functions
-}
module HsLua.UtilTests (tests) where
import HsLua
import Test.Tasty.HsLua ((=:), shouldBeResultOf)
import Test.Tasty (TestTree, testGroup)
-- | Specifications for Attributes parsing functions.
tests :: TestTree
tests = testGroup "Util"
[ testGroup "getglobbal'"
[ "returns nil if global does not exist" =:
TypeNil `shouldBeResultOf` do
getglobal' "nope"
ltype top
, "returns global" =:
TypeTable `shouldBeResultOf` do
openlibs
getglobal' "math"
ltype top
, "can access nested fields" =:
TypeFunction `shouldBeResultOf` do
openlibs
getglobal' "math.log"
ltype top
, "can access 3rd level fields" =:
TypeTable `shouldBeResultOf` do
openlibs
getglobal' "package.loaded.math"
ltype top
]
, testGroup "setglobbal'"
[ "sets a global" =:
Just "new value" `shouldBeResultOf` do
pushstring "new value"
setglobal' "new"
getglobal "new"
tostring top
, "can change nested values" =:
Just "euler" `shouldBeResultOf` do
openlibs
pushstring "euler"
setglobal' "math.test"
getglobal "math"
getfield top "test"
tostring top
, "can modify 3rd level fields" =:
Just 42 `shouldBeResultOf` do
openlibs
pushinteger 42
setglobal' "package.loaded.math.foo"
getglobal "package"
getfield top "loaded"
getfield top "math"
getfield top "foo"
tointeger top
]
]
|