scripts.t.svn-base

来自「这是一个DFA简化和生成LL(1)分析表的程序,自动生成表格及图形」· SVN-BASE 代码 · 共 147 行

SVN-BASE
147
字号
# scripts.t# test script/*.pluse strict;use warnings;use Test::More tests => 36;use IPC::Run3;use Data::Dumper::Simple;our $Regex = '(a|b)*';sub test {    my $script = shift;    my $expected = shift;    my @outfiles = @_;    for my $file (@outfiles) {        unlink $file if -f $file;    }    my $cmd = [$^X, "-Ilib", "script/$script.pl", $Regex];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "$script - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    if (ref $expected) {        like($stdout, $expected, "$script - output ok");    } else {        is($stdout, $expected, "$script - output ok");    }    for my $file (@outfiles) {        ok -f $file, "$script - outfile $file creation ok";        ok -s $file, "$script - outfile $file size ok";        unlink $file if -f $file;    }}test( 're2re', $Regex );test( 're2xml', qr/<expression>/ );test( 're2nfa', "NFA.png generated.", 'NFA.png' );test( 're2dfa', "DFA.png generated.\nDFA.min.png generated.", 'DFA.png', 'DFA.min.png' );test( 're2pl', qr/sub  {.*\$state/s );test( 're2c', qr/int match \(char\* s\) {.*state/s );{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '(a|)b*', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: 'bbb'", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '-p', '(a|)b*', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: 'bbb'", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '-c', '(a|)b*', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: 'bbb'", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: ''", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", 'c', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "fail to match", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '-c', 'c', 'bbba'];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "fail to match", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", "c'*b", "c''''b"];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: 'c\\'\\'\\'\\'b'", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '-c', "c'*b", "c''''b"];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: 'c\\'\\'\\'\\'b'", 'evalre - stdout ok');}{    my $cmd = [$^X, "-Ilib", "script/evalre.pl", '-c', "'", "'"];    #warn Dumper($cmd);    my $stdout;    run3 $cmd, \undef, \$stdout;    ok defined $stdout, "evalre - start ok";    #warn "$buffer";    $stdout =~ s/[\s\n]+$//gs;    is ($stdout, "match: '\\''", 'evalre - stdout ok');}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?