xref: /openbsd/gnu/usr.bin/perl/t/opbasic/qq.t (revision 5dea098c)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    @INC = '../lib';
6}
7
8# This file uses a specially crafted is() function rather than that found in
9# t/test.pl or Test::More.  Hence, we place this file in directory t/opbasic.
10
11print q(1..30
12);
13
14# This is() function is written to avoid ""
15my $test = 1;
16sub is {
17    my($left, $right) = @_;
18
19    if ($left eq $right) {
20      printf 'ok %d
21', $test++;
22      return 1;
23    }
24    foreach ($left, $right) {
25      # Comment out these regexps to map non-printables to ord if the perl under
26      # test is so broken that it is not helping
27      s/([^-+A-Za-z_0-9])/sprintf q{'.chr(%d).'}, ord $1/ge;
28      $_ = sprintf q('%s'), $_;
29      s/^''\.//;
30      s/\.''$//;
31    }
32    printf q(not ok %d - got %s expected %s
33), $test++, $left, $right;
34
35    printf q(# Failed test at line %d
36), (caller)[2];
37
38    return 0;
39}
40
41is ("\x53", chr 83);
42is ("\x4EE", chr (78) . 'E');
43is ("\x4i", chr (4) . 'i');	# This will warn
44is ("\xh", chr (0) . 'h');	# This will warn
45is ("\xx", chr (0) . 'x');	# This will warn
46is ("\xx9", chr (0) . 'x9');	# This will warn. \x9 is tab in EBCDIC too?
47is ("\x9_E", chr (9) . '_E');	# This will warn
48
49is ("\x{4E}", chr 78);
50is ("\x{ 4E }", chr 78);
51is ("\x{6_9}", chr 105);
52is ("\x{_6_3}", chr 99);
53is ("\x{_6B}", chr 107);
54
55is ("\x{9__0}", chr 9);		# multiple underscores not allowed.
56is ("\x{77_}", chr 119);	# trailing underscore warns.
57is ("\x{6FQ}z", chr (111) . 'z');
58
59is ("\x{0x4E}", chr 0);
60is ("\x{x4E}", chr 0);
61
62is ("\x{0065}", chr 101);
63is ("\x{000000000000000000000000000000000000000000000000000000000000000072}",
64    chr 114);
65is ("\x{0_06_5}", chr 101);
66is ("\x{1234}", chr 4660);
67is ("\x{10FFFD}", chr 1114109);
68is ("\400", chr 0x100);
69is ("\600", chr 0x180);
70is ("\777", chr 0x1FF);
71is ("a\o{120}b", "a" . chr(0x50) . "b");
72is ("a\o{ 120 }b", "a" . chr(0x50) . "b");
73is ("a\o{400}b", "a" . chr(0x100) . "b");
74is ("a\o{1000}b", "a" . chr(0x200) . "b");
75
76# Maybe \x{} should be an error, but if not it should certainly mean \x{0}
77# rather than anything else.
78is ("\x{}", chr(0));
79