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.

45 lines
1.3 KiB

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