summaryrefslogtreecommitdiff
path: root/test/ruby/test_whileuntil.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_whileuntil.rb')
-rw-r--r--test/ruby/test_whileuntil.rb30
1 files changed, 24 insertions, 6 deletions
diff --git a/test/ruby/test_whileuntil.rb b/test/ruby/test_whileuntil.rb
index 9731879122..ff6d29ac4a 100644
--- a/test/ruby/test_whileuntil.rb
+++ b/test/ruby/test_whileuntil.rb
@@ -1,6 +1,6 @@
+# frozen_string_literal: false
require 'test/unit'
require 'tmpdir'
-require_relative 'envutil'
class TestWhileuntil < Test::Unit::TestCase
def test_while
@@ -22,7 +22,7 @@ class TestWhileuntil < Test::Unit::TestCase
break if /vt100/ =~ line
end
- assert(!tmp.eof?)
+ assert_not_predicate(tmp, :eof?)
assert_match(/vt100/, line)
tmp.close
@@ -31,7 +31,7 @@ class TestWhileuntil < Test::Unit::TestCase
next if /vt100/ =~ line
assert_no_match(/vt100/, line)
end
- assert(tmp.eof?)
+ assert_predicate(tmp, :eof?)
assert_no_match(/vt100/, line)
tmp.close
@@ -46,7 +46,7 @@ class TestWhileuntil < Test::Unit::TestCase
assert_no_match(/vt100/, line)
assert_no_match(/VT100/, line)
end
- assert(tmp.eof?)
+ assert_predicate(tmp, :eof?)
tmp.close
sum=0
@@ -61,7 +61,7 @@ class TestWhileuntil < Test::Unit::TestCase
tmp = open(tmpfilename, "r")
while line = tmp.gets()
- break if 3
+ break if $. == 3
assert_no_match(/vt100/, line)
assert_no_match(/Amiga/, line)
assert_no_match(/paper/, line)
@@ -73,11 +73,29 @@ class TestWhileuntil < Test::Unit::TestCase
}
end
+ def test_begin_while
+ i = 0
+ sum = 0
+ begin
+ i += 1
+ sum += i
+ end while i < 10
+ assert_equal([10, 55], [i, sum])
+
+ i = 0
+ sum = 0
+ (
+ i += 1
+ sum += i
+ ) while false
+ assert_equal([0, 0], [i, sum])
+ end
+
def test_until
i = 0
until i>4
i+=1
end
- assert(i>4)
+ assert_operator(i, :>, 4)
end
end