PageRenderTime 15ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/test/lib/string/test_substring.e

http://github.com/tybor/Liberty
Specman e | 102 lines | 74 code | 7 blank | 21 comment | 1 complexity | 9f28bb3cfa6295fe9c49e6f790ed8958 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_SUBSTRING
  5
  6create {}
  7   make
  8
  9feature {ANY}
 10   make
 11      local
 12         s1, s2: STRING
 13      do
 14         s1 := "123"
 15         s2 := s1.substring(1, 1)
 16         assert(s2.count = 1)
 17         assert(("1").is_equal(s2))
 18         s2 := s1.substring(2, 2)
 19         assert(("2").is_equal(s2))
 20         s2 := s1.substring(3, 3)
 21         assert(("3").is_equal(s2))
 22         s2 := s1.substring(2, 3)
 23         assert(("23").is_equal(s2))
 24         s2 := s1.substring(1, 3)
 25         assert(("123").is_equal(s2))
 26         s2 := s1.substring(1, 2)
 27         assert(("12").is_equal(s2))
 28         s2 := s1.substring(1, 0)
 29         assert(("").is_equal(s2))
 30         s2 := s1.substring(2, 1)
 31         assert(("").is_equal(s2))
 32         s2 := s1.substring(3, 2)
 33         assert(("").is_equal(s2))
 34         s2 := s1.substring(4, 3)
 35         assert(("").is_equal(s2))
 36         s1 := "1"
 37         s2 := s1.substring(1, 1)
 38         assert(("1").is_equal(s2))
 39         s2 := s1.substring(1, 0)
 40         assert(("").is_equal(s2))
 41         s2 := s1.substring(2, 1)
 42         assert(("").is_equal(s2))
 43         s1 := ""
 44         s2 := s1.substring(1, 0)
 45         assert(("").is_equal(s2))
 46
 47         s1 := "1234"
 48         s1.insert_string("XY", 3)
 49         assert(("12XY34").is_equal(s1))
 50         s1 := "1234567"
 51         s1.remove_first
 52         s1.insert_string("X", 4)
 53         assert(("234X567").is_equal(s1))
 54         s1 := "1234567"
 55         s1.remove_first
 56         s1.remove_first
 57         s1.remove_first
 58         s1.remove_first
 59         s1.insert_string("X", 2)
 60         assert(("5X67").is_equal(s1))
 61         s1 := "1234567"
 62         s1.remove_first
 63         s1.remove_first
 64         s1.insert_string("XYZ", 3)
 65         assert(("34XYZ567").is_equal(s1))
 66
 67         assert(("1234567890" ^ ({INTEGER 4} |..| {INTEGER 6}))~"456")
 68      end
 69
 70feature {}
 71   assert (bool: BOOLEAN)
 72      do
 73         cpt := cpt + 1
 74         if not bool then
 75            std_output.put_string("TEST_SUBSTRING: ERROR Test # ")
 76            std_output.put_integer(cpt)
 77            std_output.put_string("%N")
 78            crash
 79         end
 80      end
 81
 82   cpt: INTEGER
 83
 84end -- class TEST_SUBSTRING
 85--
 86-- ------------------------------------------------------------------------------------------------------------------------------
 87-- Copyright notice below. Please read.
 88--
 89-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
 90-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
 91-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
 92-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
 93-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
 94-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 95--
 96-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
 97-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
 98--
 99-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
100--
101-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
102-- ------------------------------------------------------------------------------------------------------------------------------