feat: add Test effect and native testing framework
- Add Test effect with operations: assert, assertEqual, assertNotEqual, assertTrue, assertFalse, fail - Implement Test effect handlers in interpreter with TestResults tracking - Add values_equal method for comparing Value types in tests - Update lux test command to discover and run test_* functions - Create example test files: test_math.lux, test_lists.lux - Add TESTING_DESIGN.md documentation - Fix AST mismatches in C backend and compiler.rs for compatibility Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
51
examples/test_math.lux
Normal file
51
examples/test_math.lux
Normal file
@@ -0,0 +1,51 @@
|
||||
// Math Test Suite
|
||||
// Run with: lux test examples/test_math.lux
|
||||
|
||||
fn test_addition(): Unit with {Test} = {
|
||||
Test.assertEqual(4, 2 + 2)
|
||||
Test.assertEqual(0, 0 + 0)
|
||||
Test.assertEqual(100, 50 + 50)
|
||||
}
|
||||
|
||||
fn test_subtraction(): Unit with {Test} = {
|
||||
Test.assertEqual(0, 2 - 2)
|
||||
Test.assertEqual(5, 10 - 5)
|
||||
Test.assertEqual(-5, 0 - 5)
|
||||
}
|
||||
|
||||
fn test_multiplication(): Unit with {Test} = {
|
||||
Test.assertEqual(6, 2 * 3)
|
||||
Test.assertEqual(0, 0 * 100)
|
||||
Test.assertEqual(100, 10 * 10)
|
||||
}
|
||||
|
||||
fn test_division(): Unit with {Test} = {
|
||||
Test.assertEqual(2, 6 / 3)
|
||||
Test.assertEqual(0, 0 / 5)
|
||||
Test.assertEqual(5, 25 / 5)
|
||||
}
|
||||
|
||||
fn test_comparisons(): Unit with {Test} = {
|
||||
Test.assertTrue(5 > 3)
|
||||
Test.assertTrue(3 < 5)
|
||||
Test.assertTrue(5 >= 5)
|
||||
Test.assertTrue(5 <= 5)
|
||||
Test.assertFalse(3 > 5)
|
||||
Test.assertFalse(5 < 3)
|
||||
}
|
||||
|
||||
fn test_equality(): Unit with {Test} = {
|
||||
Test.assertTrue(42 == 42)
|
||||
Test.assertFalse(42 == 43)
|
||||
Test.assertTrue(42 != 43)
|
||||
Test.assertFalse(42 != 42)
|
||||
}
|
||||
|
||||
fn test_boolean_logic(): Unit with {Test} = {
|
||||
Test.assertTrue(true && true)
|
||||
Test.assertFalse(true && false)
|
||||
Test.assertTrue(true || false)
|
||||
Test.assertFalse(false || false)
|
||||
Test.assertTrue(!false)
|
||||
Test.assertFalse(!true)
|
||||
}
|
||||
Reference in New Issue
Block a user