]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/regexp/regexp-tests.factor
regexp: fix case-insensitive lookahead and lookbehind.
[factor.git] / basis / regexp / regexp-tests.factor
index 2d981c8c2ca7edc9fc8206d935bdf3a92e9edb12..cdbe7742efcfa05435ddf2545c2d307ad25ae380 100644 (file)
@@ -1,6 +1,6 @@
 USING: arrays regexp tools.test kernel sequences regexp.parser
 regexp.private eval strings multiline accessors ;
-IN: regexp-tests
+IN: regexp.tests
 
 { f } [ "b" "a*" <regexp> matches? ] unit-test
 { t } [ "" "a*" <regexp> matches? ] unit-test
@@ -49,6 +49,9 @@ IN: regexp-tests
 { t } [ "a" ".+" <regexp> matches? ] unit-test
 { t } [ "ab" ".+" <regexp> matches? ] unit-test
 
+{ t } [ "\0" "[\\0]" <regexp> matches? ] unit-test
+{ f } [ "0" "[\\0]" <regexp> matches? ] unit-test
+
 { t } [ " " "[\\s]" <regexp> matches? ] unit-test
 { f } [ "a" "[\\s]" <regexp> matches? ] unit-test
 { f } [ " " "[\\S]" <regexp> matches? ] unit-test
@@ -60,7 +63,7 @@ IN: regexp-tests
 
 { t } [ "/" "\\/" <regexp> matches? ] unit-test
 
-{ t } [ "a" R' a'i matches? ] unit-test
+{ t } [ "a" R/ a/i matches? ] unit-test
 
 { t } [ "" "a|b*|c+|d?" <regexp> matches? ] unit-test
 { t } [ "a" "a|b*|c+|d?" <regexp> matches? ] unit-test
@@ -259,11 +262,11 @@ IN: regexp-tests
 ! Comment inside a regular expression
 { t } [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
 
-{ } [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval( -- ) ] unit-test
+{ } [ "USING: regexp kernel ; R/ -{3}[+]{1,6}(?:!!)?\\s/ drop" eval( -- ) ] unit-test
 
-{ } [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval( -- ) ] unit-test
+{ } [ "USING: regexp kernel ; R/ (ftp|http|https):\\/\\/(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(\\/\\|\\/([\\w#!:.?+=&%@!\\-\\/]))?/ drop" eval( -- ) ] unit-test
 
-{ } [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval( -- ) ] unit-test
+{ } [ "USING: regexp kernel ; R/ \\*[^\s*][^*]*\\*/ drop" eval( -- ) ] unit-test
 
 { "ab" } [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
 { "abc" } [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
@@ -335,6 +338,10 @@ unit-test
 { "XhXXlXlXoX XwXoXrXlXdX" } [ "hello world" R/ e*/ "X" re-replace ] unit-test
 { "-- title --" } [ "== title ==" R/ =/ "-" re-replace ] unit-test
 
+{ "abc" } [ "a/   \\bc" "/.*\\" <regexp> "" re-replace ] unit-test
+{ "ac" } [ "a/   \\bc" R/ \/.*\\./ "" re-replace ] unit-test
+{ "abc" } [ "a/   \\bc" R/ \/.*\\/ "" re-replace ] unit-test
+
 { "" } [ "ab" "a(?!b)" <regexp> first-match >string ] unit-test
 { "a" } [ "ac" "a(?!b)" <regexp> first-match >string ] unit-test
 { t } [ "fxxbar" ".{3}(?!foo)bar" <regexp> matches? ] unit-test
@@ -349,7 +356,7 @@ unit-test
 { f } [ "foobxr" "foo(?=bar)" <regexp> first-match ] unit-test
 
 ! Bug in parsing word
-{ t } [ "a" R' a' matches? ] unit-test
+{ t } [ "a" R/ a/ matches? ] unit-test
 
 ! Testing negation
 { f } [ "a" R/ (?~a)/ matches? ] unit-test
@@ -506,6 +513,9 @@ unit-test
 
 { 3 } [ "caba" "(?<=b)a" <regexp> first-match from>> ] unit-test
 
+{ "<" } [ "<style>" R/ <(?=STYLE\b)/i first-match >string ] unit-test
+{ "bar" } [ "foobar" R/ (?<=FOO)BAR/i first-match >string ] unit-test
+
 { t } [ "\ra" R/ .^a/ms matches? ] unit-test
 { f } [ "\ra" R/ .^a/mds matches? ] unit-test
 { t } [ "\na" R/ .^a/ms matches? ] unit-test