From 5c07ca9cf341c92f23325370c4a172c4e98e4152 Mon Sep 17 00:00:00 2001 From: Eric Lagergren Date: Mon, 8 Apr 2019 02:47:43 -0700 Subject: [PATCH] update .gitignore --- .gitignore | 27 +++++++++++++++++++-------- fuzz/SetString/SetString.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 fuzz/SetString/SetString.go diff --git a/.gitignore b/.gitignore index 0256fc5..636c8f0 100644 --- a/.gitignore +++ b/.gitignore @@ -19,28 +19,39 @@ _cgo_export.* _testmain.go +# Artifacts, profiles, etc. *.exe *.test *.prof - *.tags - .git *.swp *.txt *.tags -old.* +tags *.test *.out +*.zip +*.gz + +# Internal literature/ j/ -*.txt -fuzz/ + +# Fuzzing +fuzz/**/corpus +fuzz/**/crashers +fuzz/**/suppressions + +# Benchmark artifacts benchmarks/decbench *.xml *.class -*.gz +.idea/ + +# Development internal/nat/ + +# Testing x.bash -tags -*.decTest \ No newline at end of file +*.decTest diff --git a/fuzz/SetString/SetString.go b/fuzz/SetString/SetString.go new file mode 100644 index 0000000..eb0c2f3 --- /dev/null +++ b/fuzz/SetString/SetString.go @@ -0,0 +1,37 @@ +package fuzz + +import ( + "fmt" + "runtime/debug" + + "github.com/ericlagergren/decimal" +) + +func Fuzz(data []byte) int { + debug.SetTraceback("system") + + d := new(decimal.Big) + d, ok := d.SetString(string(data)) + if !ok { + if decimal.Regexp.Match(data) && d.Context.Err() == nil { + panic(fmt.Sprintf("should work: %q", data)) + } + return 0 + } + d2 := new(decimal.Big) + ds := d.String() + d2, ok = d2.SetString(ds) + if !ok { + panic(fmt.Sprintf("SetString(%q) == nil, false", ds)) + } + if d.Cmp(d2) != 0 { + panic(fmt.Sprintf(` +got : %#v (%q) +wanted: %#v (%q) +`, d2, d2, d, d)) + } + if !decimal.Regexp.Match(data) { + panic(fmt.Sprintf("got: %q", data)) + } + return 1 +}