File: array.t

package info (click to toggle)
libfortran-format-perl 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 968; fortran: 192; makefile: 2
file content (45 lines) | stat: -rwxr-xr-x 1,312 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
#!/home/ivan/bin/perl

use strict;
use warnings;
use Fortran::Format;
#use Data::Dumper;
use Test::More;

my $fname_in  = "read_arr_tests.txt";
my $fname_out = "read_arr_tests_out.txt";
open IN,  "<", $fname_in  or die "couldn't open $fname_in: $!\n";
open OUT, "<", $fname_out or die "couldn't open $fname_out: $!\n";

my (@input, @output);
{ local $/ = "\n\n"; @input = <IN>; @output = <OUT>; }

plan tests => scalar @input;

for (1 .. @input) {
    my ($in, $out) = (shift @input, shift @output);
    my ($type, $format_in, $input) = 
        $in =~ /^(.)FORMAT\((.*)\) *\n(.*)/s or die;
    my ($type_out, $format_out, $expected_output) = 
        $out =~ /^.FORMAT.*?\n 
               (.)FORMAT\((.*)\)\ *\n(.*)/xs or die;
    my $fi = Fortran::Format->new($format_in);
    my $fo = Fortran::Format->new($format_out);

    #print "in:\n$input\nexpected:\n$expected_output\n";
    #my $fh = IO::Scalar->new(\$input);
    #open my $fh, '<', \$input;
    my $arr;
    if ($type eq 'A') {
        ($arr) = $fi->read($input, 4);
    } elsif ($type eq 'M') {
        ($arr) = $fi->read($input, [2,2]);
    } else {
        die "unknown test type\n";
    }
    #print Dumper $arr;
    my $output = $fo->write($arr) . "\n";
    #print "got:\n$output\n";
    is($output, $expected_output, $format_in);
    #last;
}