chiark / gitweb /
do JS bigfloat repr tests
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 5 Oct 2020 18:59:13 +0000 (19:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 5 Oct 2020 18:59:13 +0000 (19:59 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitignore
Makefile
extract-bf-tests [new file with mode: 0755]
src/bigfloat.rs

index 41bbff84d5ec432b6b64851b68b488c2b5f3e82c..3cd8f27b158313b0a027be77d34f34de4d19ae9d 100644 (file)
@@ -1,5 +1,6 @@
 templates/script.js
 templates/bigfloat-tests.js
+templates/bigfloat-tests-auto.ts
 templates/LICENCE
 templates/AGPLv3
 templates/CC-BY-SA-3.0
index 2e445ad72a3ab08fbdeb7addf095f9ad7ab3cad1..e1ef891cca8bf4ca0e2b5869d5eb92f39c9b78a1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,11 @@ templates/%.js: tsc-wrap tsconfig.json
        ./tsc-wrap $@ tsconfig.json $(filter %.ts,$^)
 
 templates/script.js: $(TS_SRC_FILES)
-templates/bigfloat-tests.js: templates/bigfloat.ts templates/bigfloat-tests.ts
+templates/bigfloat-tests.js: templates/bigfloat.ts \
+       templates/bigfloat-tests.ts templates/bigfloat-tests-auto.ts
+
+templates/bigfloat-tests-auto.ts: extract-bf-tests src/bigfloat.rs
+       ./$^ >$@.tmp && mv -f $@.tmp $@
 
 js-check: templates/bigfloat-tests.js
        nodejs <$<
diff --git a/extract-bf-tests b/extract-bf-tests
new file mode 100755 (executable)
index 0000000..b23f869
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+use strict;
+
+sub chk_repr ($) {
+  my ($p) = @_;
+  print "assert_eq($p, Bigfloats.pack(Bigfloats.unpack($p as any)));\n";
+}
+
+while (<>) {
+  next unless m/^mod test/..0;
+  my $l = $_;
+  $l =~ s{bf\((\"[^"]+\")\)}{ chk_repr($1) }ge;
+}
index 51d7a6d3ec29a643a4d812b48cf4a5183965fd3e..69c75451ed149343606ac43a4d29826d72a10b3f 100644 (file)
@@ -385,6 +385,7 @@ impl Serialize for Bigfloat {
 
 #[cfg(test)]
 mod test {
+  // everything from here on is seded by the js test extractor!
   use super::*;
 
   fn bf(s: &str) -> Bigfloat {