From 02e327485e506812194dafb2cd8f75741cb32982 Mon Sep 17 00:00:00 2001 From: webreflection Date: Mon, 30 Mar 2026 10:13:40 +0200 Subject: [PATCH] Fix #86 - Test all variants through deeply nsted recursion --- test/shared.cjs | 27 +++++++++++++++++++++++++++ test/shared.json | 1 + test/shared.php | 22 ++++++++++++++++++++++ test/shared.py | 22 ++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 test/shared.cjs create mode 100644 test/shared.json create mode 100644 test/shared.php create mode 100644 test/shared.py diff --git a/test/shared.cjs b/test/shared.cjs new file mode 100644 index 0000000..ec196f2 --- /dev/null +++ b/test/shared.cjs @@ -0,0 +1,27 @@ +const { parse, stringify } = require(__dirname + '/../cjs'); + +let arr = ['arr', 1]; +let obj = { obj: 2 }; + +for (let i = 0; i < 64; i++) { + arr = [arr]; + obj = { obj: obj }; +} + +const str = stringify([arr, obj]); + +require('fs').writeFileSync(__dirname + '/shared.json', str); + +[arr, obj] = parse(str); + +for (let i = 0; i < 64; i++) { + arr = arr[0]; + obj = obj.obj; +} + +console.assert( + arr.length === 2 && + arr[0] === 'arr' && + arr[1] === 1 && + obj.obj === 2 +); diff --git a/test/shared.json b/test/shared.json new file mode 100644 index 0000000..7adf9fc --- /dev/null +++ b/test/shared.json @@ -0,0 +1 @@ +[["1","2"],["3"],{"obj":"4"},["5"],{"obj":"6"},["7"],{"obj":"8"},["9"],{"obj":"10"},["11"],{"obj":"12"},["13"],{"obj":"14"},["15"],{"obj":"16"},["17"],{"obj":"18"},["19"],{"obj":"20"},["21"],{"obj":"22"},["23"],{"obj":"24"},["25"],{"obj":"26"},["27"],{"obj":"28"},["29"],{"obj":"30"},["31"],{"obj":"32"},["33"],{"obj":"34"},["35"],{"obj":"36"},["37"],{"obj":"38"},["39"],{"obj":"40"},["41"],{"obj":"42"},["43"],{"obj":"44"},["45"],{"obj":"46"},["47"],{"obj":"48"},["49"],{"obj":"50"},["51"],{"obj":"52"},["53"],{"obj":"54"},["55"],{"obj":"56"},["57"],{"obj":"58"},["59"],{"obj":"60"},["61"],{"obj":"62"},["63"],{"obj":"64"},["65"],{"obj":"66"},["67"],{"obj":"68"},["69"],{"obj":"70"},["71"],{"obj":"72"},["73"],{"obj":"74"},["75"],{"obj":"76"},["77"],{"obj":"78"},["79"],{"obj":"80"},["81"],{"obj":"82"},["83"],{"obj":"84"},["85"],{"obj":"86"},["87"],{"obj":"88"},["89"],{"obj":"90"},["91"],{"obj":"92"},["93"],{"obj":"94"},["95"],{"obj":"96"},["97"],{"obj":"98"},["99"],{"obj":"100"},["101"],{"obj":"102"},["103"],{"obj":"104"},["105"],{"obj":"106"},["107"],{"obj":"108"},["109"],{"obj":"110"},["111"],{"obj":"112"},["113"],{"obj":"114"},["115"],{"obj":"116"},["117"],{"obj":"118"},["119"],{"obj":"120"},["121"],{"obj":"122"},["123"],{"obj":"124"},["125"],{"obj":"126"},["127"],{"obj":"128"},["129"],{"obj":"130"},["131",1],{"obj":2},"arr"] \ No newline at end of file diff --git a/test/shared.php b/test/shared.php new file mode 100644 index 0000000..a80f560 --- /dev/null +++ b/test/shared.php @@ -0,0 +1,22 @@ +obj; +} + +assert(count($arr) == 2 && $arr[0] == 'arr' && $arr[1] == 1 && $obj->obj == 2); + +assert(Flatted::stringify($json) == $str); + +?> diff --git a/test/shared.py b/test/shared.py new file mode 100644 index 0000000..c6dfda4 --- /dev/null +++ b/test/shared.py @@ -0,0 +1,22 @@ +# ⚠️ RUN node test/shared.cjs FIRST +# then python test/shared.py + +import os, sys + +__dir__ = os.path.dirname(__file__) +sys.path.append(os.path.join(__dir__, '..', 'python')) + +from flatted import parse, stringify + +with open(os.path.join(__dir__, 'shared.json'), 'r') as f: + str = f.read() + +arr, obj = parse(str) + +for i in range(64): + arr = arr[0] + obj = obj['obj'] + +assert len(arr) == 2 and arr[0] == 'arr' and arr[1] == 1 and obj['obj'] == 2 + +assert stringify(parse(str), separators=(',', ':')) == str