From 6c2d82a4da7fa5565641fbd886a8e32211448535 Mon Sep 17 00:00:00 2001 From: Alexandr Mayorskiy Date: Sun, 12 Apr 2020 21:35:45 +0300 Subject: [PATCH] fix typo & add test for noCopy --- README.md | 2 +- tests/nocopy_test.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67ee8fc..7153930 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Besides standart json tag options like 'omitempty' the following are supported: objects which are not hold in memory after decoding and immediate usage. Note if string requires unescaping it will be processed as normally. * 'intern' - string "interning" (deduplication) to save memory when the very - same string dictionory values are often met all over the structure. + same string dictionary values are often met all over the structure. See below for more details. ## Generated Marshaler/Unmarshaler Funcs diff --git a/tests/nocopy_test.go b/tests/nocopy_test.go index 2ca0e86..45592a2 100644 --- a/tests/nocopy_test.go +++ b/tests/nocopy_test.go @@ -48,6 +48,17 @@ func TestNocopy(t *testing.T) { } }) if allocsPerRun != 1 { - t.Fatalf("expected 1 allocs, got %f", allocsPerRun) + t.Fatalf("noCopy field unmarshal: expected 1 allocs, got %f", allocsPerRun) + } + + data = []byte(`{"a": "valueNoCopy"}`) + allocsPerRun = testing.AllocsPerRun(1000, func() { + easyjson.Unmarshal(data, &res) + if res.A != "valueNoCopy" { + t.Fatalf("wrong value: %q", res.A) + } + }) + if allocsPerRun != 2 { + t.Fatalf("copy field unmarshal: expected 2 allocs, got %f", allocsPerRun) } }