File: metatable_test.go

package info (click to toggle)
golang-layeh-gopher-luar 1.0.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 224 kB
  • sloc: makefile: 7
file content (38 lines) | stat: -rw-r--r-- 693 bytes parent folder | download | duplicates (2)
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
package luar

import (
	"testing"

	"github.com/yuin/gopher-lua"
)

func Test_metatable(t *testing.T) {
	L := lua.NewState()
	defer L.Close()

	tbl := []struct {
		Value    interface{}
		CustomMT bool
	}{
		{"hello", false},
		{123, false},
		{1.23, false},
		{nil, false},
		{struct{}{}, true},
		{&struct{}{}, true},
		{[]string{}, true},
		{make(chan string), true},
		{(*string)(nil), true},
		{func() {}, false},
		{map[string]int{}, true},
	}

	for _, v := range tbl {
		mt := MT(L, v.Value)
		if v.CustomMT && mt == nil {
			t.Fatalf("expected to have custom MT for %#v\n", v.Value)
		} else if !v.CustomMT && mt != nil {
			t.Fatalf("unexpected custom MT for %#v\n", v.Value)
		}
	}
}