summaryrefslogtreecommitdiff
path: root/t/uni/write.t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-03-02 07:21:36 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-03-02 07:21:36 +0000
commit78da4d13e9515c4d820a5423a160a2c81889d633 (patch)
tree57f8664b2617e20db45689b9ba3a801f9357ea4c /t/uni/write.t
parent2bfba5f0e6f81fa3f5e291fd35e61c9d1112415c (diff)
downloadperl-78da4d13e9515c4d820a5423a160a2c81889d633.tar.gz
Further Unicode formats patching from Inaba Hiroto.
p4raw-id: //depot/perl@18794
Diffstat (limited to 't/uni/write.t')
-rw-r--r--t/uni/write.t96
1 files changed, 96 insertions, 0 deletions
diff --git a/t/uni/write.t b/t/uni/write.t
new file mode 100644
index 0000000000..95c3bbb36a
--- /dev/null
+++ b/t/uni/write.t
@@ -0,0 +1,96 @@
+#!./perl -w
+use strict;
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = qw(../lib .);
+ require "test.pl";
+}
+
+plan tests => 6;
+
+# Some tests for UTF8 and format/write
+
+our ($bitem1, $uitem1) = ("\x{ff}", "\x{100}");
+our ($bitem2, $uitem2) = ("\x{fe}", "\x{101}");
+our ($blite1, $ulite1) = ("\x{fd}", "\x{102}");
+our ($blite2, $ulite2) = ("\x{fc}", "\x{103}");
+our ($bmulti, $umulti) = ("\x{fb}\n\x{fa}\n\x{f9}\n",
+ "\x{104}\n\x{105}\n\x{106}\n");
+
+sub fmwrtest {
+ no strict 'refs';
+ my ($out, $format, $expect, $name) = @_;
+ eval "format $out =\n$format.\n"; die $@ if $@;
+ open $out, '>:utf8', 'Uni_write.tmp' or die "Can't create Uni_write.tmp";
+ write $out;
+ close $out or die "Could not close $out: $!";
+
+ open UIN, '<:utf8', 'Uni_write.tmp' or die "Can't open Uni_write.tmp";;
+ my $result = do { local $/; <UIN>; };
+ close UIN;
+
+ is($result, $expect, $name);
+}
+
+fmwrtest OUT1 => <<EOFORMAT, <<EOEXPECT, "non-UTF8 literal / UTF8 item (1)";
+$blite1 @<<
+\$uitem1
+$blite2 @<<
+\$bitem2
+EOFORMAT
+$blite1 $uitem1
+$blite2 $bitem2
+EOEXPECT
+
+fmwrtest OUT2 => <<EOFORMAT, <<EOEXPECT, "non-UTF8 literal / UTF8 item (2)";
+$blite1 @<<
+\$bitem1
+$blite2 @<<
+\$uitem2
+EOFORMAT
+$blite1 $bitem1
+$blite2 $uitem2
+EOEXPECT
+
+fmwrtest OUT3 => <<EOFORMAT, <<EOEXPECT, "UTF8 literal / non-UTF8 item (1)";
+$ulite1 @<<
+\$bitem1
+$blite2 @<<
+\$bitem2
+EOFORMAT
+$ulite1 $bitem1
+$blite2 $bitem2
+EOEXPECT
+
+fmwrtest OUT4 => <<EOFORMAT, <<EOEXPECT, "UTF8 literal / non-UTF8 item (2)";
+$blite1 @<<
+\$bitem1
+$ulite2 @<<
+\$bitem2
+EOFORMAT
+$blite1 $bitem1
+$ulite2 $bitem2
+EOEXPECT
+
+fmwrtest OUT5 => <<EOFORMAT, <<EOEXPECT, "non-UTF8 literal / UTF8 multiline";
+$blite1
+@*
+\$umulti
+$blite2
+EOFORMAT
+$blite1
+$umulti$blite2
+EOEXPECT
+
+fmwrtest OUT6 => <<EOFORMAT, <<EOEXPECT, "UTF8 literal / non-UTF8 multiline";
+$ulite1
+@*
+\$bmulti
+$blite2
+EOFORMAT
+$ulite1
+$bmulti$blite2
+EOEXPECT
+
+unlink 'Uni_write.tmp';