From 6f9eb299570e0412d2fed45379051b0f0e35bf79 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 30 Dec 2025 03:26:08 +0300 Subject: [PATCH] docs and tests... Signed-off-by: Alex A. Naanou --- serialize2.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- test.js | 10 ++++------ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/serialize2.js b/serialize2.js index ce21158..65d5c15 100644 --- a/serialize2.js +++ b/serialize2.js @@ -48,10 +48,54 @@ var debug = { // string - string to use for indenting // // -// serialize(obj, path, seen, indent, depth) +// serialize(obj, base_path, seen, indent, depth) // -> str // // +// Paths +// A path is a chain of indexes/keys leading to a specific object in +// tree. +// +// the root object is referenced by an empty path array. +// +// For sets, positional indexes are used, i.e. a set is treated like +// an array ov values. +// +// For maps a two number index is used with the first being the position +// of the item and the second indicated if the target is the key or the +// value. i.e. a map is treated like an array of key value pairs. +// +// +// Examples: +// Object paths +// --------------------------------------------------------------- +// obj = [ <- [] +// null, <- [0] +// [ +// 'a', +// 'b', <- [1, 1] +// 'c', +// ], +// Set([ +// 1, +// 2, +// 3, <- [2, 2] +// ]), +// Map([i <- [3] +----- index of elemnt in map +// [ / +--- 0 means key +// 'key', <- [3, 0, 0] +// 'value' <- [3, 0, 1] +// ], +--- 1 means value +// [ +// [ +// 123 <- [3, 1, 0, 0] +// ], +// 'got tired of thinking up names', +// ], +// ]), +// ] +// +// // XXX add function support... // XXX need to destinguish between map key and value in path... // XXX BUG: using non-whitespace as indent breaks the depth of the first diff --git a/test.js b/test.js index 9342e3a..140e9e7 100755 --- a/test.js +++ b/test.js @@ -57,14 +57,12 @@ test.Modifiers({ return `[${ setup }]` }, 'object-stuffed': function(assert, setup){ return `{"key":${ setup }}` }, - //* XXX need better indexing... - // .getItem(..) / .setItem(..) break on recursive structures - // in maps/sets... - 'map-stuffed': function(assert, setup){ - return `Map([["key",${ setup }],[${ setup },"value"]])` }, 'set-stuffed': function(assert, setup){ return `Set([${ setup }])` }, - //*/ + 'map-key-stuffed': function(assert, setup){ + return `Map([[${ setup },"value"]])` }, + 'map-value-stuffed': function(assert, setup){ + return `Map([["key",${ setup }]])` }, }) test.Tests({