From d04e78cb00ca7015e2cdf84e057b778cc642617c Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 24 Jan 2024 09:37:42 +0400 Subject: [PATCH] test_wrapper --- test/formatters/test_wrapper.rb | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/formatters/test_wrapper.rb diff --git a/test/formatters/test_wrapper.rb b/test/formatters/test_wrapper.rb new file mode 100644 index 0000000..6022d4b --- /dev/null +++ b/test/formatters/test_wrapper.rb @@ -0,0 +1,50 @@ +require_relative '../../lib/formatters/wrapper' +require 'test/unit' + +class TestWrapper < Test::Unit::TestCase + SCORE_ANSI = "début\e[0;35m\e[0;36mMarron\e[0mMoyen\e[0;35mBleu\e[0mFin\e[0;35m" + SCORE_ANSI2 = "\e[0;35mMauve\e[0m" + SQL_ANSI = "\e[0;35mScore Load (0.6ms)\e[0m \e[0;36mSELECT \"scores\".* FROM \"scores\" WHERE \"scores\".\"id\" = $1 LIMIT $2\e[0m [[\"id\", 2], [\"LIMIT\", 1]]" + + BEGINT = "my text is:\n" + ENDOFT = "a final is:\n" + + def test_wrap_score + assert_wrap("\ +********************\n\ +********************\n\ +**********", + ('*' * 50), 20) + + assert_wrap("\ +> ******************\n\ +> ******************\n\ +> **************", + ('*' * 50), 20, '> ') + end + + def test_wrap_sql + assert_wrap("\ +\e[0;35mScore Load (0.6ms)\e[0m \e[0;36mS\e[0m\n\ +\e[0;36mELECT \"scores\".* FRO\e[0m\n\ +\e[0;36mM \"scores\" WHERE \"sc\e[0m\n\ +\e[0;36mores\".\"id\" = $1 LIMI\e[0m\n\ +\e[0;36mT $2\e[0m [[\"id\", 2], [\"L\n\ +IMIT\", 1]]", "\ +\e[0;35mScore Load (0.6ms)\e[0m \e[0;36mSELECT \"scores\".* FROM \"scores\" WHERE \"scores\".\"id\" = $1 LIMIT $2\e[0m [[\"id\", 2], [\"LIMIT\", 1]]", +20) + end + + private + + def assert_wrap(expectation, text, length, prefix = '') + assert_equal(expectation, prefix+Wrapper.wrap(text, prefix, length - prefix.length)) + test_with_style(text, length, prefix) + end + + def test_with_style(text, length, prefix = '') + puts "#{BEGINT}#{prefix}#{text}\e[0m" + puts "#{ENDOFT}#{prefix}#{Wrapper.wrap(text, prefix, length - prefix.length)}\e[0m" + puts + end +end