|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
| 3 | +require "pp" |
3 | 4 | require_relative "abstract_unit"
|
4 | 5 | require "active_support/ordered_options"
|
5 | 6 |
|
@@ -278,4 +279,46 @@ def test_inheritable_options_count
|
278 | 279 |
|
279 | 280 | assert_equal 3, object.count
|
280 | 281 | end
|
| 282 | + |
| 283 | + def test_ordered_options_to_s |
| 284 | + object = ActiveSupport::OrderedOptions.new |
| 285 | + assert_equal "{}", object.to_s |
| 286 | + |
| 287 | + object.one = "first value" |
| 288 | + object[:two] = "second value" |
| 289 | + object["three"] = "third value" |
| 290 | + |
| 291 | + assert_equal "{:one=>\"first value\", :two=>\"second value\", :three=>\"third value\"}", object.to_s |
| 292 | + end |
| 293 | + |
| 294 | + def test_inheritable_options_to_s |
| 295 | + object = ActiveSupport::InheritableOptions.new(one: "first value") |
| 296 | + assert_equal "{:one=>\"first value\"}", object.to_s |
| 297 | + |
| 298 | + object[:two] = "second value" |
| 299 | + object["three"] = "third value" |
| 300 | + assert_equal "{:one=>\"first value\", :two=>\"second value\", :three=>\"third value\"}", object.to_s |
| 301 | + end |
| 302 | + |
| 303 | + def test_odrered_options_pp |
| 304 | + object = ActiveSupport::OrderedOptions.new |
| 305 | + object.one = "first value" |
| 306 | + object[:two] = "second value" |
| 307 | + object["three"] = "third value" |
| 308 | + |
| 309 | + io = StringIO.new |
| 310 | + PP.pp(object, io) |
| 311 | + assert_equal "{:one=>\"first value\", :two=>\"second value\", :three=>\"third value\"}\n", io.string |
| 312 | + end |
| 313 | + |
| 314 | + def test_inheritable_options_pp |
| 315 | + object = ActiveSupport::InheritableOptions.new(one: "first value") |
| 316 | + object[:two] = "second value" |
| 317 | + object["three"] = "third value" |
| 318 | + assert_equal "{:one=>\"first value\", :two=>\"second value\", :three=>\"third value\"}", object.to_s |
| 319 | + |
| 320 | + io = StringIO.new |
| 321 | + PP.pp(object, io) |
| 322 | + assert_equal "{:one=>\"first value\", :two=>\"second value\", :three=>\"third value\"}\n", io.string |
| 323 | + end |
281 | 324 | end
|
0 commit comments