diff options
Diffstat (limited to 'js/scripting-lang/scratch_tests/test_first_part.txt')
-rw-r--r-- | js/scripting-lang/scratch_tests/test_first_part.txt | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/scripting-lang/scratch_tests/test_first_part.txt b/js/scripting-lang/scratch_tests/test_first_part.txt new file mode 100644 index 0000000..61b2da1 --- /dev/null +++ b/js/scripting-lang/scratch_tests/test_first_part.txt @@ -0,0 +1,48 @@ +/* Test first part of enhanced case statements */ + +/* ===== FIZZBUZZ IMPLEMENTATION ===== */ + +/* Classic FizzBuzz using multi-value patterns with expressions */ +fizzbuzz : n -> + when (n % 3) (n % 5) is + 0 0 then "FizzBuzz" + 0 _ then "Fizz" + _ 0 then "Buzz" + _ _ then n; + +/* Test FizzBuzz implementation */ +fizzbuzz_15 : fizzbuzz 15; /* Should be "FizzBuzz" */ +fizzbuzz_3 : fizzbuzz 3; /* Should be "Fizz" */ +fizzbuzz_5 : fizzbuzz 5; /* Should be "Buzz" */ +fizzbuzz_7 : fizzbuzz 7; /* Should be 7 */ + +/* ===== TABLE ACCESS IN WHEN EXPRESSIONS ===== */ + +/* User data for testing */ +admin_user : {role: "admin", level: 5, name: "Alice"}; +user_user : {role: "user", level: 2, name: "Bob"}; +guest_user : {role: "guest", level: 0, name: "Charlie"}; + +/* Access control using table access in patterns */ +access_level : user -> + when user.role is + "admin" then "full access" + "user" then "limited access" + _ then "no access"; + +/* Test access control */ +admin_access : access_level admin_user; +user_access : access_level user_user; +guest_access : access_level guest_user; + +/* Output results */ +..out "FizzBuzz Results:"; +..out fizzbuzz_15; +..out fizzbuzz_3; +..out fizzbuzz_5; +..out fizzbuzz_7; + +..out "Access Control Results:"; +..out admin_access; +..out user_access; +..out guest_access; \ No newline at end of file |