summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-11-10 13:27:18 +0000
committerdakkar <dakkar@thenautilus.net>2016-11-10 13:39:29 +0000
commit61f964216b16b25200e2a2ac961f7444c0570daf (patch)
treea39731665727a5f0a5aaa20c1c8c92a8f1a1ffcc /t
parenttry using more magic (diff)
downloadData-QRCode-61f964216b16b25200e2a2ac961f7444c0570daf.tar.gz
Data-QRCode-61f964216b16b25200e2a2ac961f7444c0570daf.tar.bz2
Data-QRCode-61f964216b16b25200e2a2ac961f7444c0570daf.zip
split into input / qrcode
Diffstat (limited to 't')
-rw-r--r--t/base.t31
-rw-r--r--t/input.t33
-rw-r--r--t/qrcode.t68
3 files changed, 101 insertions, 31 deletions
diff --git a/t/base.t b/t/base.t
deleted file mode 100644
index 25bda6a..0000000
--- a/t/base.t
+++ /dev/null
@@ -1,31 +0,0 @@
-#!perl
-use strict;
-use warnings;
-use Test2::Bundle::Extended;
-use Data::QRCode;
-
-my $qr = Data::QRCode->new('some words','M');
-
-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";
-}
-
-note $text;
-
-ok($text);
-
-done_testing;
diff --git a/t/input.t b/t/input.t
new file mode 100644
index 0000000..91e8afc
--- /dev/null
+++ b/t/input.t
@@ -0,0 +1,33 @@
+#!perl
+use strict;
+use warnings;
+use Test2::Bundle::Extended;
+use Data::QRCode::Input;
+
+my $input = Data::QRCode::Input->new();
+
+$input->version(12);
+$input->error_correction_level(Data::QRCode::Input::ECLEVEL_M);
+
+is(
+ $input->version,
+ 12,
+ 'version should round-trip',
+);
+
+is(
+ $input->error_correction_level,
+ Data::QRCode::Input::ECLEVEL_M,
+ 'ec level should round-trip',
+);
+
+is(
+ $input->append(
+ Data::QRCode::Input::MODE_8,
+ 'some data',
+ ),
+ 0,
+ 'append should work and return 0 on success',
+);
+
+done_testing;
diff --git a/t/qrcode.t b/t/qrcode.t
new file mode 100644
index 0000000..f82c5ff
--- /dev/null
+++ b/t/qrcode.t
@@ -0,0 +1,68 @@
+#!perl
+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);
+
+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;