@@ -320,6 +320,10 @@ def obj.to_i; 10; end
320
320
@method . call ( "%s" , "abc" ) . should == "abc"
321
321
end
322
322
323
+ it "substitutes '' for nil" do
324
+ @method . call ( "%s" , nil ) . should == ""
325
+ end
326
+
323
327
it "converts argument to string with to_s" do
324
328
obj = mock ( "string" )
325
329
obj . should_receive ( :to_s ) . and_return ( "abc" )
@@ -348,6 +352,28 @@ def obj.to_str
348
352
Kernel . format ( "%-3.3s" , "hello" ) . should == "hel"
349
353
end
350
354
355
+ it "formats string with width" do
356
+ @method . call ( "%6s" , "abc" ) . should == " abc"
357
+ @method . call ( "%6s" , "abcdefg" ) . should == "abcdefg"
358
+ end
359
+
360
+ it "formats string with width and precision" do
361
+ @method . call ( "%4.6s" , "abc" ) . should == " abc"
362
+ @method . call ( "%4.6s" , "abcdefg" ) . should == "abcdef"
363
+ end
364
+
365
+ it "formats nli with width" do
366
+ @method . call ( "%6s" , nil ) . should == " "
367
+ end
368
+
369
+ it "formats nli with precision" do
370
+ @method . call ( "%.6s" , nil ) . should == ""
371
+ end
372
+
373
+ it "formats nil with width and precision" do
374
+ @method . call ( "%4.6s" , nil ) . should == " "
375
+ end
376
+
351
377
it "formats multibyte string with precision" do
352
378
Kernel . format ( "%.2s" , "été" ) . should == "ét"
353
379
end
0 commit comments