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