[macruby-changes] [MacRuby/MacRuby] 53b78c: fix named argument
GitHub
noreply at github.com
Wed Feb 1 04:24:36 PST 2012
Branch: refs/heads/master
Home: https://github.com/MacRuby/MacRuby
Commit: 53b78caf0339d8544d0970b2fc58d6896e8ad57f
https://github.com/MacRuby/MacRuby/commit/53b78caf0339d8544d0970b2fc58d6896e8ad57f
Author: Watson <watson1978 at gmail.com>
Date: 2012-02-01 (Wed, 01 Feb 2012)
Changed paths:
M sprintf.c
Log Message:
-----------
fix named argument
Test Script:
----
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
assert_equal(
"foo, bar",
"%{firstname}, %{lastname}" % {firstname: "foo", lastname: "bar"}
)
assert_equal(
"10, 43.5",
"%<integer>d, %<float>.1f" % { integer: 10, float: 43.476374 }
)
assert_equal(
"10<float>",
"%{integer}<float>" % { integer: 10, float: 43.476374 }
)
assert_raise(ArgumentError){ "%<foo><bar>" % { foo: 10, bar: 42 } }
#----
assert_equal(
"01 : 02",
"%<foo>02d : %<bar>02d" % { :foo => 1, :bar => 2 }
)
assert_equal(
"01<foo>",
"%02d<foo>" % [1, {:foo => 1}]
)
assert_raise(ArgumentError){ "%s %1$s" % "foo" }
assert_raise(ArgumentError){ "%02d%<foo>" % [1, {:foo => 1}] }
assert_raise(ArgumentError){ "%1$<key2>s" % {:key => "value"} }
More information about the macruby-changes
mailing list