summaryrefslogtreecommitdiff
path: root/t/qrcode.t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-11-10 14:26:47 +0000
committerdakkar <dakkar@thenautilus.net>2016-11-10 14:26:47 +0000
commit3db58a4fe8a121093bc5c5287eb808f71de87441 (patch)
treeb6ecd45739d931ae4a096ac2876674e16386a001 /t/qrcode.t
parentmove example script into examples/ (diff)
downloadData-QRCode-3db58a4fe8a121093bc5c5287eb808f71de87441.tar.gz
Data-QRCode-3db58a4fe8a121093bc5c5287eb808f71de87441.tar.bz2
Data-QRCode-3db58a4fe8a121093bc5c5287eb808f71de87441.zip
move QRcode* to ::Result, wrap in Moo
Diffstat (limited to 't/qrcode.t')
-rw-r--r--t/qrcode.t50
1 files changed, 17 insertions, 33 deletions
diff --git a/t/qrcode.t b/t/qrcode.t
index f82c5ff..14e8bd7 100644
--- a/t/qrcode.t
+++ b/t/qrcode.t
@@ -3,43 +3,27 @@ use strict;
use warnings;
use Test2::Bundle::Extended;
use Data::QRCode;
-use Data::QRCode::Input;
-my $input = Data::QRCode::Input->new;
-$input->error_correction_level(Data::QRCode::Input::ECLEVEL_M);
-$input->append(Data::QRCode::Input::MODE_8,'some words');
+my $qr = Data::QRCode->new({
+ input_data => 'some words',
+});
-my $qr = Data::QRCode->new($input);
-
-is(
- $qr->version,
- 1,
- 'version should be set',
-);
-
-is(
- $qr->width,
- 21,
- 'width should be set',
+my $text_matrix = $qr->map(
+ sub{
+ my ($data) = @_;
+ !$data->{color} ? ' ' :
+ $data->{in_data} ? 'D' :
+ $data->{in_format} ? 'F' :
+ $data->{in_version} ? 'V' :
+ $data->{in_timing} ? 'T' :
+ $data->{in_alignment} ? 'A' :
+ $data->{in_finder} ? 'R' :
+ '*';
+ },
);
-my $text;
-for my $y (0..$qr->width-1) {
- for my $x (0..$qr->width-1) {
- my $data = $qr->data_at($x,$y);
- $text .= (
- !$data->{color} ? ' ' :
- $data->{in_data} ? 'D' :
- $data->{in_format} ? 'F' :
- $data->{in_version} ? 'V' :
- $data->{in_timing} ? 'T' :
- $data->{in_alignment} ? 'A' :
- $data->{in_finder} ? 'R' :
- '*'
- );
- }
- $text .= "\n";
-}
+my $text = join "\n", map { join '',@{$_} } @{$text_matrix};
+$text .= "\n";
is($text,<<'QRCODE','data should be as expected');
RRRRRRR F DDD RRRRRRR