aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/lulu/testchecks/cost
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/lulu/testchecks/cost')
-rw-r--r--cmd/lulu/testchecks/cost20
1 files changed, 19 insertions, 1 deletions
diff --git a/cmd/lulu/testchecks/cost b/cmd/lulu/testchecks/cost
index 5ce1d48..479bdf4 100644
--- a/cmd/lulu/testchecks/cost
+++ b/cmd/lulu/testchecks/cost
@@ -1 +1,19 @@
-grep -E '^total: [1-9][0-9]*(\.[0-9]+)? [A-Z]{3}$' $1
+money='[0-9]+(\.[0-9]+)? [A-Z]{3}'
+for field in "item 0" "item 1" "shipping" "fulfillment" "discount" "tax" "total"
+do
+ re="$(printf '^%s: +%s *$' "${field}" "${money}")"
+ echo "$re"
+ grep -E "$re" $1
+done
+grep -E -v '^item [^01]' $1
+awk '
+ # Ensure sum of fields equals total.
+ !/^total/ { wantTotal += $(NF-1) }
+ /^total/ {
+ gotTotal = $(NF-1)
+ if (gotTotal > wantTotal+1e7 || gotTotal < wantTotal-1e7) {
+ printf "total (%f) does not match expected (%f)\n", gotTotal, wantTotal >>"/dev/stderr"
+ exit 1
+ }
+ }
+' $1