From 0dfe76425cecd07f62fa2448c8f4da7d9147c008 Mon Sep 17 00:00:00 2001 From: Drew Boyuka Date: Tue, 22 Mar 2016 13:18:01 -0400 Subject: [PATCH] Added tricky JSON tests (issue #5) --- parser_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/parser_test.go b/parser_test.go index 60014c05..b891d0d3 100644 --- a/parser_test.go +++ b/parser_test.go @@ -118,3 +118,27 @@ func TestInvalidJSON(t *testing.T) { t.Errorf("Should raise malformed json error: ", e) } } + +func TestTrickyJSON(t *testing.T) { + killer := []byte(`{ + "parentkey": { + "childkey": { + "grandchildkey": 111 + }, + "otherchildkey": 222 + }, + "bad key\"good key": 333, + }`) + + if data, jtype, _, _ := Get(killer, "childkey"); jtype != NotExist { + t.Errorf(`Get("childkey") should not exist, but found data %s`, string(data)) + } + + if data, jtype, _, _ := Get(killer, "parentkey", "childkey", "otherchildkey"); jtype != NotExist { + t.Errorf(`Get("parentkey", "childkey", "otherchildkey") should not exist, but found data %s`, string(data)) + } + + if data, jtype, _, _ := Get(killer, "good key"); jtype != NotExist { + t.Errorf(`Get("good key") should not exist, but found data %s`, string(data)) + } +}