Files
Odin/tests/internal/test_objc.odin
T
BBandClaude Opus 5.5 9e594ed3d1 Pass the class name in objc_register_class
objc_register_class handed objc_allocateClassPair a nil Class as the
name argument, which the backend cannot convert to cstring, so any use
of the builtin panicked the compiler. The class pair is now allocated
under the requested name, as the checked signature intends.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 22:07:09 +02:00

26 lines
924 B
Odin

#+build darwin
package test_internal
import "base:intrinsics"
import "core:testing"
import NS "core:sys/darwin/Foundation"
// Sending a message makes the Objective-C setup look up the receiver's class and the
// selector, so the compiler needs objc_lookUpClass and sel_registerName even when nothing
// else refers to them.
@(test)
objc_send_registers_names :: proc(t: ^testing.T) {
s := NS.String.alloc()->initWithOdinString("hello")
defer s->release()
testing.expect_value(t, s->odinString(), "hello")
testing.expect_value(t, intrinsics.objc_send(NS.UInteger, s, "length"), 5)
}
@(test)
objc_register_class_names_the_class :: proc(t: ^testing.T) {
cls := intrinsics.objc_register_class("OdinTestRegisteredClass")
testing.expect(t, cls != nil)
testing.expect_value(t, string(NS.class_getName(cls)), "OdinTestRegisteredClass")
testing.expect_value(t, intrinsics.objc_find_class("OdinTestRegisteredClass"), cls)
}