lua-json/tests-enhances-coverage-for-strings.additionalEscape.patch
2019-12-25 15:57:26 +08:00

47 lines
1.6 KiB
Diff

From 4556f70aa8fd4826551399701144ec56f4733954 Mon Sep 17 00:00:00 2001
From: Thomas Harning Jr <harningt@gmail.com>
Date: Mon, 18 Apr 2016 23:08:49 -0400
Subject: [PATCH] tests: enhances coverage for strings.additionalEscapes
decoding option
---
tests/lunit-tests.lua | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tests/lunit-tests.lua b/tests/lunit-tests.lua
index 30e82df..d25216c 100644
--- a/tests/lunit-tests.lua
+++ b/tests/lunit-tests.lua
@@ -1,6 +1,7 @@
local json = require("json")
local lunit = require("lunit")
local testutil = require("testutil")
+local lpeg = require("lpeg")
-- DECODE NOT 'local' due to requirement for testutil to access it
decode = json.decode.getDecoder(false)
@@ -35,6 +36,11 @@ function test_preprocess()
assert_equal('-Infinity', json.encode(1/0, {preProcess = function(x) return -x end}))
end
+function test_additionalEscapes_only()
+ -- Need to do escape while skipping escape character san-check
+ assert_equal("Hello", json.decode([["\S"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("S")) / "Hello", escapeCheck= false } }))
+end
+
local strictDecoder = json.decode.getDecoder(true)
local function buildStrictDecoder(f)
@@ -45,7 +51,7 @@ local function buildFailedStrictDecoder(f)
end
-- SETUP CHECKS FOR SEQUENCE OF DECODERS
for k, v in pairs(_M) do
- if k:match("^test_") and not k:match("_gen$") then
+ if k:match("^test_") and not k:match("_gen$") and not k:match("_only$") then
if k:match("_nostrict") then
_M[k .. "_strict_gen"] = buildFailedStrictDecoder(v)
else
--
1.8.3.1