minor fixes, still not done yet...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-09-14 00:29:13 +03:00
parent d0d87f223f
commit 8a9a62d9f3
2 changed files with 36 additions and 22 deletions

View File

@ -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

45
test.js
View File

@ -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---') }) },
})