File: 2-test.t

package info (click to toggle)
libdata-binary-perl 0.01-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 100 kB
  • sloc: perl: 35; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 792 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use strict;
use warnings;

use Test::More tests => 8;

use Data::Binary qw(is_text is_binary);

my $text_test = '12345678' x 100;
my $binary1_test = "\f234\f67\cg" x 100;
my $binary2_test = "\f234\xff67\x80" x 100;
my $binary3_test = "12345678" . "\x00" . $text_test;

ok(is_text($text_test), "Plain text is text");
ok(! is_binary($text_test), "Plain text is not binary");

ok(! is_text($binary1_test), "Data >30% control codes is not text");
ok(is_binary($binary1_test), "Data >30% control codes is binary");

ok(! is_text($binary2_test), "Data with high-order bits is not text");
ok(is_binary($binary2_test), "Data with high-order bits is binary");

ok(! is_text($binary3_test), "Data with a single null is not text");
ok(is_binary($binary3_test), "Data with a single null is binary");

1;