Skip to content

Commit

Permalink
Improve the is_tap method in Tapir::Parser and add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Jan 23, 2010
1 parent 959dbdf commit fb239bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/Tapir/Parser.pir
Expand Up @@ -113,11 +113,13 @@ Written and maintained by Jonathan "Duke" Leto C<< jonathan@leto.net >>.

.sub is_tap :method
.param string tapline
$S0 = substr tapline, 0, 2
if $S0 == "ok" goto yes
$S0 = substr tapline, 0, 3
if $S0 == "ok " goto yes

$S0 = substr tapline, 0, 5
if $S0 == "not ok" goto yes
$S0 = substr tapline, 0, 7
if $S0 == "not ok " goto yes

goto no
yes:
.return( 1 )
no:
Expand Down
32 changes: 31 additions & 1 deletion t/03-parse_tapstream_error.t
Expand Up @@ -7,7 +7,7 @@
load_bytecode 'lib/Tapir/Stream.pbc'
load_bytecode 'lib/Tapir/Parser.pbc'

plan(35)
plan(42)

# setup test data
klass = newclass [ 'Tapir'; 'Parser' ]
Expand All @@ -19,6 +19,36 @@
test_exit_code(tapir)
test_exit_code_pass(tapir)
test_parse_tapstream_out_of_order(tapir)
test_is_tap(tapir)
.end

.sub test_is_tap
.param pmc tapir
.local pmc stream

$S0 = 'Who paid for this damn Bail out!?!'
$I0 = tapir.'is_tap'($S0)
is($I0,0,'invalid bailout detected by is_tap')

$S0 = 'ok 42'
$I0 = tapir.'is_tap'($S0)
is($I0,1,'valid ok line detected by is_tap')

$S0 = 'not ok 99999'
$I0 = tapir.'is_tap'($S0)
is($I0,1,'valid not ok line detected by is_tap')

$S0 = 'Some junk # and a comment'
$I0 = tapir.'is_tap'($S0)
is($I0,0,'non-TAP lines properly detected by is_tap')

$S0 = 'okie dokey pokey'
$I0 = tapir.'is_tap'($S0)
is($I0,0,'non-TAP lines properly detected by is_tap')

$S0 = 'not oklahoma, but any other state!'
$I0 = tapir.'is_tap'($S0)
is($I0,0,'non-TAP lines properly detected by is_tap')
.end

.sub test_parse_tapstream_out_of_order
Expand Down

0 comments on commit fb239bd

Please sign in to comment.