Files
hakorune/local_tests/test_phase_8_9_transparency_removal.nyash

84 lines
2.1 KiB
Plaintext
Raw Normal View History

# Phase 8.9: birth() Unified System Test
# Test 1: Transparency system must produce compile errors
# Test 2: Explicit birth() syntax must work correctly
# Test 3: Weak reference nullification after fini()
print("=== Phase 8.9: Testing transparency removal and explicit birth() syntax ===")
# Test 1: This should produce a compile error after changes
# from StringBox(content) # ❌ Should error after transparency removal
# Test 2: Explicit birth() syntax - should work correctly
box EnhancedString from StringBox {
init { prefix }
birth(content, prefixStr) {
from StringBox.birth(content) # ✅ Explicit syntax - must work
me.prefix = prefixStr
}
override toString() {
return me.prefix + ": " + from StringBox.toString()
}
}
print("Test 2: Explicit birth() syntax")
local enhanced = new EnhancedString("Hello World", "Enhanced")
print(enhanced.toString())
# Test 3: Weak reference nullification after fini
box CPU {
init { name, memory }
birth(cpuName) {
me.name = cpuName
print("CPU " + me.name + " initialized")
}
fini() {
print("CPU " + me.name + " finalizing...")
if (me.memory != null) {
me.memory.cleanup()
}
print("CPU " + me.name + " finalized")
}
}
box Memory {
init { data, weak cpu_ref }
birth(cpu) {
me.data = "memory_data"
me.cpu_ref = cpu # This becomes a weak reference
print("Memory initialized with weak CPU reference")
}
checkCPU() {
if (me.cpu_ref != null) {
return "CPU is alive: " + me.cpu_ref.name
} else {
return "CPU reference is null"
}
}
cleanup() {
print("Memory cleanup called")
me.data = "cleaned"
}
}
print("Test 3: Weak reference nullification after fini")
local cpu = new CPU("TestCPU")
local memory = new Memory(cpu)
cpu.memory = memory
# Before fini
print("Before CPU fini: " + memory.checkCPU())
# After fini - weak reference should be nullified
cpu.fini()
cpu = null
print("After CPU fini: " + memory.checkCPU())
print("=== Phase 8.9 tests completed ===")