From 44284f71c91b309d46b35fc683504235de6f8e50 Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 18 Feb 2004 09:09:21 +0000 Subject: [PATCH] * test/ruby/test_sprintf.rb: added tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++ MANIFEST | 1 + test/ruby/test_sprintf.rb | 77 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 test/ruby/test_sprintf.rb diff --git a/ChangeLog b/ChangeLog index 5332433e41..de76d3e801 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Feb 18 18:07:09 2004 NAKAMURA Usaku + + * test/ruby/test_sprintf.rb: added tests. + Wed Feb 18 17:18:01 2004 WATANABE Hirofumi * ext/win32ole/win32ole.c: need to include on Cygwin. diff --git a/MANIFEST b/MANIFEST index 6d3b3265ce..5ac2924765 100644 --- a/MANIFEST +++ b/MANIFEST @@ -825,6 +825,7 @@ test/ruby/test_pipe.rb test/ruby/test_proc.rb test/ruby/test_range.rb test/ruby/test_signal.rb +test/ruby/test_sprintf.rb test/ruby/test_stringchar.rb test/ruby/test_struct.rb test/ruby/test_system.rb diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb new file mode 100644 index 0000000000..e6cfb5b016 --- /dev/null +++ b/test/ruby/test_sprintf.rb @@ -0,0 +1,77 @@ +require 'test/unit' + +$KCODE = 'none' + +class TestSprintf < Test::Unit::TestCase + def test_binary + assert_equal("0", sprintf("%b", 0)) + assert_equal("1", sprintf("%b", 1)) + assert_equal("10", sprintf("%b", 2)) + assert_equal("..1", sprintf("%b", -1)) + + assert_equal(" 0", sprintf("%4b", 0)) + assert_equal(" 1", sprintf("%4b", 1)) + assert_equal(" 10", sprintf("%4b", 2)) + assert_equal(" ..1", sprintf("%4b", -1)) + + assert_equal("0000", sprintf("%04b", 0)) + assert_equal("0001", sprintf("%04b", 1)) + assert_equal("0010", sprintf("%04b", 2)) + assert_equal("1111", sprintf("%04b", -1)) + + assert_equal("0000", sprintf("%.4b", 0)) + assert_equal("0001", sprintf("%.4b", 1)) + assert_equal("0010", sprintf("%.4b", 2)) + assert_equal("1111", sprintf("%.4b", -1)) + + assert_equal(" 0000", sprintf("%6.4b", 0)) + assert_equal(" 0001", sprintf("%6.4b", 1)) + assert_equal(" 0010", sprintf("%6.4b", 2)) + assert_equal(" 1111", sprintf("%6.4b", -1)) + + assert_equal(" 0b0", sprintf("%#4b", 0)) + assert_equal(" 0b1", sprintf("%#4b", 1)) + assert_equal("0b10", sprintf("%#4b", 2)) + assert_equal("0b..1", sprintf("%#4b", -1)) + + assert_equal("0b00", sprintf("%#04b", 0)) + assert_equal("0b01", sprintf("%#04b", 1)) + assert_equal("0b10", sprintf("%#04b", 2)) + assert_equal("0b11", sprintf("%#04b", -1)) + + assert_equal("0b0000", sprintf("%#.4b", 0)) + assert_equal("0b0001", sprintf("%#.4b", 1)) + assert_equal("0b0010", sprintf("%#.4b", 2)) + assert_equal("0b1111", sprintf("%#.4b", -1)) + + assert_equal("0b0000", sprintf("%#6.4b", 0)) + assert_equal("0b0001", sprintf("%#6.4b", 1)) + assert_equal("0b0010", sprintf("%#6.4b", 2)) + assert_equal("0b1111", sprintf("%#6.4b", -1)) + + assert_equal("+0", sprintf("%+b", 0)) + assert_equal("+1", sprintf("%+b", 1)) + assert_equal("+10", sprintf("%+b", 2)) + assert_equal("-1", sprintf("%+b", -1)) + + assert_equal(" +0", sprintf("%+4b", 0)) + assert_equal(" +1", sprintf("%+4b", 1)) + assert_equal(" +10", sprintf("%+4b", 2)) + assert_equal(" -1", sprintf("%+4b", -1)) + + assert_equal("+000", sprintf("%+04b", 0)) + assert_equal("+001", sprintf("%+04b", 1)) + assert_equal("+010", sprintf("%+04b", 2)) + assert_equal("-001", sprintf("%+04b", -1)) + + assert_equal("+0000", sprintf("%+.4b", 0)) + assert_equal("+0001", sprintf("%+.4b", 1)) + assert_equal("+0010", sprintf("%+.4b", 2)) + assert_equal("-0001", sprintf("%+.4b", -1)) + + assert_equal(" +0000", sprintf("%+6.4b", 0)) + assert_equal(" +0001", sprintf("%+6.4b", 1)) + assert_equal(" +0010", sprintf("%+6.4b", 2)) + assert_equal(" -0001", sprintf("%+6.4b", -1)) + end +end