You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

10 months ago
  1. require_relative '../../lib/formatters/wrapper'
  2. require 'test/unit'
  3. class TestWrapper < Test::Unit::TestCase
  4. SCORE_ANSI = "début\e[0;35m\e[0;36mMarron\e[0mMoyen\e[0;35mBleu\e[0mFin\e[0;35m"
  5. SCORE_ANSI2 = "\e[0;35mMauve\e[0m"
  6. 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]]"
  7. BEGINT = "my text is:\n"
  8. ENDOFT = "a final is:\n"
  9. def test_wrap_score
  10. assert_wrap("\
  11. ********************\n\
  12. ********************\n\
  13. **********",
  14. ('*' * 50), 20)
  15. assert_wrap("\
  16. > ******************\n\
  17. > ******************\n\
  18. > **************",
  19. ('*' * 50), 20, '> ')
  20. end
  21. def test_wrap_sql
  22. assert_wrap("\
  23. \e[0;35mScore Load (0.6ms)\e[0m \e[0;36mS\e[0m\n\
  24. \e[0;36mELECT \"scores\".* FRO\e[0m\n\
  25. \e[0;36mM \"scores\" WHERE \"sc\e[0m\n\
  26. \e[0;36mores\".\"id\" = $1 LIMI\e[0m\n\
  27. \e[0;36mT $2\e[0m [[\"id\", 2], [\"L\n\
  28. IMIT\", 1]]", "\
  29. \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]]",
  30. 20)
  31. end
  32. private
  33. def assert_wrap(expectation, text, length, prefix = '')
  34. assert_equal(expectation, prefix+Wrapper.wrap(text, prefix, length - prefix.length))
  35. test_with_style(text, length, prefix)
  36. end
  37. def test_with_style(text, length, prefix = '')
  38. puts "#{BEGINT}#{prefix}#{text}\e[0m"
  39. puts "#{ENDOFT}#{prefix}#{Wrapper.wrap(text, prefix, length - prefix.length)}\e[0m"
  40. puts
  41. end
  42. end