diff --git a/object.js b/object.js index 3e446e2..d070489 100755 --- a/object.js +++ b/object.js @@ -89,8 +89,8 @@ function(text, tab_size, leading_tabs){ text = tab != '' ? text.replace(/\t/g, tab) : text + // trim the tail and remove leading blank lines... var lines = text.trimEnd().split(/\n/) - // remove leading blank lines... while(lines[0].trim() == ''){ lines.shift() } // count common indent... diff --git a/test.js b/test.js index c994d51..157bfe8 100755 --- a/test.js +++ b/test.js @@ -673,20 +673,52 @@ var cases = test.Cases({ }, text_cases: [ - [`a - b - c`, - 'a\n\tb\nc'], - [`a - b - c`, - 'a\n\tb\n\tc'], + // 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' }, + + { input: `a + b + c`, + all: 'a\nb\nc' }, + + + { input: ` + a + c`, + all: 'a\n c' }, + + { input: `a + b + c`, + all: `a\n b\nc` }, ], text: function(assert){ - this.text_cases.map(function([orig, target]){ - assert(object.doc([orig]) == target) - assert(object.text([orig]) == target) - }) + this.text_cases + .map(function({input, doc, text, all}, i){ + var res + + ;(doc || all) + && assert((res = object.doc([input])) == (doc || all), + 'doc(text_cases['+i+']):\n' + + res + +'\n---\n' + + (doc || all)) + ;(text || all) + && assert((res = object.text([input])) == (text || all), + 'text(text_cases['+i+']):\n' + + res + +'\n---\n' + + (text || all)) + }) }, })