Skip to content
Browse files

round trippy tests

  • Loading branch information...
1 parent 1e89c03 commit d9cb94747f505b0aaa73466f5ac37ff1998003bd @rjbs rjbs committed Jun 8, 2008
Showing with 38 additions and 6 deletions.
  1. +6 −6 lib/Software/LicenseUtils.pm
  2. +32 −0 t/round-trip.t
View
12 lib/Software/LicenseUtils.pm
@@ -20,25 +20,25 @@ Calling this method in scalar context is a fatal error.
=cut
-my $_v = qr/(?:, )?(?:v(?:er(?:sion|\.))(?: |\.)?)/i;
+my $_v = qr/(?:v(?:er(?:sion|\.))(?: |\.)?)/i;
my @phrases = (
"under the same (?:terms|license) as perl $_v?6" => [],
'under the same (?:terms|license) as perl' => 'Perl_5',
'affero g' => 'AGPL_3',
- "GNU (?:general )?public license $_v?([123])" => sub { "GPL_$_[0]_0" },
- 'GNU (?:general )?public license' => [ map {"GPL_$_\_0"} (1..3) ],
- "GNU (?:lesser|library) (?:general )?public license $_v?([23])\\D" => sub {
+ "GNU (?:general )?public license,? $_v?([123])" => sub { "GPL_$_[0]" },
+ 'GNU (?:general )?public license' => [ map {"GPL_$_"} (1..3) ],
+ "GNU (?:lesser|library) (?:general )?public license,? $_v?([23])\\D" => sub {
$_[0] == 2 ? 'LGPL_2_1' : $_[0] == 3 ? 'LGPL_3_0' : ()
},
'GNU (?:lesser|library) (?:general )?public license' => [ qw(LGPL_2_1 LGPL_3_0) ],
'BSD license' => 'BSD',
"Artistic license $_v?(\\d)" => sub { "Artistic_$_[0]_0" },
'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' : ()
},
'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) ],
'BSD' => 'BSD',
'Artistic' => [ map { "Artistic_$_\_0" } (1..2) ],
View
32 t/round-trip.t
@@ -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.
Something went wrong with that request. Please try again.