Commit 1af64b46 authored by Angel Abad's avatar Angel Abad

Merge tag 'upstream/1.999804'

Upstream version 1.999804

# gpg: Firmado el sáb 10 dic 2016 08:42:38 CET
# gpg:                usando RSA clave 4A0897191621CCF7FBEEF752A6D58816010A1096
# gpg:                issuer "angelabad@gmail.com"
# gpg: Firma correcta de "Angel Abad <angelabad@gmail.com>" [desconocido]
# gpg:                 alias "Angel Abad <angel@debian.org>" [desconocido]
# gpg:                 alias "Angel Abad <angelabad@ubuntu.com>" [desconocido]
# gpg: ATENCIÓN: ¡Esta clave no está certificada por una firma de confianza!
# gpg:           No hay indicios de que la firma pertenezca al propietario.
# Huellas dactilares de la clave primaria: 4A08 9719 1621 CCF7 FBEE  F752 A6D5 8816 010A 1096
parents 6e071390 727899d5
2016-12-07 v1.999804 pjacklam
* Implement as_bytes(), as requested (CPAN RT 119096). Also implement the
inverse conversion from_bytes(). This applies to Math::BigInt only. (Alas,
these methods will be inherited from Math::BigInt into Math::BigFloat,
Math::BigRat etc. where the methods won't work. Fixing this class
relationship is an issue of its own.)
* Implement _as_bytes() and _from_bytes() in Math::BigInt::Lib. Preferably,
the various backend libraries will implement faster versions of their
own. Add author test files for testing these methods thorougly.
* Fix from_hex(), from_oct(), and from_bin().
- When called as instance methods, the new value should be assigned to the
invocand unless the invocand is read-only (a constant).
- When called as instance methods, the assigned value was incorrect, if the
invocand was inf or NaN.
- Add tests to t/from_hex-mbf.t, t/from_oct-mbf.t, and t/from_bin-mbf.t
to confirm the fix.
- Add new test files t/from_hex-mbi.t, t/from_oct-mbi.t, and
t/from_bin-mbi.t for better testing of these methods with Math::BigInt.
* Correct typo in Math/BigInt/Lib.pm (otherise -> otherwise) (CPAN RT 118829).
* Add POD coverage testing of Math::BigInt::Lib to t/03podcov.t.
2016-12-03 v1.999803 pjacklam
* Remove BENCHMARK file. The information was obsolete.
......
......@@ -86,6 +86,8 @@ t/author-lib-constructor-nullary-_zero.t
t/author-lib-constructor-unary-_copy.t
t/author-lib-constructor-unary-_from_bin.dat
t/author-lib-constructor-unary-_from_bin.t
t/author-lib-constructor-unary-_from_bytes.dat
t/author-lib-constructor-unary-_from_bytes.t
t/author-lib-constructor-unary-_from_hex.dat
t/author-lib-constructor-unary-_from_hex.t
t/author-lib-constructor-unary-_from_oct.dat
......@@ -94,6 +96,8 @@ t/author-lib-constructor-unary-_new.t
t/author-lib-convert-number-_num.t
t/author-lib-convert-string-_as_bin.dat
t/author-lib-convert-string-_as_bin.t
t/author-lib-convert-string-_as_bytes.dat
t/author-lib-convert-string-_as_bytes.t
t/author-lib-convert-string-_as_hex.dat
t/author-lib-convert-string-_as_hex.t
t/author-lib-convert-string-_as_oct.dat
......@@ -142,8 +146,11 @@ t/dparts-mbi.t
t/eparts-mbf.t
t/eparts-mbi.t
t/from_bin-mbf.t
t/from_bin-mbi.t
t/from_hex-mbf.t
t/from_hex-mbi.t
t/from_oct-mbf.t
t/from_oct-mbi.t
t/inf_nan.t
t/isa.t
t/lib_load.t
......
......@@ -39,6 +39,6 @@
}
},
"release_status" : "stable",
"version" : "1.999803",
"version" : "1.999804",
"x_serialization_backend" : "JSON::PP version 2.27400"
}
......@@ -21,5 +21,5 @@ requires:
Math::Complex: '1.39'
Test::More: '0.94'
perl: '5.006001'
version: '1.999803'
version: '1.999804'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
......@@ -15,15 +15,15 @@ not run its Makefile.PL or Build.PL.
Hash: SHA1
SHA1 20104176cd4b0623c201cdb2c9583056898b2afc BUGS
SHA1 32ca2f5e00149d006d7dc32e19e8fbad75b776c9 CHANGES
SHA1 755acfd201a20351030f77c0ff7aeb42d89a1423 CHANGES
SHA1 a40e6f05bfd2a3e0542cf9e4971b1d48100eb2fd CREDITS
SHA1 8d0b726d78afa344fb12508e1b027079699570e4 GOALS
SHA1 fe61299e80a1dca48fbaa33f0869e3238ec07c70 HISTORY
SHA1 d7c83d8f89b92a3262a01eb2778d39402e77263a LICENSE
SHA1 cb37159025d48a2fcc0bb2316924a2735664d2fc MANIFEST
SHA1 536b20c8fbe593c8f73ad08000210b4d4731e0b2 MANIFEST
SHA1 86df44fbe1ea7a68897113f0e327d0f0c25b91e3 MANIFEST.SKIP
SHA1 6ceba8a4673bfa2bf0e56838ae322e7349f6738a META.json
SHA1 f4d66f99f58b03614561e11a30e9bad0c62f49d6 META.yml
SHA1 23cd038049ce1aa81bb94580d2bd6aa1cda9a738 META.json
SHA1 d73bcf645a934a9f62c2eeb1d47f4c69ce6fe570 META.yml
SHA1 a3ec4bde20bcafcc16ffcbe577befa0728a61176 Makefile.PL
SHA1 4e2191d1724e699862efc5350f480c8e02755112 NEW
SHA1 813c62e6d3edd18b7b634765ecbd75b2cd6389a0 README
......@@ -31,15 +31,15 @@ SHA1 eda34055882182d059d20179b445be7a2940e8cf TODO
SHA1 a8ffc7d3270e481c9d24603a74ba2c0f46cae0e3 examples/1000.txt
SHA1 3295c03031e6a50199c1acc743a3f3276e6ae59d examples/bigprimes.pl
SHA1 989bfc0ad145d0f42b1eb65e83d9de018a7ee150 examples/prime.pl
SHA1 28b0d3e11656fb597a5615e7d5fef992df069a3e lib/Math/BigFloat.pm
SHA1 430dbb5254990276e8f4c664b0982bd11d6a9eaa lib/Math/BigInt.pm
SHA1 40cf7df9826c10f222feca4ca4fe840fd1b48943 lib/Math/BigInt/Calc.pm
SHA1 a8ffd4f45d88426b98bf3b2e5b3926e171cf5e01 lib/Math/BigInt/CalcEmu.pm
SHA1 6d2096dfa46f7494a7efa7058acd7b6f42ce24a2 lib/Math/BigInt/Lib.pm
SHA1 079e7420478cf71f866bd1c2dc2dcccdeaac807a lib/Math/BigFloat.pm
SHA1 b834f100857766fc45cdcdf7965718bb6380eeb7 lib/Math/BigInt.pm
SHA1 494567e1b03193567255d009d2e0b344350b68de lib/Math/BigInt/Calc.pm
SHA1 01d0274ae39942d61835151011f0844546240510 lib/Math/BigInt/CalcEmu.pm
SHA1 c2e87a3682c56c6160681d5c2b851188ab419d66 lib/Math/BigInt/Lib.pm
SHA1 385cc7ed3bf3e6290640b9880445ca9a3dea629e t/00sig.t
SHA1 062a7e33e6697b19e002cdb11f3c648fe6669139 t/01load.t
SHA1 b2ed9206ca5b69ec3b8bbf850bf4b6dfde518e7e t/02pod.t
SHA1 70791ee5e7358a9605f95a1aa02a566210bec223 t/03podcov.t
SHA1 47c879490e1a6229d0464805679c67660af7b4b3 t/03podcov.t
SHA1 a323fbde83f97abdedc14ff923a2ecabb1333e2d t/Math/BigFloat/#Subclass.pm#
SHA1 a323fbde83f97abdedc14ff923a2ecabb1333e2d t/Math/BigFloat/Subclass.pm
SHA1 079c95d9ecb1e4c0a863c60d66c15c407b162ad9 t/Math/BigInt/BareCalc.pm
......@@ -112,6 +112,8 @@ SHA1 acc96f478427840b085052fe050f19563be715ff t/author-lib-constructor-nullary-_
SHA1 340bef1f004f15ecdcb7cc4d0f52d8e8bf515d52 t/author-lib-constructor-unary-_copy.t
SHA1 c9539965e7ef898559b9f9b978aabb4429684cdd t/author-lib-constructor-unary-_from_bin.dat
SHA1 0bef4c2744a42c012b0d3cf7ae1e97161bd1a2f6 t/author-lib-constructor-unary-_from_bin.t
SHA1 f6b48efb760df125dc6ff2775ca7ec2f682d73a7 t/author-lib-constructor-unary-_from_bytes.dat
SHA1 7c179da34c3bf48f5d4bf4d45d57820f741ba5cd t/author-lib-constructor-unary-_from_bytes.t
SHA1 a17c631c96d719880a0911475a7cf87b1d024257 t/author-lib-constructor-unary-_from_hex.dat
SHA1 940dd7604f9ebc5ade1ac357ff334168003bd712 t/author-lib-constructor-unary-_from_hex.t
SHA1 c4aee685339894d9975cd5b643869130e31e70c2 t/author-lib-constructor-unary-_from_oct.dat
......@@ -120,6 +122,8 @@ SHA1 b4fa96e1f73def99b8a55ac515823769dd6c4c92 t/author-lib-constructor-unary-_ne
SHA1 c775a9fab56467b389d22cd8e7a44254bf639fdf t/author-lib-convert-number-_num.t
SHA1 25cb7ed724cecb287ae7cc1b52eeed6e8313b674 t/author-lib-convert-string-_as_bin.dat
SHA1 b64e68ebd8f3ccba8eecbd326d56bc85de1de670 t/author-lib-convert-string-_as_bin.t
SHA1 23659b7433005b596a1f84cd2ae67ed0a6eb9836 t/author-lib-convert-string-_as_bytes.dat
SHA1 ae465cba3941a45fdb7c200f31fe781d88cfeaf8 t/author-lib-convert-string-_as_bytes.t
SHA1 d3ab340bf68cac2efcf28da0183851195aaa1a31 t/author-lib-convert-string-_as_hex.dat
SHA1 fd55c04375eb769b6348cec1e3141aed085bd5a9 t/author-lib-convert-string-_as_hex.t
SHA1 1a321f2488a44cb420484a8b6daeaa80064e7cf1 t/author-lib-convert-string-_as_oct.dat
......@@ -158,7 +162,7 @@ SHA1 8d5692fa1ab8b84bb816f83c0d51c409de8f13b5 t/bsstr-mbf.t
SHA1 c97164e3ae794f8d2f141be42e5f7af4f2dd674b t/bsstr-mbi.t
SHA1 dcaf0d82455c9a814da942383cbceb2da7ad3a4c t/calling-class-methods.t
SHA1 63e873c5cdcccfb338fb9220d33904027865e9cf t/calling-instance-methods.t
SHA1 af45539194c9301d8eca2529d1502a91974f09bb t/calling.t
SHA1 cf6abcd1fbd6ae1deafc2fd8bc3f3cb4b92d1db0 t/calling.t
SHA1 c403d1c64ae6c3b803fc8cd0d10a1df15219057f t/config.t
SHA1 af01ecfb6f43bb518c67185eb063c196e2dbdc48 t/const_mbf.t
SHA1 17eb15c35392945a5b3ed2b711f7d166fca294de t/constant.t
......@@ -167,9 +171,12 @@ SHA1 0bd79be40fb655a91d9589c1efecda979e587feb t/dparts-mbf.t
SHA1 360f8ec3c0784cb90c36935e5eca8229a165507b t/dparts-mbi.t
SHA1 771490cdc077d0527801b29b33d9e58794c7eb9e t/eparts-mbf.t
SHA1 caefcd4243e49d5d48a6e80b74ceee38dc13d484 t/eparts-mbi.t
SHA1 9f6ba1b532a82769af11c1666d01d200d1e9975d t/from_bin-mbf.t
SHA1 1ee53aba4bd3cdea7ec6acd44e91f9ff5fc614be t/from_hex-mbf.t
SHA1 6604c799d3ee2b537225ce96f8b3a4c11a281008 t/from_oct-mbf.t
SHA1 7e6ae97cbc1c7ed92af901238bfae13561096c21 t/from_bin-mbf.t
SHA1 1ef3618e448d187419e12cb7f138ff0a18e5bcea t/from_bin-mbi.t
SHA1 d6792aa13e49928e8b56a1a1d35fe03c136b5cc3 t/from_hex-mbf.t
SHA1 c3628d24513842e7aa913b2c1bc196e017284c24 t/from_hex-mbi.t
SHA1 3df863b78e05372cd005b88d6a97295430f5fee7 t/from_oct-mbf.t
SHA1 69f57191028ada1f807f32fcfef89852ff73b4ee t/from_oct-mbi.t
SHA1 2dbc417043f25c141ea9a45f860b31a07b9c29be t/inf_nan.t
SHA1 e870ac55d1583cdae6efa043628ece5fb725820e t/isa.t
SHA1 3dcc5482e16ef304a284abfa6096841311e0373f t/lib_load.t
......@@ -214,11 +221,11 @@ SHA1 6f8e43710067bed0b0872fafdeb751c9a68732c4 t/use_mbfw.t
SHA1 33e23e08da0a2ee6861350a81e843a2522b4966b t/with_sub.t
-----BEGIN PGP SIGNATURE-----
iQEcBAEBAgAGBQJYQ9WmAAoJEGcmPl2fr166DUoIAMwCJIQJM8FuTRhbn7puA4Ke
vtJPslzMAwI83peR95ldk2eDNYFs2yNzVhMkpoaP/B+TRExYV26uK1u4L1q/HuaY
uZSIqTOzOV1Br2GmJf5yHsHNa6K3dbZqX5lDd/PcGQbLP6wAj1hLqCQrqYRqJ/9b
X9AEzJkU1D/ZTMq71SGlMsPn5ru9mkmgskAjLyuNj2M5PDuiNL2+Z+U/KEBz7BYE
9o6Hy7btkfUCWWwgApbfxEEtT9R+rYwURTj7d9OPtcIUH3fS1ccoFJe38zjcjz9a
gutl8Y1Mz9yWSDwU0cLAVVIz4FgL+HzFnALMjGigUBv6iewlSDXhcAU/zg2Ou1U=
=t3fW
iQEcBAEBAgAGBQJYSSwKAAoJEGcmPl2fr166TWsH/1Ek+LykUlHo73bU3sSjhAtT
So6HcE3mIe+fUCgJ6wS5gnnvLJSf1tLCES5O38k9R7Vi/Z60M7pJQRpnvUIOhJf7
TV/gFeMJPlpy86hxQXFqRkiPa/QK/yK2o8pD4kFsc3iKcSuRcDaYlq8+7sDdOpsa
8lwbm/zinXNM4PPwo0PyUM0SXCLuAN0B/55fkWpAXJe/JZJ1KhpcEXpO23i/Yjfc
mpyn1uw4n/zptyU2b354wobfIUwB6ZCU4pRsLQaz14U4sYL9lSaGCKRsYCnbekEc
T5e0p0DHqPMz0pA8ZvRSSFAr9b0RL2AQr6SxgxnJc/CLm70JdyAtyGxC/zhHM1U=
=D6DA
-----END PGP SIGNATURE-----
......@@ -19,7 +19,7 @@ use warnings;
use Carp ();
use Math::BigInt ();
our $VERSION = '1.999803';
our $VERSION = '1.999804';
require Exporter;
our @ISA = qw/Math::BigInt/;
......@@ -517,6 +517,10 @@ sub from_hex {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_hex');
my $str = shift;
# If called as a class method, initialize a new object.
......@@ -602,6 +606,10 @@ sub from_oct {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_oct');
my $str = shift;
# If called as a class method, initialize a new object.
......@@ -684,6 +692,10 @@ sub from_bin {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_bin');
my $str = shift;
# If called as a class method, initialize a new object.
......
......@@ -20,7 +20,7 @@ use warnings;
use Carp ();
our $VERSION = '1.999803';
our $VERSION = '1.999804';
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(objectify bgcd blcm);
......@@ -719,6 +719,10 @@ sub from_hex {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_hex');
my $str = shift;
# If called as a class method, initialize a new object.
......@@ -750,9 +754,8 @@ sub from_hex {
# Place the sign.
if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
$self->{sign} = '-';
}
$self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
? '-' : '+';
return $self;
}
......@@ -770,6 +773,10 @@ sub from_oct {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_oct');
my $str = shift;
# If called as a class method, initialize a new object.
......@@ -800,9 +807,8 @@ sub from_oct {
# Place the sign.
if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
$self->{sign} = '-';
}
$self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
? '-' : '+';
return $self;
}
......@@ -820,6 +826,10 @@ sub from_bin {
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_bin');
my $str = shift;
# If called as a class method, initialize a new object.
......@@ -851,9 +861,8 @@ sub from_bin {
# Place the sign.
if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
$self->{sign} = '-';
}
$self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
? '-' : '+';
return $self;
}
......@@ -864,6 +873,27 @@ sub from_bin {
return $self->bnan();
}
# Create a Math::BigInt from a byte string.
sub from_bytes {
my $self = shift;
my $selfref = ref $self;
my $class = $selfref || $self;
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('from_bytes');
my $str = shift;
# If called as a class method, initialize a new object.
$self = $class -> bzero() unless $selfref;
$self -> {sign} = '+';
$self -> {value} = $CALC -> _from_bytes($str);
return $self;
}
sub bzero {
# create/assign '+0'
......@@ -878,6 +908,9 @@ sub bzero {
my $class = $selfref || $self;
$self->import() if $IMPORT == 0; # make require work
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('bzero');
$self = bless {}, $class unless $selfref;
......@@ -915,6 +948,9 @@ sub bone {
my $class = $selfref || $self;
$self->import() if $IMPORT == 0; # make require work
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('bone');
my $sign = shift;
......@@ -964,6 +1000,9 @@ sub binf {
}
$self->import() if $IMPORT == 0; # make require work
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('binf');
my $sign = shift;
......@@ -998,6 +1037,9 @@ sub bnan {
}
$self->import() if $IMPORT == 0; # make require work
# Don't modify constant (read-only) objects.
return if $selfref && $self->modify('bnan');
$self = bless {}, $class unless $selfref;
......@@ -3478,6 +3520,16 @@ sub as_bin {
return $s . $CALC->_as_bin($x->{value});
}
sub as_bytes {
# return a byte string
my $x = shift;
$x = $class->new($x) if !ref($x);
Carp::croak("as_bytes() requires a finite, non-negative integer")
if $x -> is_neg() || ! $x -> is_int();
return $CALC->_as_bytes($x->{value});
}
###############################################################################
# Other conversion methods
###############################################################################
......@@ -4219,6 +4271,7 @@ Math::BigInt - Arbitrary size integer/float math package
$x->as_hex(); # as signed hexadecimal string with prefixed 0x
$x->as_bin(); # as signed binary string with prefixed 0b
$x->as_oct(); # as signed octal string with prefixed 0
$x->as_bytes(); # as byte string
# Other conversion methods
......@@ -4512,6 +4565,31 @@ Interpret the input as a binary string. A "0b" or "b" prefix is optional. A
single underscore character may be placed right after the prefix, if present,
or between any two digits. If the input is invalid, a NaN is returned.
=item from_bytes()
$x = Math::BigInt->from_bytes("\xf3\x6b"); # $x = 62315
Interpret the input as a byte string, assuming big endian byte order. The
output is always a non-negative, finite integer.
In some special cases, from_bytes() matches the conversion done by unpack():
$b = "\x4e"; # one char byte string
$x = Math::BigInt->from_bytes($b); # = 78
$y = unpack "C", $b; # ditto, but scalar
$b = "\xf3\x6b"; # two char byte string
$x = Math::BigInt->from_bytes($b); # = 62315
$y = unpack "S>", $b; # ditto, but scalar
$b = "\x2d\xe0\x49\xad"; # four char byte string
$x = Math::BigInt->from_bytes($b); # = 769673645
$y = unpack "L>", $b; # ditto, but scalar
$b = "\x2d\xe0\x49\xad\x2d\xe0\x49\xad"; # eight char byte string
$x = Math::BigInt->from_bytes($b); # = 3305723134637787565
$y = unpack "Q>", $b; # ditto, but scalar
=item bzero()
$x = Math::BigInt->bzero();
......@@ -5321,6 +5399,14 @@ prefixed by "0b".
Returns a string representing the number using octal notation. The output is
prefixed by "0".
=item as_bytes()
$x = Math::BigInt->new("1667327589");
$s = $x->as_bytes(); # $s = "cafe"
Returns a byte string representing the number using big endian byte order. The
invocand must be a non-negative, finite integer.
=back
=head2 Other conversion methods
......
......@@ -7,7 +7,7 @@ use warnings;
use Carp;
use Math::BigInt::Lib;
our $VERSION = '1.999803';
our $VERSION = '1.999804';
our @ISA = ('Math::BigInt::Lib');
......
......@@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;
our $VERSION = '1.999803';
our $VERSION = '1.999804';
package Math::BigInt;
......
This diff is collapsed.
......@@ -21,19 +21,30 @@ eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
plan tests => 2;
plan tests => 3;
my $trustme;
# Math::BigInt
$trustme = {
trustme => [ 'fround',
'objectify' ],
};
pod_coverage_ok('Math::BigInt', $trustme, "Math::BigInt is covered");
# Math::BigFloat
$trustme = {
trustme => [ 'DEBUG',
'isa' ],
coverage_class => 'Pod::Coverage::CountParents',
};
pod_coverage_ok('Math::BigFloat', $trustme, "Math::BigFloat is covered");
# Math::BigInt::Lib
$trustme = {
private => [ qr/^(un)?import$/ ],
};
pod_coverage_ok('Math::BigInt::Lib', $trustme, "Math::BigInt::Lib is covered");
This diff is collapsed.
#!perl
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
require Test::More;
Test::More::plan(skip_all =>
'these tests are for testing by the author');
}
}
use strict;
use warnings;
use Test::More tests => 4001;
###############################################################################
# Read and load configuration file and backend library.
use Config::Tiny ();
my $config_file = 't/author-lib.ini';
my $config = Config::Tiny -> read('t/author-lib.ini')
or die Config::Tiny -> errstr();
# Read the library to test.
our $LIB = $config->{_}->{lib};
die "No library defined in file '$config_file'"
unless defined $LIB;
die "Invalid library name '$LIB' in file '$config_file'"
unless $LIB =~ /^[A-Za-z]\w*(::\w+)*\z/;
# Read the reference type(s) the library uses.
our $REF = $config->{_}->{ref};
die "No reference type defined in file '$config_file'"
unless defined $REF;
die "Invalid reference type '$REF' in file '$config_file'"
unless $REF =~ /^[A-Za-z]\w*(::\w+)*\z/;
# Load the library.
eval "require $LIB";
die $@ if $@;
###############################################################################
can_ok($LIB, '_from_hex');
my @data;
# Add data in data file.
(my $datafile = $0) =~ s/\.t/.dat/;
open DATAFILE, $datafile or die "$datafile: can't open file for reading: $!";
while (<DATAFILE>) {
s/\s+\z//;
next if /^#/ || ! /\S/;
push @data, [ split /:/ ];
}
close DATAFILE or die "$datafile: can't close file after reading: $!";
# List context.
for (my $i = 0 ; $i <= $#data ; ++ $i) {
my ($in0, $out0) = @{ $data[$i] };
my ($x, @got);
my $test = qq|\@got = $LIB->_from_bytes("$in0");|;
eval $test;
is($@, "", "'$test' gives emtpy \$\@");
subtest "_from_bytes() in list context: $test", sub {
plan tests => 4,
cmp_ok(scalar @got, '==', 1,
"'$test' gives one output arg");
is(ref($got[0]), $REF,
"'$test' output arg is a $REF");
is($LIB->_check($got[0]), 0,
"'$test' output is valid");
is($LIB->_str($got[0]), $out0,
"'$test' output arg has the right value");
};
}
# Scalar context.
for (my $i = 0 ; $i <= $#data ; ++ $i) {
my ($in0, $out0) = @{ $data[$i] };
my ($x, $got);
my $test = qq|\$got = $LIB->_from_bytes("$in0");|;
eval $test;
is($@, "", "'$test' gives emtpy \$\@");
subtest "_from_bytes() in scalar context: $test", sub {
plan tests => 3,
is(ref($got), $REF,
"'$test' output arg is a $REF");
is($LIB->_check($got), 0,
"'$test' output is valid");
is($LIB->_str($got), $out0,
"'$test' output arg has the right value");
};
}
This diff is collapsed.
#!perl
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
require Test::More;
Test::More::plan(skip_all =>
'these tests are for testing by the author');
}
}
use strict;
use warnings;
use Test::More tests => 4001;
###############################################################################
# Read and load configuration file and backend library.
use Config::Tiny ();
my $config_file = 't/author-lib.ini';
my $config = Config::Tiny -> read('t/author-lib.ini')
or die Config::Tiny -> errstr();
# Read the library to test.
our $LIB = $config->{_}->{lib};
die "No library defined in file '$config_file'"
unless defined $LIB;
die "Invalid library name '$LIB' in file '$config_file'"
unless $LIB =~ /^[A-Za-z]\w*(::\w+)*\z/;
# Load the library.
eval "require $LIB";
die $@ if $@;
###############################################################################
can_ok($LIB, '_as_bytes');
my @data;
# Add data in data file.
(my $datafile = $0) =~ s/\.t/.dat/;
open DATAFILE, $datafile or die "$datafile: can't open file for reading: $!";
while (<DATAFILE>) {
s/\s+\z//;
next if /^#/ || ! /\S/;
push @data, [ split /:/ ];
}
close DATAFILE or die "$datafile: can't close file after reading: $!";
# List context.
for (my $i = 0 ; $i <= $#data ; ++ $i) {
my ($in0, $out0) = @{ $data[$i] };
$out0 = eval qq|"$out0"|;
my ($x, @got);
my $test = qq|\$x = $LIB->_new("$in0"); |
. qq|\@got = $LIB->_as_bytes(\$x)|;
eval $test;
is($@, "", "'$test' gives emtpy \$\@");
subtest "_from_hex() in list context: $test", sub {
plan tests => 3,
cmp_ok(scalar @got, '==', 1,
"'$test' gives one output arg");
is(ref($got[0]), "",
"'$test' output arg is a scalar");
is($got[0], $out0,
"'$test' output arg has the right value");
};
}
# Scalar context.
for (my $i = 0 ; $i <= $#data ; ++ $i) {
my ($in0, $out0) = @{ $data[$i] };
$out0 = eval qq|"$out0"|;
my ($x, $got);
my $test = qq|\$x = $LIB->_new("$in0"); |
. qq|\$got = $LIB->_as_bytes(\$x)|;
eval $test;
is($@, "", "'$test' gives emtpy \$\@");
subtest "_from_hex() in scalar context: $test", sub {
plan tests => 2,
is(ref($got), "",
"'$test' output arg is a scalar");
is($got, $out0,
"'$test' output arg has the right value");
};
}
......@@ -6,7 +6,7 @@ use strict;
use warnings;
use lib 't';
my $VERSION = '1.999803'; # adjust manually to match latest release
my $VERSION = '1.999804'; # adjust manually to match latest release
use Test::More tests => 5;
......
......@@ -3,7 +3,7 @@
use strict;
use warnings;
use Test::More tests => 27;
use Test::More tests => 183;
my $class;
......@@ -16,23 +16,43 @@ while (<DATA>) {
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
my $x;
my $test = qq|\$x = $class -> from_bin("$in0");|;
my $desc = $test;
# As class method.
eval $test;
die $@ if $@; # this should never happen
{
my $x;
my $test = qq|\$x = $class -> from_bin("$in0");|;
subtest $desc, sub {
plan tests => 2,
eval $test;
die $@ if $@; # this should never happen