/test/lib/regular_expression/test_python_syntax_01.e

http://github.com/tybor/Liberty · Specman e · 89 lines · 66 code · 9 blank · 14 comment · 0 complexity · a2f6a06c9f99e79eb3c4e5bee26111c5 MD5 · raw file

  1. -- This file is part of Liberty Eiffel.
  2. --
  3. -- Liberty Eiffel is free software: you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation, version 3 of the License.
  6. --
  7. -- Liberty Eiffel is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  14. --
  15. class TEST_PYTHON_SYNTAX_01
  16. insert
  17. EIFFELTEST_TOOLS
  18. create {}
  19. make
  20. feature {}
  21. make
  22. local
  23. pattern: REGULAR_EXPRESSION
  24. text, data: STRING
  25. do
  26. pattern := re.convert_python_pattern("a+(?P=foo)")
  27. assert(pattern = Void)
  28. assert(re.last_error_message.is_equal("Error at position 10: undefined named group."))
  29. assert(re.last_error_position = 10)
  30. pattern := re.convert_python_pattern("^(?P<foo>a+)(?P=foo)$")
  31. assert(pattern /= Void)
  32. assert(not pattern.match("aaa"))
  33. text := "aaaa"
  34. assert(pattern.match(text))
  35. assert(pattern.group_names.count = 1)
  36. assert(pattern.group_names.first.is_equal("foo"))
  37. assert(pattern.has_group_name("foo"))
  38. assert(not pattern.has_group_name("bar"))
  39. assert(pattern.ith_group_matched(0))
  40. assert(pattern.named_group_matched("foo"))
  41. data := ""
  42. pattern.append_named_group(text, data, "foo")
  43. assert(data.is_equal("aa"))
  44. pattern := re.convert_python_pattern("^(?P<foo>a+?)(?P=foo)$")
  45. assert(pattern /= Void)
  46. assert(not pattern.match("aaa"))
  47. text := "aaaa"
  48. assert(pattern.match(text))
  49. assert(pattern.group_names.count = 1)
  50. assert(pattern.group_names.first.is_equal("foo"))
  51. assert(pattern.has_group_name("foo"))
  52. assert(not pattern.has_group_name("bar"))
  53. assert(pattern.ith_group_matched(0))
  54. assert(pattern.named_group_matched("foo"))
  55. data := ""
  56. pattern.append_named_group(text, data, "foo")
  57. assert(data.is_equal("aa"))
  58. pattern := re.convert_python_pattern("^(?P<foo>a+b)(?P=foo)$")
  59. assert(pattern /= Void)
  60. assert(not pattern.match("aaaabab"))
  61. text := "aaabaaab"
  62. assert(pattern.match(text))
  63. assert(pattern.group_names.count = 1)
  64. assert(pattern.group_names.first.is_equal("foo"))
  65. assert(pattern.has_group_name("foo"))
  66. assert(not pattern.has_group_name("bar"))
  67. assert(pattern.ith_group_matched(0))
  68. assert(pattern.named_group_matched("foo"))
  69. data := ""
  70. pattern.append_named_group(text, data, "foo")
  71. assert(data.is_equal("aaab"))
  72. pattern.for_all_matched_named_groups(text, agent compare_group_text("foo", ?, "aaab", ?))
  73. end
  74. compare_group_text (expected_group: STRING; actual_group: FIXED_STRING; expected_data: STRING; actual_data: STRING)
  75. do
  76. assert(expected_group.is_equal(actual_group))
  77. assert(expected_data.is_equal(actual_data))
  78. end
  79. re: REGULAR_EXPRESSION_BUILDER
  80. end -- class TEST_PYTHON_SYNTAX_01