Skip to content

Instantly share code, notes, and snippets.

@perlpilot
Created April 6, 2017 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlpilot/67fd0b46d0d07500fab37e6ba942d5ac to your computer and use it in GitHub Desktop.
Save perlpilot/67fd0b46d0d07500fab37e6ba942d5ac to your computer and use it in GitHub Desktop.
tests for alphah
#!/usr/bin/env perl6
use Test;
##use Grammar::Debugger;
### Package : package-name-ver-arch-build-tag.ext
grammar Pkg {
token TOP { <ws> <name> ['-' <ver>]? ['-' <arch>]? ['-' <build>]? ['-' <tag>]? ['.' <ext>]? }
regex name { <alnum>+ [ '-' <alnum>+ ]* <!before '.'>} # using regex as name may contain "-"
token ver { <digit>+ ['.' <digit>+]* }
proto token arch { * } # look-around asssertions for "arch" token doesn't work, Why!
token arch:sym<x86_64> { <sym> }
token arch:sym<i386> { <sym> }
token build { <!after '-' <ver> '-'> <digit>+ }
token tag { <?after '-' <build> '-'> <alnum>+ } # "tag" is optional in the package name.
token ext { <?after [<build> | <tag>] '.'> 'pkg' } # "ext" should come after ("build" or "tag") only
}
my @tests = (
# [ 'string to test', matches?, message ]
[ 'package-name', True, 'match name' ],
[ 'package-name-ver', True, 'match name, ver' ],
[ 'package-name-ver-arch', True, 'match name, ver, arch' ],
[ 'package-name-ver-arch-build', True, 'match name, ver, arch, build' ],
[ 'package-name-ver-build', False, '"build" should come after "arch"' ],
[ 'package-name-ver-arch-build-tag', True, 'match name, ver, arch, build, tag' ],
[ 'package-name-ver-arch-build.ext', True, 'match name, ver, arch, build, ext' ],
[ 'package-name-ver-arch-build-tag.ext', True, 'match name, ver, arch, build, tag, ext' ],
[ 'package-name-arch-build', False, '"arch" must be after ver and before build' ],
[ 'package-name-ver-build', False, '"build" must be after arch' ],
);
for @tests -> [$string, $should-parse, $message] {
my $m = Pkg.parse($string);
my $result = ?$m; # make boolean
$result = !$result if $should-parse === False;
ok $result, $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment