Author: fperrad
Date: Sat Mar  3 07:23:02 2007
New Revision: 17308

Modified:
   trunk/languages/lua/t/alarm.t
   trunk/languages/lua/t/regex.t
   trunk/languages/lua/t/rx_captures
   trunk/languages/lua/t/rx_charclass
   trunk/languages/lua/t/rx_metachars
   trunk/languages/lua/t/string.t

Log:
[Lua]
- add tests (regex)

Modified: trunk/languages/lua/t/alarm.t
==============================================================================
--- trunk/languages/lua/t/alarm.t       (original)
+++ trunk/languages/lua/t/alarm.t       Sat Mar  3 07:23:02 2007
@@ -22,9 +22,16 @@
 use FindBin;
 use lib "$FindBin::Bin";
 
-use Parrot::Test tests => 6;
+use Parrot::Test;
 use Test::More;
 
+if ( exists $ENV{PARROT_LUA_TEST_PROG} ) {
+    plan skip_all => "parrot only";
+}
+else {
+    plan tests => 6;
+}
+
 language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function alarm' );
 require "alarm"
 print(type(alarm))

Modified: trunk/languages/lua/t/regex.t
==============================================================================
--- trunk/languages/lua/t/regex.t       (original)
+++ trunk/languages/lua/t/regex.t       Sat Mar  3 07:23:02 2007
@@ -68,15 +68,23 @@
         next if (/^\s*$/);
         my ($pattern, $target, $result, $desc) = split /\t+/, $_;
         $pattern = '' if ($pattern eq "''");
+        $pattern =~ s/"/\\"/g;
         $target = '' if ($target eq "''");
+        $target =~ s/"/\\"/g;
+        $result = '' if ($result eq "''");
         my $output = $result;
         $output =~ s/\\f/\f/g;
         $output =~ s/\\n/\n/g;
         $output =~ s/\\r/\r/g;
         $output =~ s/\\t/\t/g;
+        $output =~ s/\\01/\01/g;
+        $output =~ s/\\02/\02/g;
+        $output =~ s/\\03/\03/g;
+        $output =~ s/\\04/\04/g;
+        $output =~ s/\\0/\0/g;
         $test_number ++;
 
-        my $code = "print(string.match('$target', '$pattern'))";
+        my $code = "print(string.match(\"$target\", \"$pattern\"))";
         if ($output =~ /^\//) {
             language_output_like( 'lua', $code, $output . "\n", $desc );
         }

Modified: trunk/languages/lua/t/rx_captures
==============================================================================
--- trunk/languages/lua/t/rx_captures   (original)
+++ trunk/languages/lua/t/rx_captures   Sat Mar  3 07:23:02 2007
@@ -1,5 +1,12 @@
 (a.)..(..)             zzzabcdefzzz    ab\tef                  basic match

 (a(b(c))(d))           abcd            abcd\tbc\tc\td          nested match

 ((%w+))                        abcd            abcd\tabcd              nested 
match

+(a*(.)%w(%s*))         aa!b c          aa!b \t!\t              nested match

+(a?)..                 abcd            a                       opt

+(A?)..                 abcd            ''                      opt

+()aa()                 flaaap          3\t5                    empty capture

+(.)%1                  bookkeeper      o                       backreference

+(%w+)%s+%1             hello hello     hello                   backreference

+(.*)x                  123x            123                     repeated dot 
capture

 

 ## vim: noexpandtab tabstop=4 shiftwidth=4


Modified: trunk/languages/lua/t/rx_charclass
==============================================================================
--- trunk/languages/lua/t/rx_charclass  (original)
+++ trunk/languages/lua/t/rx_charclass  Sat Mar  3 07:23:02 2007
@@ -12,7 +12,6 @@
 [b-d]                  axxxef          nil             character range

 [^b-d]                 abcdef          a               negated character range

 [^b-d]                 bbccdd          nil             negated character range

-#[^d-b]                        bbccdd          nil             negated 
(illegal) character range

 [-]                    ab-def          -               unescaped hyphen

 [%-]                   ab-def          -               escaped hyphen

 [%-]                   abcdef          nil             escaped hyphen

@@ -31,12 +30,8 @@
 ["\\]                  \\              \               escaped backslash

 [%]]                   ]               ]               escaped close bracket

 [%]                    \\]]            /malformed pattern/     unescaped 
backslash (or no closing brace)

-ab\'>cd                        ab\'>cd         ab'>cd          literal match 
with quote

 ab\\cd                 ab\092cd        ab\cd           literal match with 
backslash

 %?                     ab<?            ?               literal match with 
question mark

-<                      ab<?            <               literal match with lt

-<%?                    ab<?            <?              literal match with lt 
and question mark

-<%?                    ab<x?           nil             non-matching literal 
match with lt and question mark#

 [A-Z0-9]               abcdef          nil             two enumerated ranges

 [A-Z0-9]               abcDef          D               two enumerated ranges

 


Modified: trunk/languages/lua/t/rx_metachars
==============================================================================
--- trunk/languages/lua/t/rx_metachars  (original)
+++ trunk/languages/lua/t/rx_metachars  Sat Mar  3 07:23:02 2007
@@ -15,14 +15,11 @@
 def$\nabc              def\nabc        nil             start and end of string 
(^)

 abc\n$                 abc\n           abc\n           end of string ($)

 abc$                   abc\n           nil             end of string ($)

-c\nd                   abc\ndef        c\nd            logical newline (\n)

-c\nd                   abc\010def      c\nd            logical newline (\n)

-#c\nd                  abc\013def      c\nd            logical newline (\n)

-c\n+d                  abc\n\ndef      c\n\nd          logical newline (\n)

-a\n+f                  abcdef          nil             logical newline (\n)

-c\nd                   abc\010\013def  nil             logical newline (\n)

-#c\nd                  abc\013\010def  c\nd            logical newline (\n)

-b\nc                   abc\ndef        nil             logical newline (\n)

+c\nd                   abc\ndef        c\nd            newline (\n)

+c\nd                   abc\010def      c\nd            newline (\n)

+c\n+d                  abc\n\ndef      c\n\nd          newline (\n)

+a\n+f                  abcdef          nil             newline (\n)

+b\nc                   abc\ndef        nil             newline (\n)

 c\td                   abc\tdef        c\td            horizontal tab (\t)

 c\td                   abc\09def       c\td            horizontal tab (\t)

 c\t+d                  abc\t\tdef      c\t\td          horizontal tab (\t)

@@ -43,6 +40,24 @@
 c\033+d                        abc!!def        c!!d            dec (\0)

 a\033+f                        abcdef          nil             dec (\0)

 b\033c                 abc!def         nil             dec (\0)

+a%^d                   a^d             a^d             escaped (useless)

+a^d                    a^d             a^d             not escaped

+%^d                    ^d              ^d              escaped

+a%$d                   a$d             a$d             escaped (useless)

+a$d                    a$d             a$d             not escaped

+a%$                    a$              a$              escaped

+a%(d                   a(d             a(d             escaped

+a%)d                   a)d             a)d             escaped

+a%%d                   a%d             a%d             escaped

+a%.d                   a.d             a.d             escaped

+a%.d                   abd             nil             escaped

+a%[d                   a[d             a[d             escaped

+a%]d                   a]d             a]d             escaped

+a%*d                   a*d             a*d             escaped

+a%+d                   a+d             a+d             escaped

+a%-d                   a-d             a-d             escaped

+a%?d                   a?d             a?d             escaped

+a%yd                   ayd             ayd             escaped

 a%w+f                  a=[ *f          nil             word character

 a%w+f                  abcdef          abcdef          word character

 a%W+f                  a&%- f          a&%- f          not word character

@@ -51,5 +66,37 @@
 ab%d+cdef              ab42cdef        ab42cdef        digit

 a%D+f                  abcdef          abcdef          not digit

 a%D+f                  ab0cdef         nil             not digit

+a%l+f                  aBCDEf          nil             lowercase letter

+a%l+f                  abcdef          abcdef          lowercase letter

+a%L+f                  a&2D f          a&2D f          not lowercase letter

+a%L+f                  aBCdEf          nil             not lowercase letter

+a%u+f                  abcdef          nil             uppercase letter

+a%u+f                  aBCDEf          aBCDEf          uppercase letter

+a%U+f                  a&2d f          a&2d f          not uppercase letter

+a%U+f                  a&2D f          nil             not uppercase letter

+a%a+f                  aBcDef          aBcDef          all letter

+a%a+f                  a=[ *f          nil             all letter

+a%A+f                  a&%- f          a&%- f          not all letter

+a%A+f                  abcdef          nil             not all letter

+a%p+f                  abcdef          nil             ponctuation

+a%p+f                  a,;:!f          a,;:!f          ponctuation

+a%P+f                  abcdef          abcdef          not ponctuation

+a%P+f                  adc:ef          nil             not ponctuation

+a%c+f                  abcdef          nil             control character

+a%c+f                  a\04\03\02f     a\04\03\02f     control character

+a%C+f                  abcdef          abcdef          not control character

+a%C+f                  abc\01ef        nil             not control character

+a%x+f                  axyzef          nil             hexadecimal

+a%x+f                  ab3Def          ab3Def          hexadecimal

+a%X+f                  abcdef          nil             not hexadecimal

+a%X+f                  axy;Zf          axy;Zf          not hexadecimal

+a%z+f                  abcdef          nil             zero

+a%z+f                  a\0f            a               zero

+a%Z+f                  abcdef          abcdef          not zero

+a%Z+f                  abc\0ef         nil             not zero

+a%b()f                 a(bcde)f        a(bcde)f        balanced

+a%b()f                 a(b(de)f        nil             balanced

+a%b()f                 a(b(d)e)f       a(b(d)e)f       balanced

+a%b''f                 a'bcde'f        a'bcde'f        balanced

 

 ## vim: noexpandtab tabstop=4 shiftwidth=4


Modified: trunk/languages/lua/t/string.t
==============================================================================
--- trunk/languages/lua/t/string.t      (original)
+++ trunk/languages/lua/t/string.t      Sat Mar  3 07:23:02 2007
@@ -27,7 +27,7 @@
 use FindBin;
 use lib "$FindBin::Bin";
 
-use Parrot::Test tests => 33;
+use Parrot::Test tests => 34;
 use Test::More;
 
 language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function string.byte' );
@@ -377,6 +377,24 @@
 name   Anna
 OUTPUT
 
+TODO: {
+    local $TODO = 'back reference';
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function string.match 
(back ref)' );
+s = [[then he said: "it's all right"!]]
+q, quotedPart = string.match(s, "([\"'])(.-)%1")
+print(quotedPart)
+print(q)
+p = "%[(=*)%[(.-)%]%1%]"
+s = "a = [=[[[ something ]] ]==]x]=]; print(a)"
+print(string.match(s, p))
+CODE
+it's all right
+"
+=      [[ something ]] ]==]x
+OUTPUT
+}
+
 language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function string.rep' );
 print(string.rep("ab", 3))
 print(string.rep("ab", 0))

Reply via email to