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.

64 lines
2.0 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
6 months ago
10 months ago
10 months ago
10 months ago
  1. require_relative '../../lib/formatters/ansi_wrapper'
  2. require 'minitest/autorun'
  3. class Wrapper2Test < Minitest::Test
  4. def test_wrap_score
  5. assert_wrap("\
  6. ********************\e[0m\n\
  7. ********************\e[0m\n\
  8. **********\e[0m",
  9. ('*' * 50), 20)
  10. assert_wrap("\
  11. > ******************\e[0m\n\
  12. > ******************\e[0m\n\
  13. > **************\e[0m",
  14. ('*' * 50), 20, '> ')
  15. end
  16. def test_wrap_sql
  17. assert_wrap("\
  18. \e[0m\e[0;36mELECT \"scores\".* FRO\e[0m
  19. +\e[0m\e[0;36mM \"scores\" WHERE \"sc\e[0m
  20. +\e[0m\e[0;36mores\".\"id\" = $1 LIMI\e[0m
  21. +\e[0m\e[0;36mT $2\e[0m [[\"id\", 2], [\"L
  22. IMIT\", 1]]
  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. # def test_carriage_return
  33. # assert_wrap('text', "text\n\n", 10)
  34. # assert_wrap('first ', "first \n", 10)
  35. # assert_wrap('first ', "first \n", 10)
  36. # assert_wrap('first ', "first \n", 10)
  37. # assert_wrap("first \n second ", "first\n second\n", 10)
  38. # assert_wrap("\e[0;35mhello\e[0m \n\e[0;35m\e[0m\n\e[0;35myop", "\e[0;35mhello\n\nyop", 10)
  39. # end
  40. private
  41. def assert_wrap(expectation, text, length, prefix = '')
  42. show_with_style(text, length, prefix)
  43. assert_equal(expectation, prefix + AnsiWrapper.wrap(text, length - prefix.length, prefix))
  44. end
  45. def show_with_style(text, length, prefix = '')
  46. expectation = AnsiWrapper.wrap(text, length - prefix.length, prefix)
  47. puts "original_o is:\n#{prefix}[#{text}]\e[0m"
  48. puts "original_i is:\n#{prefix}[#{text.inspect}]\e[0m"
  49. puts
  50. puts "final_o is:\n#{prefix}[#{expectation}]\e[0m"
  51. puts "final_i is:\n#{prefix}[#{expectation.inspect}]\e[0m"
  52. puts
  53. end
  54. end