From 82559fe7ff00f5cce030f4d5231a270267087624 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sun, 18 Jan 2026 23:23:50 +0000 Subject: Fix for #5 --- tests/features/fstring_lib.h | 9 +++++++++ tests/features/fstring_mod.zc | 4 ++++ tests/features/test_fstring.zc | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/features/fstring_lib.h create mode 100644 tests/features/fstring_mod.zc create mode 100644 tests/features/test_fstring.zc (limited to 'tests') diff --git a/tests/features/fstring_lib.h b/tests/features/fstring_lib.h new file mode 100644 index 0000000..ef292d2 --- /dev/null +++ b/tests/features/fstring_lib.h @@ -0,0 +1,9 @@ + +#ifndef FSTRING_LIB_H +#define FSTRING_LIB_H + +static int lib_val() { + return 99; +} + +#endif diff --git a/tests/features/fstring_mod.zc b/tests/features/fstring_mod.zc new file mode 100644 index 0000000..78b16ef --- /dev/null +++ b/tests/features/fstring_mod.zc @@ -0,0 +1,4 @@ + +fn get_val() -> int { + return 42; +} diff --git a/tests/features/test_fstring.zc b/tests/features/test_fstring.zc new file mode 100644 index 0000000..3ef64a7 --- /dev/null +++ b/tests/features/test_fstring.zc @@ -0,0 +1,23 @@ +import "tests/features/fstring_mod.zc" as Mod; + +test "alias namespace fstring" { + // Tests that {Mod::get_val()} is parsed correctly (Mod_get_val) + var res = f"{Mod::get_val()}"; + assert(res == "42", "Import namespace in f-string failed"); + + // Check local string formatting via println (compile check) + println "Val: {Mod::get_val()}"; +} + +import "tests/features/fstring_lib.h" as Lib; + +test "alias C header fstring" { + // Tests that {Lib::lib_val()} resolves to lib_val() (no mangling/prefix) + // parser_expr.c strips alias for C headers. + // parser_utils.c rewrite_expr_methods needs to do the same. + var res = f"{Lib::lib_val()}"; + assert(res == "99", "C header namespace in f-string failed"); + + // Verify println (rewrite_expr_methods path) + println "C Val: {Lib::lib_val()}"; +} -- cgit v1.2.3