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 <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-09-12 03:40:35 +03:00
parent 2429835d92
commit 43e70f817e
2 changed files with 45 additions and 13 deletions

View File

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

46
test.js
View File

@ -673,19 +673,51 @@ var cases = test.Cases({
},
text_cases: [
[`a
// 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`,
'a\n\tb\nc'],
[`a
all: 'a\nb\nc' },
{ input: `
a
c`,
all: 'a\n c' },
{ input: `a
b
c`,
'a\n\tb\n\tc'],
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))
})
},
})