summaryrefslogtreecommitdiffhomepage
path: root/test/t
diff options
context:
space:
mode:
authorChristopher Aue <[email protected]>2017-07-16 22:25:48 +0200
committerChristopher Aue <[email protected]>2017-07-16 22:25:48 +0200
commit8fe2a6ce0ffcc82be98d55a4df699150af1f3cb1 (patch)
tree1f7f00ad9e4ea2e2f8266c05259012735f6c4ec0 /test/t
parent515a093213cba06e4750d4facfbd9a8297426478 (diff)
downloadmruby-8fe2a6ce0ffcc82be98d55a4df699150af1f3cb1.tar.gz
mruby-8fe2a6ce0ffcc82be98d55a4df699150af1f3cb1.zip
added basic tests for while/until/break/next
Diffstat (limited to 'test/t')
-rw-r--r--test/t/iterations.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/t/iterations.rb b/test/t/iterations.rb
new file mode 100644
index 000000000..f227a6037
--- /dev/null
+++ b/test/t/iterations.rb
@@ -0,0 +1,61 @@
+assert('while expression', '11.5.2.3.2') do
+ idx = 10
+ all = []
+ res = while idx > 0
+ all << idx
+ idx -= 1
+ end
+
+ assert_equal nil, res
+ assert_equal [10,9,8,7,6,5,4,3,2,1], all
+end
+
+assert('until expression', '11.5.2.3.3') do
+ idx = 10
+ all = []
+ res = until idx == 0
+ all << idx
+ idx -= 1
+ end
+
+ assert_equal nil, res
+ assert_equal [10,9,8,7,6,5,4,3,2,1], all
+end
+
+assert('break expression', '11.5.2.4.3') do
+ assert_equal :result do
+ while true
+ break :result
+ end
+ end
+
+ assert_equal :result do
+ until false
+ break :result
+ end
+ end
+end
+
+assert('next expression', '11.5.2.4.4') do
+ assert_equal [8,6,4,2,0] do
+ all = []
+ idx = 10
+ while idx > 0
+ idx -= 1
+ next if (idx % 2) == 1
+ all << idx
+ end
+ all
+ end
+
+ assert_equal [8,6,4,2,0] do
+ all = []
+ idx = 10
+ until idx == 0
+ idx -= 1
+ next if (idx % 2) == 1
+ all << idx
+ end
+ all
+ end
+end \ No newline at end of file