-
Notifications
You must be signed in to change notification settings - Fork 1
/
module_test.go
96 lines (80 loc) · 2.01 KB
/
module_test.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gp
import (
"testing"
)
func TestModuleImport(t *testing.T) {
setupTest(t)
// Test importing a built-in module
mathMod := ImportModule("math")
if mathMod.Nil() {
t.Fatal("Failed to import math module")
}
// Test getting module dictionary
modDict := mathMod.Dict()
if modDict.Nil() {
t.Fatal("Failed to get module dictionary")
}
// Verify math module has expected attributes
if !modDict.HasKey("pi") {
t.Error("Math module doesn't contain 'pi' constant")
}
}
func TestGetModule(t *testing.T) {
setupTest(t)
// First import the module
sysModule := ImportModule("sys")
if sysModule.Nil() {
t.Fatal("Failed to import sys module")
}
// Then try to get it
gotModule := GetModule("sys")
if gotModule.Nil() {
t.Fatal("Failed to get sys module")
}
// Both should refer to the same module
if !sysModule.Equals(gotModule) {
t.Error("GetModule returned different module instance than ImportModule")
}
}
func TestCreateModule(t *testing.T) {
setupTest(t)
// Create a new module
modName := "test_module"
mod := CreateModule(modName)
if mod.Nil() {
t.Fatal("Failed to create new module")
}
// Add an object to the module
value := From(42)
err := mod.AddObject("test_value", value)
if err != 0 {
t.Fatal("Failed to add object to module")
}
// Verify the object was added
modDict := mod.Dict()
if !modDict.HasKey("test_value") {
t.Error("Module doesn't contain added value")
}
// Verify the value is correct
gotValue := modDict.Get(From("test_value"))
if !gotValue.Equals(value) {
t.Error("Retrieved value doesn't match added value")
}
}
func TestGetModuleDict(t *testing.T) {
setupTest(t)
// Get the module dictionary
moduleDict := GetModuleDict()
if moduleDict.Nil() {
t.Fatal("Failed to get module dictionary")
}
// Import a module
mathMod := ImportModule("math")
if mathMod.Nil() {
t.Fatal("Failed to import math module")
}
// Verify the module is in the module dictionary
if !moduleDict.HasKey("math") {
t.Error("Module dictionary doesn't contain imported module")
}
}