From 43e70f817e0a201de118423bd373941e60e83b9e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 12 Sep 2020 03:40:35 +0300 Subject: [PATCH] reworked text testing, still failing some tests, not yet sure if the error is in the test or in code... Signed-off-by: Alex A. Naanou --- object.js | 2 +- test.js | 56 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 13 deletions(-) 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)) + }) }, })