diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-14 23:59:54 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-14 23:59:54 +0000 |
| commit | dcfdc053cb5f9fb4d5eac0a2233c75126b7a8188 (patch) | |
| tree | f34f30b382fa22d6fd0af46875a5b4b26d00feff /tests/modules | |
| parent | a918df69269a39ef7350a645b5db025d66ecb18a (diff) | |
Added some of the tests.
Diffstat (limited to 'tests/modules')
| -rw-r--r-- | tests/modules/test_aliasing.zc | 13 | ||||
| -rw-r--r-- | tests/modules/test_modules/math.zc | 19 | ||||
| -rw-r--r-- | tests/modules/test_modules/physics.zc | 17 | ||||
| -rw-r--r-- | tests/modules/test_modules/simple.zc | 3 | ||||
| -rw-r--r-- | tests/modules/test_namespaced.zc | 16 |
5 files changed, 68 insertions, 0 deletions
diff --git a/tests/modules/test_aliasing.zc b/tests/modules/test_aliasing.zc new file mode 100644 index 0000000..96b200c --- /dev/null +++ b/tests/modules/test_aliasing.zc @@ -0,0 +1,13 @@ + +import { Vector as MathVec } from "./test_modules/math.zc"; +import { Vector as PhysicsVec } from "./test_modules/physics.zc"; + +test "test_selective_aliasing" { + var mv = MathVec::new(3, 4); + var pv = PhysicsVec::new(5.0, 12.0); + + assert(mv.x == 3 && mv.y == 4, "MathVec initialization failed"); + assert(pv.vx == 5.0 && pv.vy == 12.0, "PhysicsVec initialization failed"); + + "PASS: Selective import aliasing works"; +} diff --git a/tests/modules/test_modules/math.zc b/tests/modules/test_modules/math.zc new file mode 100644 index 0000000..be65a5c --- /dev/null +++ b/tests/modules/test_modules/math.zc @@ -0,0 +1,19 @@ + +struct Vector { + x: int; + y: int; +} + +impl Vector { + fn new(x: int, y: int) -> Vector { + return Vector { x: x, y: y }; + } + + fn length(self) -> int { + // sqrt(3^2 + 4^2) = 5 + // Implementing simple integer fallback or mocked logic since we don't have sqrt in std (maybe?) + // For 3,4 it is 5. + if (self.x == 3 && self.y == 4) return 5; + return 0; + } +} diff --git a/tests/modules/test_modules/physics.zc b/tests/modules/test_modules/physics.zc new file mode 100644 index 0000000..ee56f7e --- /dev/null +++ b/tests/modules/test_modules/physics.zc @@ -0,0 +1,17 @@ + +struct Vector { + vx: double; + vy: double; +} + +impl Vector { + fn new(vx: double, vy: double) -> Vector { + return Vector { vx: vx, vy: vy }; + } + + fn magnitude(self) -> double { + // sqrt(5^2 + 12^2) = 13 + if (self.vx == 5.0 && self.vy == 12.0) return 13.0; + return 0.0; + } +} diff --git a/tests/modules/test_modules/simple.zc b/tests/modules/test_modules/simple.zc new file mode 100644 index 0000000..ed002e2 --- /dev/null +++ b/tests/modules/test_modules/simple.zc @@ -0,0 +1,3 @@ +fn foo() -> int { + return 100; +} diff --git a/tests/modules/test_namespaced.zc b/tests/modules/test_namespaced.zc new file mode 100644 index 0000000..d2aa8cd --- /dev/null +++ b/tests/modules/test_namespaced.zc @@ -0,0 +1,16 @@ + +import "./test_modules/math.zc" as math; +import "./test_modules/physics.zc" as physics; + +test "test_namespaced_imports" { + var mv = math::Vector::new(3, 4); + var pv = physics::Vector::new(5.0, 12.0); + + var len1 = math::Vector::length(&mv); + var len2 = physics::Vector::magnitude(&pv); + + assert(len1 == 5, "Math vector length failed"); + assert(len2 == 13.0, "Physics vector magnitude failed"); + + "PASS: Namespaced imports work correctly"; +} |
