chiark / gitweb /
README: Fix formatting of geckdodriver section
[otter.git] / extract-bf-tests
1 #!/usr/bin/perl -w
2 use strict;
3
4 sub chk_repr ($) {
5   my ($p) = @_;
6   print "assert_eq($p, Bigfloats.pack(Bigfloats.unpack($p as any)));\n";
7 }
8
9 my $sre = qr{\"[^"]+\"};
10
11 print <<END;
12 // autogenerated from $0 @ARGV
13 let mk : any;
14 END
15
16 while (<>) {
17   next unless m/^mod test/..0;
18   my $l = $_;
19   $l =~ s{bf\(($sre)\)}{ chk_repr($1) }ge;
20
21   if (m{^ +fn addition}..m{^ +\#\[test\]}) {
22     if (m{^ +mk\(($sre)\)}) {
23       print "mk = $1;\n";
24     } elsif (m{^ +\.chk\((\w+),\s*($sre)\)\s*$}) {
25       print "mk = Bigfloats.add(mk, $1); assert_eq(mk, $2);\n";
26     }
27   }
28 }