summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-19 22:48:04 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-19 22:48:04 +0000
commit23065ddf6ed0b3762dda5f5059888eb52b5c2415 (patch)
treeaec187b8211203081e8dacb07a5ce325eb348cc4 /tests
parent3af5dcf34d705cc52c1ffe5b85c2a90b5104e4c9 (diff)
Fixes related to memory safety. I will work more on this related to the stdlib.
Diffstat (limited to 'tests')
-rw-r--r--tests/collections/test_string_suite.zc12
-rw-r--r--tests/std/test_fs.zc13
2 files changed, 12 insertions, 13 deletions
diff --git a/tests/collections/test_string_suite.zc b/tests/collections/test_string_suite.zc
index 4d2c080..a3f608d 100644
--- a/tests/collections/test_string_suite.zc
+++ b/tests/collections/test_string_suite.zc
@@ -10,7 +10,7 @@ test "test_string_methods" {
var s1: String = String::from("Hello World");
var sub: String = s1.substring(0, 5);
var expected1: String = String::from("Hello");
- if (sub.eq(expected1)) {
+ if (sub.eq(&expected1)) {
println " -> substring(0, 5): Passed";
} else {
assert(false, "substring(0, 5) failed");
@@ -19,7 +19,7 @@ test "test_string_methods" {
// Substring middle
var sub2: String = s1.substring(6, 5);
var expected2: String = String::from("World");
- if (sub2.eq(expected2)) {
+ if (sub2.eq(&expected2)) {
println " -> substring(6, 5): Passed";
} else {
assert(false, "substring(6, 5) failed");
@@ -67,9 +67,9 @@ test "test_string_methods" {
// Append
var s2: String = String::from("Hello");
var s3: String = String::from(" World");
- s2.append(s3);
+ s2.append(&s3);
var expected6: String = String::from("Hello World");
- if (s2.eq(expected6)) {
+ if (s2.eq(&expected6)) {
println " -> append(): Passed";
} else {
assert(false, "append() failed");
@@ -99,7 +99,7 @@ test "test_string_std_ops" {
var s1 = String::from("Hello");
var s2 = String::from(" World");
- var s3 = s1 + s2;
+ var s3 = s1.add(&s2);
print "Concatenated: ";
s3.println();
@@ -107,7 +107,7 @@ test "test_string_std_ops" {
assert(s3.length() == 11, "Length mismatch");
var s4 = String::from("Hello World");
- if (s3.eq(s4)) {
+ if (s3.eq(&s4)) {
println "Equality check passed: Strings are identical.";
} else {
assert(false, "Equality check failed");
diff --git a/tests/std/test_fs.zc b/tests/std/test_fs.zc
index 7f66589..fc6d069 100644
--- a/tests/std/test_fs.zc
+++ b/tests/std/test_fs.zc
@@ -13,19 +13,19 @@ test "test_std_fs_extended" {
var p3 = Path::new("file.txt");
var ext = p3.extension();
assert(ext.is_some(), "Extension missed");
- assert(strcmp(ext.unwrap().c_str(), ".txt") == 0, "Wrong extension");
+ assert(strcmp(ext.unwrap_ref().c_str(), ".txt") == 0, "Wrong extension");
var p4 = Path::new("/usr/bin/gcc");
var parent = p4.parent();
assert(parent.is_some(), "Parent missed");
- assert(strcmp(parent.unwrap().c_str(), "/usr/bin") == 0, "Wrong parent");
+ assert(strcmp(parent.unwrap_ref().c_str(), "/usr/bin") == 0, "Wrong parent");
var fname = p4.file_name();
assert(fname.is_some(), "Filename missed");
- assert(strcmp(fname.unwrap().c_str(), "gcc") == 0, "Wrong filename");
+ assert(strcmp(fname.unwrap_ref().c_str(), "gcc") == 0, "Wrong filename");
"Testing FS...";
- var test_dir = "test_fs_sandbox";
+ var test_dir = "tests/test_fs_sandbox";
if (File::exists(test_dir)) {
File::remove_dir(test_dir);
@@ -63,9 +63,8 @@ test "test_std_fs_extended" {
assert(list_res.is_ok(), "Read dir failed");
var entries = list_res.unwrap();
var found_idx = -1;
- for (var i: usize = 0; i < entries.length(); i = i + 1) {
- var entry: DirEntry = entries.get(i);
- if (strcmp(entry.name.c_str(), "hello.txt") == 0) {
+ for entry in &entries {
+ if (strcmp((*entry).name.c_str(), "hello.txt") == 0) {
found_idx = 1;
break;
}