From 8a9a62d9f38dd4d98e05c38e11847a0484bba702 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 14 Sep 2020 00:29:13 +0300 Subject: [PATCH] minor fixes, still not done yet... Signed-off-by: Alex A. Naanou --- object.js | 13 ++++++++----- test.js | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/object.js b/object.js index d070489..6761a53 100755 --- a/object.js +++ b/object.js @@ -67,6 +67,7 @@ module.LEADING_TABS = 1 // | return a + b } | return a + b // | |} // +// // NOTE: this will trim out both leading and trailing white-space. // NOTE: this is generally code-agnostic with one sigificant // exception -- normalizeIndent(..) will break code written @@ -100,10 +101,12 @@ function(text, tab_size, leading_tabs){ return e.trim().length == 0 // ignore 0 indent of first line... || (i == 0 && indent == 0) ? - l + l || indent // last line -- ignore leading_tabs if lower indent... - : i == lines.length-1 && indent > l ? - Math.max(l-leading_tabs, 0) + // XXX BUG this does messes things up for 2 liners... + : i == lines.length-1 + && indent >= l ? + Math.max(indent - leading_tabs, 0) // initial state... : l < 0 ? indent @@ -111,9 +114,9 @@ function(text, tab_size, leading_tabs){ : Math.min(l, indent) }, -1) // normalize... return lines - .map(function(line, i){ + .map(function(line, i){ return i == 0 ? - line + line : line.slice(l) }) .join('\n') .trim() } diff --git a/test.js b/test.js index cf73334..a786533 100755 --- a/test.js +++ b/test.js @@ -672,31 +672,34 @@ var cases = test.Cases({ assert(xx.call(null), 'xx.call(null)') }, - // XXX two-liners still not fully passing... text_cases: [ // NOTE: there is no way to know what is the indent of 'a' // relative to the rest of the text... // ...without reading the source file, and that should // be avoided. - // XXX FAIL: for some reason the two line case does not work... { input: `a c`, - all: 'a\nc', }, - - { input: `a - c`, - all: 'a\nc' }, - + text: 'a\nc', + doc: 'a\n c'}, { input: `a b c`, - all: 'a\nb\nc' }, + text: 'a\nb\nc', + doc: 'a\n b\n c' }, + // XXX text(..): c is not indented... { input: ` a c`, all: 'a\n c' }, + // XXX text(..): losing all lines but 0 and -1... + // XXX text(..): c is not indented... + { input: ` + a + b + c`, + all: 'a\nb\n c' }, { input: `a b @@ -710,16 +713,24 @@ var cases = test.Cases({ ;(doc || all) && assert((res = object.doc([input])) == (doc || all), - 'doc(text_cases['+i+']):\n' - + res - +'\n---\n' - + (doc || all)) + 'doc(text_cases['+i+']):' + +'\n---input---\n' + + input + +'\n---Expected---\n' + + (doc || all) + +'\n---Got---\n' + + res + +'\n---') ;(text || all) && assert((res = object.text([input])) == (text || all), - 'text(text_cases['+i+']):\n' - + res - +'\n---\n' - + (text || all)) }) }, + 'text(text_cases['+i+']):' + +'\n---input---\n' + + input + +'\n---Expected---\n' + + (text || all) + +'\n---Got---\n' + + res + +'\n---') }) }, })