File: UnsafeTests.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 (36 lines) | stat: -rw-r--r-- 939 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
{-# OPTIONS_GHC -Wno-warnings-deprecations #-}
{-# LANGUAGE OverloadedStrings #-}
{-|
Module      : HsLua.Core.UnsafeTests
Copyright   : © 2021-2024 Albert Krewinkel
License     : MIT
Maintainer  : Albert Krewinkel <tarleb@hslua.org>
Stability   : beta

Tests for bindings to unsafe functions.
-}
module HsLua.Core.UnsafeTests (tests) where

import HsLua.Core
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HsLua ((=:), pushLuaExpr, shouldBeResultOf)
import qualified HsLua.Core.Unsafe as Unsafe

-- | Tests for unsafe methods.
tests :: TestTree
tests = testGroup "Unsafe"
  [ testGroup "next"
    [ "get next key from table" =:
      Just 43 `shouldBeResultOf` do
        pushLuaExpr "{43}"
        pushnil -- first key
        True <- Unsafe.next (nth 2)
        tonumber top

    , "returns FALSE if table is empty" =:
      False `shouldBeResultOf` do
        newtable
        pushnil
        Unsafe.next (nth 2)
    ]
  ]