Skip to content

Commit

Permalink
round trippy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 8, 2008
1 parent 1e89c03 commit d9cb947
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Software/LicenseUtils.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ Calling this method in scalar context is a fatal error.
=cut =cut


my $_v = qr/(?:, )?(?:v(?:er(?:sion|\.))(?: |\.)?)/i; my $_v = qr/(?:v(?:er(?:sion|\.))(?: |\.)?)/i;
my @phrases = ( my @phrases = (
"under the same (?:terms|license) as perl $_v?6" => [], "under the same (?:terms|license) as perl $_v?6" => [],
'under the same (?:terms|license) as perl' => 'Perl_5', 'under the same (?:terms|license) as perl' => 'Perl_5',
'affero g' => 'AGPL_3', 'affero g' => 'AGPL_3',
"GNU (?:general )?public license $_v?([123])" => sub { "GPL_$_[0]_0" }, "GNU (?:general )?public license,? $_v?([123])" => sub { "GPL_$_[0]" },
'GNU (?:general )?public license' => [ map {"GPL_$_\_0"} (1..3) ], 'GNU (?:general )?public license' => [ map {"GPL_$_"} (1..3) ],
"GNU (?:lesser|library) (?:general )?public license $_v?([23])\\D" => sub { "GNU (?:lesser|library) (?:general )?public license,? $_v?([23])\\D" => sub {
$_[0] == 2 ? 'LGPL_2_1' : $_[0] == 3 ? 'LGPL_3_0' : () $_[0] == 2 ? 'LGPL_2_1' : $_[0] == 3 ? 'LGPL_3_0' : ()
}, },
'GNU (?:lesser|library) (?:general )?public license' => [ qw(LGPL_2_1 LGPL_3_0) ], 'GNU (?:lesser|library) (?:general )?public license' => [ qw(LGPL_2_1 LGPL_3_0) ],
'BSD license' => 'BSD', 'BSD license' => 'BSD',
"Artistic license $_v?(\\d)" => sub { "Artistic_$_[0]_0" }, "Artistic license $_v?(\\d)" => sub { "Artistic_$_[0]_0" },
'Artistic license' => [ map { "Artistic_$_\_0" } (1..2) ], 'Artistic license' => [ map { "Artistic_$_\_0" } (1..2) ],
"LGPL $_v?(\\d)" => sub { "LGPL,? $_v?(\\d)" => sub {
$_[0] == 2 ? 'LGPL_2_1' : $_[0] == 3 ? 'LGPL_3_0' : () $_[0] == 2 ? 'LGPL_2_1' : $_[0] == 3 ? 'LGPL_3_0' : ()
}, },
'LGPL' => [ qw(LGPL_2_1 LGPL_3_0) ], 'LGPL' => [ qw(LGPL_2_1 LGPL_3_0) ],
"GPL $_v?(\\d)" => sub { "GPL_$_[0]_0" }, "GPL,? $_v?(\\d)" => sub { "GPL_$_[0]_0" },
'GPL' => [ map { "GPL_$_\_0" } (1..3) ], 'GPL' => [ map { "GPL_$_\_0" } (1..3) ],
'BSD' => 'BSD', 'BSD' => 'BSD',
'Artistic' => [ map { "Artistic_$_\_0" } (1..2) ], 'Artistic' => [ map { "Artistic_$_\_0" } (1..2) ],
Expand Down
32 changes: 32 additions & 0 deletions t/round-trip.t
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
#!perl
use strict;
use warnings;
use Test::More;

use Software::License;
use Software::LicenseUtils;

my @round_trippable = qw(
AGPL_3
Artistic_1_0 Artistic_2_0
BSD
GPL_1 GPL_2 GPL_3
LGPL_2_1 LGPL_3_0
MIT
Perl_5
);

plan tests => 2 * @round_trippable;

for my $name (@round_trippable) {
my $class = "Software::License::$name";
eval "require $class; 1" or die $@;
my $notice = $class->new({ holder => 'J. Phred Bloggs' })->notice;
my $pod = "=head1 LEGAL\n\n$notice\n\n=cut\n";

my @guess = Software::LicenseUtils->guess_license_from_pod($pod);

is(@guess, 1, "$name: only 1 guess for license we build")
or diag "guesses: @guess";
is($guess[0], $class, "$name: ...and we got it right");
}

0 comments on commit d9cb947

Please sign in to comment.