~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to test/ruby/test_sprintf.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'test/unit'
2
2
 
3
3
class TestSprintf < Test::Unit::TestCase
 
4
  def test_positional
 
5
    assert_equal("     00001", sprintf("%*1$.*2$3$d", 10, 5, 1))
 
6
  end
 
7
 
4
8
  def test_binary
5
9
    assert_equal("0", sprintf("%b", 0))
6
10
    assert_equal("1", sprintf("%b", 1))
138
142
    assert_equal("-Inf    ", sprintf("%- 08f", -inf))
139
143
    assert_equal("-0000Inf", sprintf("%+ 08f", -inf))
140
144
  end
 
145
 
 
146
  def test_invalid
 
147
    # [ruby-core:11569]
 
148
 
 
149
    # Star precision before star width:
 
150
    assert_raise(ArgumentError) {sprintf("%.**d", 5, 10, 1)}
 
151
 
 
152
    # Precision before flags and width:
 
153
    assert_raise(ArgumentError) {sprintf("%.5+05d", 5)}
 
154
    assert_raise(ArgumentError) {sprintf("%.5 5d", 5)}
 
155
 
 
156
    # Overriding a star width with a numeric one:
 
157
    assert_raise(ArgumentError) {sprintf("%*1s", 5, 1)}
 
158
 
 
159
    # Width before flags:
 
160
    assert_raise(ArgumentError) {sprintf("%5+0d", 1)}
 
161
    assert_raise(ArgumentError) {sprintf("%5 0d", 1)}
 
162
 
 
163
    # Specifying width multiple times:
 
164
    assert_raise(ArgumentError) {sprintf("%50+30+20+10+5d", 5)}
 
165
    assert_raise(ArgumentError) {sprintf("%50 30 20 10 5d", 5)}
 
166
 
 
167
    # [ruby-core:11570]
 
168
    # Specifying the precision multiple times with negative star arguments:
 
169
    assert_raise(ArgumentError) {sprintf("%.*.*.*.*f", -1, -1, -1, 5, 1)}
 
170
 
 
171
    # [ruby-core:11571]
 
172
    # Null bytes after percent signs are removed:
 
173
    assert_equal("%\0x hello", sprintf("%\0x hello"))
 
174
 
 
175
    # [ruby-core:11573]
 
176
    assert_raise(ArgumentError) {sprintf("%.25555555555555555555555555555555555555s", "hello")}
 
177
  end
141
178
end