From c5e1101848b0b9b1b7a1106b3ee6735745cbe612 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Ali Fadel Date: Sat, 12 Oct 2024 19:18:27 +0300 Subject: [PATCH] Add interpreter tests for arrays --- test/interpreter_test.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/interpreter_test.rb b/test/interpreter_test.rb index 669e855..f0101f8 100644 --- a/test/interpreter_test.rb +++ b/test/interpreter_test.rb @@ -220,5 +220,40 @@ def test_while_with_continue assert_output("5\n4\n2\n1\n") { @interpreter.eval(code) } end + + def test_array + code = <<~CODE + مصفوفة_الأعداد = [١، ٢] + اطبع(مصفوفة_الأعداد[٠]) + CODE + + assert_output("1\n") { @interpreter.eval(code) } + end + + def test_array_with_newlines + code = <<~CODE + مصفوفة_الأعداد = [ + ١، + ٢ + ] + + اطبع(مصفوفة_الأعداد[٠]) + CODE + + assert_output("1\n") { @interpreter.eval(code) } + end + + def test_nested_arrays + code = <<~CODE + مصفوفة_الأعداد = [ + ١، + [٢، ٣] + ] + + اطبع(مصفوفة_الأعداد[١][٠]) + CODE + + assert_output("2\n") { @interpreter.eval(code) } + end end end