File: 01test.t

package info (click to toggle)
libtest-hexstring-perl 0.03-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 108 kB
  • sloc: perl: 98; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,646 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w

use strict;

use Test::Builder::Tester tests => 5;

use Test::HexString;

test_out( "ok 1 - hello" );
is_hexstr( "hello", "hello", 'hello' );
test_test( "equal strings succeeds" );

test_out( "not ok 1 - binary" );
test_fail( +4 );
test_err( "#   at bytes 0-0xf (0-15)",
          "#   got: | 01 02 03 04 .. .. .. .. .. .. .. .. .. .. .. .. |....            |",
          "#   exp: | 01 02 03 05 .. .. .. .. .. .. .. .. .. .. .. .. |....            |" );
is_hexstr( "\1\2\3\4", "\1\2\3\5", 'binary' );
test_test( "differing binary strings fails" );

test_out( "not ok 1 - text" );
test_fail( +4 );
test_err( "#   at bytes 0-0xf (0-15)",
          "#   got: | 66 6f 6f 62 61 72 .. .. .. .. .. .. .. .. .. .. |foobar          |",
          "#   exp: | 66 6f 30 62 61 72 .. .. .. .. .. .. .. .. .. .. |fo0bar          |" );
is_hexstr( "foobar", "fo0bar", 'text' );
test_test( "differing text strings fails" );

my $longstring = join( "", map chr, 0 .. 255 ) x 10;
my $different = $longstring;
substr( $different, 1000, 1 ) = "A";

test_out( "not ok 1 - long string" );
test_fail( +4 );
test_err( "#   at bytes 0x3e0-0x3ef (992-1007)",
          "#   got: | e0 e1 e2 e3 e4 e5 e6 e7 41 e9 ea eb ec ed ee ef |........A.......|",
          "#   exp: | e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef |................|" );
is_hexstr( $different, $longstring, 'long string' );
test_test( "differing long text strings fails" );

test_out( "not ok 1 - ARRAY ref" );
test_fail( +2 );
test_err( "#   expected a plain string, was given a reference to ARRAY" );
is_hexstr( [], "array", 'ARRAY ref' );
test_test( "giving ARRAY ref fails" );