chiark / gitweb /
Revert "get rid of some old test extractor"
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 11 Oct 2020 00:07:51 +0000 (01:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 11 Oct 2020 00:08:07 +0000 (01:08 +0100)
Actually we want to convert this to Rust, not just delete it.

This reverts commit 01cd4e9673de59576398c7d142ddb6e3586f5705.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
extract-bf-tests [new file with mode: 0755]
templates/bigfloat-tests.ts [new file with mode: 0644]

diff --git a/extract-bf-tests b/extract-bf-tests
new file mode 100755 (executable)
index 0000000..c13dda7
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+use strict;
+
+sub chk_repr ($) {
+  my ($p) = @_;
+  print "assert_eq($p, Bigfloats.pack(Bigfloats.unpack($p as any)));\n";
+}
+
+my $sre = qr{\"[^"]+\"};
+
+print <<END;
+// autogenerated from $0 @ARGV
+let mk : any;
+END
+
+while (<>) {
+  next unless m/^mod test/..0;
+  my $l = $_;
+  $l =~ s{bf\(($sre)\)}{ chk_repr($1) }ge;
+
+  if (m{^ +fn addition}..m{^ +\#\[test\]}) {
+    if (m{^ +mk\(($sre)\)}) {
+      print "mk = $1;\n";
+    } elsif (m{^ +\.chk\((\w+),\s*($sre)\)\s*$}) {
+      print "mk = Bigfloats.add(mk, $1); assert_eq(mk, $2);\n";
+    }
+  }
+}
diff --git a/templates/bigfloat-tests.ts b/templates/bigfloat-tests.ts
new file mode 100644 (file)
index 0000000..d2c50cb
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- JavaScript -*-
+// Copyright 2020 Ian Jackson
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+function assert_eq(a: string, b: string) {
+  if (a == b) return;
+  console.log(['unequal', a, b]);
+  throw('unequal');
+}
+
+let x : any;
+let y : any
+let i : any
+
+x = "!0000 ffff_ffff_fff0" as any;
+y = "!0000 0000_0000_0040" as any;
+i = Bigfloats.iter_upto(x, y, 4);
+
+assert_eq(i(), "+0000 0000_0000_0000");
+assert_eq(i(), "+0000 0000_0000_0010");
+assert_eq(i(), "+0000 0000_0000_0020");
+assert_eq(i(), "+0000 0000_0000_0030");
+
+x = "!0000 ffff_ffff_fffe" as any;
+y = "!0000 0000_0000_0001" as any;
+i = Bigfloats.iter_upto(x, y, 4);
+
+assert_eq(i(), "!0000 ffff_ffff_ffff 3333_3333_3333");
+assert_eq(i(), "!0000 ffff_ffff_ffff 6666_6666_6666");
+assert_eq(i(), "!0000 ffff_ffff_ffff 9999_9999_9999");
+assert_eq(i(), "!0000 ffff_ffff_ffff cccc_cccc_cccc");