/test/lib/regular_expression/test_substitute_01.e

http://github.com/tybor/Liberty · Specman e · 101 lines · 58 code · 17 blank · 26 comment · 0 complexity · 58b8fc6cfa65ca1633f7bb215d2e04c0 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_SUBSTITUTE_01
  5. --
  6. -- Testing:
  7. -- prepare_substitution
  8. -- substitute_for
  9. -- substitute_all_for
  10. insert
  11. EIFFELTEST_TOOLS
  12. create {}
  13. make
  14. feature {}
  15. make
  16. local
  17. aa_matcher: REGULAR_EXPRESSION
  18. do
  19. create {AUX_SUBSTITUTE_01} aa_matcher
  20. aa_matcher.prepare_substitution("\1bc")
  21. assert(not aa_matcher.match(text1))
  22. assert(aa_matcher.match(text2))
  23. aa_matcher.substitute_for(text2)
  24. assert(aa_matcher.last_substitution.is_equal(sub2))
  25. assert(aa_matcher.match(text3))
  26. aa_matcher.substitute_for(text3)
  27. assert(aa_matcher.last_substitution.is_equal(sub3))
  28. assert(aa_matcher.match(text4))
  29. aa_matcher.substitute_for(text4)
  30. assert(aa_matcher.last_substitution.is_equal(sub4))
  31. assert(aa_matcher.match(text5))
  32. aa_matcher.substitute_for(text5)
  33. assert(aa_matcher.last_substitution.is_equal(sub5))
  34. assert(aa_matcher.match(text6))
  35. aa_matcher.substitute_for(text6)
  36. assert(aa_matcher.last_substitution.is_equal(sub6))
  37. aa_matcher.substitute_all_for(text1)
  38. assert(aa_matcher.last_substitution.is_equal(text1))
  39. aa_matcher.substitute_all_for(text2)
  40. assert(aa_matcher.last_substitution.is_equal(sub2))
  41. aa_matcher.substitute_all_for(text3)
  42. assert(aa_matcher.last_substitution.is_equal(sub3))
  43. aa_matcher.substitute_all_for(text4)
  44. assert(aa_matcher.last_substitution.is_equal(sub4))
  45. aa_matcher.substitute_all_for(text5)
  46. assert(aa_matcher.last_substitution.is_equal(sub5))
  47. aa_matcher.substitute_all_for(text6)
  48. assert(aa_matcher.last_substitution.is_equal(suball6))
  49. assert(aa_matcher.match_from(text6, 2))
  50. aa_matcher.substitute_for(text6)
  51. assert(aa_matcher.last_substitution.is_equal(subfrom6))
  52. end
  53. text1: STRING "Little message without the pattern."
  54. text2: STRING "aa apears one time in the begining."
  55. text3: STRING "The pattern aa in the middle."
  56. text4: STRING "Here in the end aa"
  57. text5: STRING "aa"
  58. text6: STRING "aa pattern appears many times aa in the string."
  59. sub2: STRING "abc apears one time in the begining."
  60. sub3: STRING "The pattern abc in the middle."
  61. sub4: STRING "Here in the end abc"
  62. sub5: STRING "abc"
  63. sub6: STRING "abc pattern appears many times aa in the string."
  64. suball6: STRING "abc pattern appears many times abc in the string."
  65. subfrom6: STRING "aa pattern appears many times abc in the string."
  66. end -- class TEST_SUBSTITUTE_01
  67. --
  68. -- ------------------------------------------------------------------------------------------------------------------------------
  69. -- Copyright notice below. Please read.
  70. --
  71. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  72. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  73. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  74. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  75. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  76. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  77. --
  78. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  79. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  80. --
  81. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  82. --
  83. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  84. -- ------------------------------------------------------------------------------------------------------------------------------