From e649cb811e757f4f8385e66da5d88123a25679fe Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 5 Oct 2020 19:59:13 +0100 Subject: [PATCH] do JS bigfloat repr tests Signed-off-by: Ian Jackson --- .gitignore | 1 + Makefile | 6 +++++- extract-bf-tests | 13 +++++++++++++ src/bigfloat.rs | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 extract-bf-tests diff --git a/.gitignore b/.gitignore index 41bbff84..3cd8f27b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 2e445ad7..e1ef891c 100644 --- 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 index 00000000..b23f8693 --- /dev/null +++ b/extract-bf-tests @@ -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; +} diff --git a/src/bigfloat.rs b/src/bigfloat.rs index 51d7a6d3..69c75451 100644 --- a/src/bigfloat.rs +++ b/src/bigfloat.rs @@ -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 { -- 2.30.2