/test/lib/string/test_string1.e
Specman e | 177 lines | 146 code | 5 blank | 26 comment | 0 complexity | c547041cc34b3bbef4447ff3ad312cd2 MD5 | raw file
1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries. 2-- See the Copyright notice at the end of this file. 3-- 4class TEST_STRING1 5 6insert 7 EIFFELTEST_TOOLS 8 9create {} 10 make 11 12feature {ANY} 13 make 14 local 15 s, s2: STRING; i: INTEGER; words: ARRAY[STRING] 16 do 17 create s.make_filled(' ', 0) 18 assert(s.count = 0) 19 s.make_filled(' ', 1) 20 assert(s.count = 1) 21 assert(s.item(1) = ' ') 22 s.put('a', 1) 23 assert(s.count = 1) 24 assert(s.item(1) = 'a') 25 create s.make_filled(' ', 4) 26 assert(s.count = 4) 27 from 28 i := 1 29 until 30 i > s.count 31 loop 32 assert(s.item(i) = ' ') 33 i := i + 1 34 end 35 assert(("").is_equal("")) 36 assert(not (" ").is_equal("")) 37 create s.make_filled(' ', 3) 38 s.put('a', 2) 39 assert((" a ").is_equal(s)) 40 assert(s.is_equal(" a ")) 41 s := "" 42 assert(s.count = 0) 43 s.extend('x') 44 assert(s.count = 1) 45 assert(s.item(1) = 'x') 46 s := "1" 47 assert(s.count = 1) 48 assert(s.item(1) = '1') 49 s.extend('x') 50 assert(s.count = 2) 51 assert(s.item(1) = '1') 52 assert(s.item(2) = 'x') 53 assert(("1x").is_equal(s)) 54 create s.make_filled(' ', 3) 55 s.put('h', 2) 56 assert((" h ").is_equal(s)) 57 s.put(' ', 2) 58 assert(not (" h ").is_equal(s)) 59 assert(s.is_equal(" ")) 60 s.make_filled(' ', 3) 61 assert(s.is_equal(" ")) 62 create s.copy("ab") 63 assert(s.count = 2) 64 assert(("ab").is_equal(s)) 65 s.copy("cdef") 66 assert(("cdef").is_equal(s)) 67 s.copy("a") 68 assert(("a").is_equal(s)) 69 s := "" 70 assert(s.count = 0) 71 create s.copy(s) 72 assert(s.count = 0) 73 s.extend('a') 74 assert(s.count = 1) 75 assert(s.item(1) = 'a') 76 s2 := "a" 77 s := s2.twin 78 assert(s.count = 1) 79 assert(s2.count = 1) 80 assert(s.item(1) = 'a') 81 s2.put('b', 1) 82 assert(s2.item(1) = 'b') 83 assert(s.item(1) = 'a') 84 s := "abc" 85 s2 := s.twin 86 assert(s.is_equal(s2)) 87 s.put('x', 2) 88 assert(not s.is_equal(s2)) 89 create s.make_filled(' ', 0) 90 assert(("").is_equal(s)) 91 create s.make_filled(' ', 2) 92 assert((" ").is_equal(s)) 93 s := "aaa" 94 s.make_filled(' ', 2) 95 assert((" ").is_equal(s)) 96 s := "" 97 assert(("").twin.is_equal(s)) 98 create s.make_filled(' ', 2) 99 assert((" ").is_equal(s)) 100 s := "aaa" 101 s.make_filled(' ', 2) 102 assert((" ").is_equal(s)) 103 assert(("abc").is_equal("abc")) 104 create s.copy("kiki") 105 assert(s.is_equal("kiki")) 106 s.copy(s) 107 assert(s.is_equal("kiki")) 108 s.copy("3") 109 assert(s.is_equal("3")) 110 create s.copy("kiki") 111 s.clear_count 112 assert(s.is_equal("")) 113 s := "123456789" 114 s.shrink(1, 7) 115 assert(("1234567").is_equal(s)) 116 s.shrink(2, 7) 117 assert(("234567").is_equal(s)) 118 assert((" +234 ").to_integer = 234) 119 assert((" -67").to_integer = -67) 120 assert((" +234 ").to_integer_64 = 234) 121 assert((" -67").to_integer_64 = -67) 122 assert(("+234.0").to_real = 234.0) 123 assert(("+1234").to_real = 1234.0) 124 assert((" +234.22").to_real <= 234.221) 125 assert((" +234.22").to_real >= 234.219) 126 assert((" -67.0 %N").to_real = -67) 127 assert((".5").to_real = 0.5) 128 assert(("0.5").to_real = 0.5) 129 -- *** std_output.put_string("Min%N") 130 -- THERE IS HERE A STRANGE BUG ONLY IN gcc -O3 ???? 131 -- D.Colnet 9 feb 2003 132 -- *** 133 -- *** std_output.put_string("Max%N") 134 assert(str1.is_equal(str2)) 135 assert(str1 /= str2) 136 create s.make(10) 137 assert(s.count = 0) 138 assert(s.capacity >= 10) 139 words := ("un machin").split 140 assert(words.count = 2) 141 assert(words.is_equal({ARRAY[STRING] 1, << "un", "machin" >> })) 142 words := (" un machin ").split 143 assert(words.is_equal({ARRAY[STRING] 1, << "un", "machin" >> })) 144 assert(" un machin ".split.is_equal({ARRAY[STRING] 1, << "un", "machin" >> })) 145 assert((" ").split = Void) 146 assert(("%/32/").first = ' ') 147 assert(("%/122/").first = 'z') 148 assert(("%/123/").first = '{') 149 assert(("%/92/").first = '%/92/') 150 assert(("%/92/").first = '\') 151 assert(("%/92/").first = '%H') 152 assert(("\").first = '%H') 153 assert((" -67 ").to_real = -67) 154 assert((" -67 ").to_real = -67) 155 end 156 157 str1,str2: STRING "Ouupps ..." 158 159end -- class TEST_STRING1 160-- 161-- ------------------------------------------------------------------------------------------------------------------------------ 162-- Copyright notice below. Please read. 163-- 164-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 165-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 166-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 167-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 168-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 169-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 170-- 171-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 172-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 173-- 174-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 175-- 176-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 177-- ------------------------------------------------------------------------------------------------------------------------------