aboutsummaryrefslogtreecommitdiff
path: root/tests/test_core.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-14 21:29:31 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-14 21:29:31 -0800
commit4e21fffe3f824247dceba0af38d36996afad2c13 (patch)
tree926a0d75f4826642d393c0c918c63bd47eecdca4 /tests/test_core.py
parent1cdb5b33158a12f950b2def5a6cbf7dddb49b07e (diff)
parenteee1dad79e3f4736c10be166ced7f62b082289f4 (diff)
Merge branch 'regex-impl' of github.com:waywardmonkeys/emscripten into incoming1.7.6
Conflicts: tools/shared.py
Diffstat (limited to 'tests/test_core.py')
-rw-r--r--tests/test_core.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index c0196a35..545bb63f 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2205,6 +2205,49 @@ returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie',
'''
self.do_run(src, 'wcslen: 5')
+ def test_regex(self):
+ # This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm
+ if self.emcc_args is None: return self.skip('needs emcc for libcextra')
+ src = r'''
+ #include <regex.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main(void)
+ {
+ regex_t preg;
+ const char *string = "a very simple simple simple string";
+ const char *pattern = "\\(sim[a-z]le\\) \\1";
+ int rc;
+ size_t nmatch = 2;
+ regmatch_t pmatch[2];
+
+ if (0 != (rc = regcomp(&preg, pattern, 0))) {
+ printf("regcomp() failed, returning nonzero (%d)\n", rc);
+ exit(EXIT_FAILURE);
+ }
+
+ if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) {
+ printf("Failed to match '%s' with '%s',returning %d.\n",
+ string, pattern, rc);
+ }
+ else {
+ printf("With the whole expression, "
+ "a matched substring \"%.*s\" is found at position %d to %d.\n",
+ pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so],
+ pmatch[0].rm_so, pmatch[0].rm_eo - 1);
+ printf("With the sub-expression, "
+ "a matched substring \"%.*s\" is found at position %d to %d.\n",
+ pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so],
+ pmatch[1].rm_so, pmatch[1].rm_eo - 1);
+ }
+ regfree(&preg);
+ return 0;
+ }
+ '''
+ self.do_run(src, 'With the whole expression, a matched substring "simple simple" is found at position 7 to 19.\n'
+ 'With the sub-expression, a matched substring "simple" is found at position 7 to 12.')
+
def test_longjmp(self):
src = r'''
#include <stdio.h>