summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/qrcode.t50
-rw-r--r--t/result.t68
2 files changed, 85 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
diff --git a/t/result.t b/t/result.t
new file mode 100644
index 0000000..c092d19
--- /dev/null
+++ b/t/result.t
@@ -0,0 +1,68 @@
+#!perl
+use strict;
+use warnings;
+use Test2::Bundle::Extended;
+use Data::QRCode::Input;
+use Data::QRCode::Result;
+
+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::Result->new($input);
+
+is(
+ $qr->version,
+ 1,
+ 'version should be set',
+);
+
+is(
+ $qr->width,
+ 21,
+ 'width should be set',
+);
+
+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";
+}
+
+is($text,<<'QRCODE','data should be as expected');
+RRRRRRR F DDD RRRRRRR
+R R F D R R
+R RRR R D D R RRR R
+R RRR R FDD R RRR R
+R RRR R R RRR R
+R R D R R
+RRRRRRR T T T RRRRRRR
+ F D
+F FF FTF DD F F FF
+ DD D DDD D DD D
+D DDTD DD D D DDD
+DDD D DD D D D D
+ D TD D D D D
+ * D DD D DD
+RRRRRRR FD D DDD
+R R F DDDD DDD D
+R RRR R D D D DD
+R RRR R F D D D D D
+R RRR R F DD DD DD
+R R DD D D D
+RRRRRRR F DDD D D
+QRCODE
+
+done_testing;