File: DebugTests.hs

package info (click to toggle)
haskell-hslua-core 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: haskell: 2,243; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,030 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
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}
{-|
Module      :  HsLua.Core.DebugTests
Copyright   :  © 2023-2024 Albert Krewinkel
License     :  MIT
Maintainer  :  Albert Krewinkel <tarleb@hslua.org>

Test the debug interface.
-}
module HsLua.Core.DebugTests (tests) where

import HsLua.Core as Lua
import Test.Tasty.HsLua ((=:), shouldBeResultOf)
import Test.Tasty (TestTree, testGroup)

-- | Specifications for Attributes parsing functions.
tests :: TestTree
tests = testGroup "Debug"
  [ "getupvalue" =:
    Just "x" `shouldBeResultOf` do
      loadstring "local x = 0; return function () return x + 23 end"
      call 0 1
      getupvalue top 1

  , "setupvalue" =:
    (Just "i", Just 28) `shouldBeResultOf` do
      loadstring "local i = 0; return function () return i + 23 end"
      call 0 1
      -- set 'x' to 5
      pushinteger 5
      name <- setupvalue (nth 2) 1
      -- call function and check the returned value
      call 0 1
      i <- tointeger top
      return (name, i)
  ]