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