File: InvokableTests.hs

package info (click to toggle)
haskell-hslua-classes 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 124 kB
  • sloc: haskell: 796; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download
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
{-# LANGUAGE OverloadedStrings #-}
{-|
Module      : HsLua.Class.InvokableTests
Copyright   : © 2017-2024 Albert Krewinkel
License     : MIT
Maintainer  : Albert Krewinkel <tarleb@hslua.org>

Tests that Lua functions can be called from Haskell.
-}
module HsLua.Class.InvokableTests (tests) where

import Data.ByteString.Char8 as Char8
import HsLua.Class.Invokable (invoke)
import HsLua.Core (Lua, openlibs)
import Test.Tasty.HsLua ((=:), shouldBeErrorMessageOf, shouldBeResultOf)
import Test.Tasty (TestTree, testGroup)

import qualified HsLua.Core as Lua

-- | Specifications for Attributes parsing functions.
tests :: TestTree
tests = testGroup "Invokable"
  [ "test equality within lua" =:
    True `shouldBeResultOf` do
      openlibs
      invoke "rawequal" (5 :: Lua.Integer) (5.0 :: Lua.Number)

  , "failing lua function call" =:
    "foo" `shouldBeErrorMessageOf` do
      openlibs
      invoke "assert" False (Char8.pack "foo") :: Lua Bool

  , "pack table via lua procedure" =:
    (True, 23 :: Lua.Integer, "moin" :: ByteString) `shouldBeResultOf` do
      openlibs
      invoke "table.pack" True (23 :: Lua.Integer) (Char8.pack "moin")

  , "failing lua procedure call" =:
    "foo" `shouldBeErrorMessageOf` do
      openlibs
      invoke "error" (Char8.pack "foo") :: Lua ()

  , "Error when Lua-to-Haskell result conversion fails" =:
    "string expected, got boolean" `shouldBeErrorMessageOf` do
      openlibs
      invoke "rawequal" (Char8.pack "a") () :: Lua String
  ]