diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2023-01-01 13:38:17 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2023-01-01 13:38:19 -0300 |
commit | 078490a4b250008b0f762bceae67018f5f1864f9 (patch) | |
tree | 4e6fbc518a5b77c32d9049e67852334156421674 | |
parent | 49eed912b0113b3b9c0949f0ef056f390ed359ba (diff) | |
download | highline-078490a4b250008b0f762bceae67018f5f1864f9.tar.gz |
Add test for issue #233
Show default for non Strings
-rwxr-xr-x | test/test_highline.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test/test_highline.rb b/test/test_highline.rb index e623305..aeb41ca 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -817,13 +817,28 @@ class TestHighLine < Minitest::Test end def test_default_with_non_String_objects - # With a non-string object, it should not show + # With a non-string object, it should try to coerce it to String. + # If the coercion is not possible, do not show # any 'default' at prompt line. And should # return the "default" object, without conversion. @input << "\n" @input.rewind + default_integer_object = 42 + + answer = @terminal.ask("Question: ") do |q| + q.default = default_integer_object + end + + assert_equal default_integer_object, answer + assert_equal "Question: |42| ", @output.string + + @input.truncate(@input.rewind) + @input << "\n" + @input.rewind + @output.truncate(@output.rewind) + default_non_string_object = Object.new answer = @terminal.ask("Question: ") do |q| |