diff --git a/t/9-junction.t b/t/9-junction.t index 3fbe156..2127409 100644 --- a/t/9-junction.t +++ b/t/9-junction.t @@ -15,15 +15,50 @@ my $junction = abbrevs $target; is $junction, "A|Ar|Arg|Args", "Single word => /regex junction/"; my @args = $junction.split("|"); -is test-junction(:$target, :@args), 0; +my ($ntests, $nfails); +my $nargs = @args.elems; -$junction = "^(A|Ar|Arg|Args)"; -is test-junction(:$junction, :$target, :@args), 0; +# subtest 1 +subtest { + ($ntests, $nfails) = test-junction(:$regex, :$target, :@args); + is $ntests, $nargs, "ntests $ntests"; + is $nfails, 0, "expect 0 fails, got $nfails"; +}, "subtest 1"; -$target = "NArgs"; -is test-junction(:$junction, :$target, :@args), 4; +# subtest 2 +subtest { + $target = "Args"; + $junction = /(A|Ar|Arg|Args)/; + ($ntests, $nfails) = test-junction(:$regex, :$junction, :$target, :@args); + is $ntests, $nargs, "ntests $ntests"; + is $nfails, 0, "expect 0 fails, got $nfails"; +}, "subtest 2"; -$junction = "A|Ar|Arg|Args"; -is test-junction(:$junction, :$target, :@args), 0; +# subtest 3 +subtest { + $target = "Args"; + $junction = /^(A|Ar|Arg|Args)/; + ($ntests, $nfails) = test-junction(:$regex, :$target, :@args); + is $ntests, $nargs, "ntests $ntests"; + is $nfails, 0, "Expected 0 fails, got $nfails"; +}, "subtest 3"; + +# subtest 4 +subtest { + $target = "NArgs"; + $junction = /^(A|Ar|Arg|Args)/; + ($ntests, $nfails) = test-junction(:$regex, :$target, :@args); + is $ntests, $nargs, "ntests $ntests"; + is $nfails, $nargs, "Expected $nargs fails, got $nfails"; +}, "subtest 4"; + +# subtest 5 +subtest { + $target = "NArgs"; + $junction = /(A|Ar|Arg|Args)/; + ($ntests, $nfails) = test-junction(:$regex, :$target, :@args); + is $ntests, $nargs, "ntests $ntests"; + is $nfails, 0, "Expected 0 fails, got $nfails"; +}, "subtest 5"; done-testing; diff --git a/t/Utils/Subs.rakumod b/t/Utils/Subs.rakumod index 9c94b18..f2b4f50 100644 --- a/t/Utils/Subs.rakumod +++ b/t/Utils/Subs.rakumod @@ -5,17 +5,16 @@ use Abbreviations :ALL; sub test-junction( :$target!, :@args!, - :$junction is copy, + :$regex!, :$debug, + --> List ) is export { - unless $junction { - $junction = abbrev $target; - } - + my $ntests = 0; my $nfails = 0; my $res; for @args { - when /<$junction>/ { + ++$ntests; + when $_ ~~ $regex { $res = True } default { @@ -23,5 +22,5 @@ sub test-junction( ++$nfails } } - $nfails + $ntests, $nfails }