Author: particle
Date: Tue Apr 25 20:12:38 2006
New Revision: 12432

Modified:
   trunk/runtime/parrot/library/Test/More.pir
   trunk/t/library/test_more.t

Log:
[Test/More.pir]
~ added like() doc, code and tests

Modified: trunk/runtime/parrot/library/Test/More.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/More.pir  (original)
+++ trunk/runtime/parrot/library/Test/More.pir  Tue Apr 25 20:12:38 2006
@@ -13,15 +13,17 @@
     .local pmc ok
     .local pmc is
     .local pmc is_deeply
+    .local pmc like
 
     plan      = find_global 'Test::More', 'plan'
     diag      = find_global 'Test::More', 'diag'
-    ok        = find_global 'Test::More',   'ok'
-    is        = find_global 'Test::More',   'is'
-    is_deeply = find_global 'Test::More',   'is_deeply'
+    ok        = find_global 'Test::More', 'ok'
+    is        = find_global 'Test::More', 'is'
+    is_deeply = find_global 'Test::More', 'is_deeply'
+    like      = find_global 'Test::More', 'like'
 
     # set a test plan
-    plan( 11 )
+    plan( 12 )
 
     # run your tests
     ok( 1 )
@@ -41,11 +43,13 @@
     diag( 'this may take a while' )
     is_deeply( some_deep_pmc, another_deep_pmc, 'deep structure comparison' )
 
+    like( 'foo', 'f o**{2}', 'passing regex compare with diagnostic' )
+
 =head1 DESCRIPTION
 
 C<Test::More> is a pure-Parrot library for testing modules.  It provides
-the C<ok()>, C<is()>, and C<is_deeply()> comparison functions for you.  It
-also provides the C<plan()> and C<diag()> helper functions. It uses
+the C<ok()>, C<is()>, C<is_deeply()>, and C<like()> comparison functions for
+you.  It also provides the C<plan()> and C<diag()> helper functions. It uses
 C<Test::Builder>, a simple, single backend for multiple test modules
 to use within your tests.
 
@@ -352,6 +356,63 @@
     .return( 1 )
 .end
 
+=item C<like( target, pattern, description )>
+
+Similar to is, but using the Parrot Grammar Engine to compare the string
+passed as C<target> to the pattern passed as C<pattern>.  It passes if the
+pattern matches and fails otherwise.  This will report the results with the
+optional test description in C<description>.
+
+=cut
+
+.sub like
+    .param string target
+    .param string pattern
+    .param string description :optional
+
+    .local pmc test
+    find_global test, 'Test::More', '_test'
+
+    .local pmc p6rule_compile
+    load_bytecode "PGE.pbc"
+    load_bytecode "PGE/Dumper.pir"
+    load_bytecode "PGE/Text.pir"
+    load_bytecode "PGE/Util.pir"
+    p6rule_compile = compreg "PGE::P6Rule"
+
+    .local string diagnostic
+    .local int pass
+    pass = 0
+
+  match_pattern:
+    .local pmc rulesub
+    .local pmc match
+    .local pmc code
+    .local pmc exp
+    (rulesub, code, exp) = p6rule_compile(pattern)
+    if_null rulesub, rule_fail
+    match = rulesub(target)
+    unless match goto match_fail
+  match_success:
+    goto PASS
+  match_fail:
+    diagnostic = "match failed"
+    goto REPORT
+  rule_fail:
+    diagnostic = "rule error"
+    goto REPORT
+
+  PASS:
+    pass = 1
+
+  REPORT:
+    test.ok( pass, description )
+    if pass goto DONE
+
+    test.diag( diagnostic )
+  DONE:
+.end
+
 .sub _make_diagnostic
     .param string received
     .param string expected

Modified: trunk/t/library/test_more.t
==============================================================================
--- trunk/t/library/test_more.t (original)
+++ trunk/t/library/test_more.t Tue Apr 25 20:12:38 2006
@@ -21,6 +21,7 @@
        .local pmc ok
        .local pmc is
        .local pmc is_deeply
+       .local pmc like
        .local pmc diag
        plan      = find_global 'Test::Builder::Tester', 'plan'
        test_pass = find_global 'Test::Builder::Tester', 'test_pass'
@@ -30,9 +31,10 @@
        ok        = find_global 'Test::More',            'ok'
        is        = find_global 'Test::More',            'is'
        is_deeply = find_global 'Test::More',            'is_deeply'
+       like      = find_global 'Test::More',            'like'
        diag      = find_global 'Test::More',            'diag'
 
-       plan( 26 )
+       plan( 30 )
 
        test_pass()
        ok( 1 )
@@ -191,5 +193,23 @@
        is_deeply( left, right, 'comparing two pmc arrays' )
        test_test( 'failing test is_deeply() for pmc arrays with description' )
 
+       test_pass()
+       like( 'abcdef', '<[c]>' )
+       test_test( 'passing test like()' )
+
+       test_pass( 'testing like()' )
+       like( 'abcdef', '<[c]>', 'testing like()' )
+       test_test( 'passing test like() with description' )
+
+       test_fail()
+       test_diag( 'match failed' )
+       like( 'abcdef', '<[g]>' )
+       test_test( 'failing test like()' )
+
+       test_fail( 'testing like()' )
+       test_diag( 'match failed' )
+       like( 'abcdef', '<[g]>', 'testing like()' )
+       test_test( 'failing test like() with description' )
+
        test.'finish'()
 .end

Reply via email to