/test/lib/string/test_rope.e

http://github.com/tybor/Liberty · Specman e · 94 lines · 77 code · 16 blank · 1 comment · 1 complexity · 11fb42e146ca26f1a7d64d0581224f7c MD5 · raw file

  1. class TEST_ROPE
  2. insert
  3. EIFFELTEST_TOOLS
  4. create {}
  5. make
  6. feature {}
  7. make
  8. local
  9. a,b: STRING
  10. r: ROPE
  11. ai, ri: ITERATOR[CHARACTER]
  12. outcome: STRING; ss: STRING_OUTPUT_STREAM
  13. do
  14. a:="A-"+"rope"+"-is-beautiful"
  15. r:="A-"|"rope"|"-is-beautiful"
  16. assert(a.count = r.count)
  17. assert(a.is_equal(r))
  18. assert(r.is_equal(a))
  19. from
  20. ai := a.new_iterator; ai.start
  21. ri := r.new_iterator; ri.start
  22. until
  23. ai.is_off or else ri.is_off
  24. loop
  25. assert(ai.item = ri.item)
  26. ai.next; ri.next
  27. end
  28. assert(ai.is_off and then ri.is_off)
  29. create outcome.make_empty
  30. create ss.connect_to(outcome)
  31. r.print_on(ss)
  32. assert(outcome~"A-rope-is-beautiful")
  33. outcome.clear_count
  34. from ri:=r.new_iterator; ri.start; until ri.is_off
  35. loop ss.put_character(ri.item); ri.next
  36. end
  37. assert(outcome~"A-rope-is-beautiful")
  38. assert(r.count=19)
  39. assert(not r.has(' '))
  40. assert(r.has('-'))
  41. assert(not r.valid_index(r.first_index_of(' ')))
  42. assert(r.valid_index(r.first_index_of('-')))
  43. outcome.clear_count;
  44. ("The rope «"+r+"» does not have spaces.").print_on(ss)
  45. assert(outcome~"The rope «A-rope-is-beautiful» does not have spaces.")
  46. outcome.clear_count;
  47. ("The rope «"|r|"» does not have spaces.").print_on(ss)
  48. assert(outcome~"The rope «A-rope-is-beautiful» does not have spaces.")
  49. outcome.clear_count;
  50. ("Foo is "|(3.out)|" characters long%N").print_on(ss)
  51. assert(outcome~"Foo is 3 characters long%N")
  52. assert(("Rope r is "+r.count.to_string+" characters long.").is_equal("Rope r is 19 characters long."))
  53. assert(("Rope r is "|r.count.to_string|" characters long.").is_equal("Rope r is 19 characters long."))
  54. assert(("Rope r is "| &r.count |" characters long.").is_equal("Rope r is 19 characters long."))
  55. assert(not ("Failing equality").is_equal("Test-"|"equality"))
  56. assert(("Test-"|"equality").is_equal("Test-"|"equality"))
  57. assert(not ("Failing"|"equality").is_equal("Test-"|"equality"))
  58. assert(("Test"|"-equality").is_equal("Test-equality"))
  59. assert(("Test"|"-equality").is_equal("Test-equ"|"ality"))
  60. assert(not ("Failing-"|"equality").is_equal("equality"))
  61. assert(("Foo is "|foo.count.out|" characters long.").is_equal("Foo is 3 characters long."))
  62. assert(("Foo is "| &foo.count |" characters long.").is_equal("Foo is 3 characters long."))
  63. assert(("Ropes are "|("beautiful".intern)).is_equal("Ropes are beautiful"))
  64. assert(("Ropes are "|("beautiful".intern)).is_equal("Ropes are beautiful".intern))
  65. -- Test mutable ROPEs
  66. a := "Eiffel"
  67. b := "beautiful"
  68. r := a|" is "|b
  69. assert(r.is_equal("Eiffel is beautiful"))
  70. a.prepend("Liberty")
  71. assert(r.is_equal("LibertyEiffel is beautiful"))
  72. b.append(" programming language.")
  73. assert(r.is_equal("LibertyEiffel is beautiful programming language."))
  74. b.prepend("a ")
  75. assert(r.is_equal("LibertyEiffel is a beautiful programming language."))
  76. end
  77. foo: STRING "Foo"
  78. end -- class TEST_ROPE