Add tests for string variables in native

This commit is contained in:
Joshua Suskalo 2025-02-27 10:44:55 -05:00
parent 053166d0f4
commit 5d94afdbf3
No known key found for this signature in database
GPG key ID: 9B6BA586EFF1B9F0
2 changed files with 9 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
const int c = 42;
const char *s = "Test string";
int add_numbers(int a, int b) {
return a + b;
@ -33,6 +34,7 @@ int upcall_test2(int (*f)(void)) {
return f();
}
char *mut_str = NULL;
int counter = 0;
static char* responses[] = { "Hello, world!", "Goodbye friend.", "co'oi prenu" };

View file

@ -11,7 +11,8 @@
(t/is (not (nil? (ffi/find-symbol "add_numbers")))))
(t/deftest can-fetch-constant
(t/is (= 42 (ffi/const "c" ::mem/int))))
(t/is (= 42 (ffi/const "c" ::mem/int)))
(t/is (= "Test string" (ffi/const "s" ::mem/c-string))))
(t/deftest can-call-primitive-fns
(t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))
@ -59,6 +60,11 @@
:y 42.0})))
(t/deftest static-variables-are-mutable
(let [mut-str (ffi/static-variable "mut_str" ::mem/c-string)]
(ffi/freset! mut-str nil)
(t/is (nil? @mut-str))
(ffi/freset! mut-str "Hello world!")
(t/is (= "Hello world!" @mut-str)))
(ffi/freset! (ffi/static-variable "counter" ::mem/int) 1)
(t/is (= ((ffi/cfn "get_string1" [] ::mem/c-string))
"Goodbye friend.")))