bugfix...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-09-15 20:22:14 +03:00
parent dce24493ff
commit d6d8492cd6
3 changed files with 27 additions and 19 deletions

View File

@ -92,7 +92,8 @@ function(text, tab_size, leading_tabs){
: text : text
// trim the tail and remove leading blank lines... // trim the tail and remove leading blank lines...
var lines = text.trimEnd().split(/\n/) var lines = text.trimEnd().split(/\n/)
while(lines[0].trim() == ''){ while(lines.length > 0
&& lines[0].trim() == ''){
// XXX we have two options here: // XXX we have two options here:
// - indent everyline including the first non-blank // - indent everyline including the first non-blank
// - do not indent anything (current) // - do not indent anything (current)

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-object", "name": "ig-object",
"version": "5.2.7", "version": "5.2.8",
"description": "", "description": "",
"main": "object.js", "main": "object.js",
"scripts": { "scripts": {

41
test.js
View File

@ -673,6 +673,8 @@ var cases = test.Cases({
// XXX still need to test tab_size values (0, ...) // XXX still need to test tab_size values (0, ...)
text_cases: [ text_cases: [
// sanity checks... // sanity checks...
{ input: '',
all: ''},
{ input: 'abc', { input: 'abc',
all: 'abc'}, all: 'abc'},
{ input: '\n\t\tabc', { input: '\n\t\tabc',
@ -758,28 +760,33 @@ var cases = test.Cases({
text: function(assert){ text: function(assert){
this.text_cases this.text_cases
.map(function({input, doc, text, all}, i){ .map(function({input, doc, text, all}, i){
var res doc = doc != null ?
doc
: all
text = text != null ?
text
: all
;(doc || all) var test = function(func, input, expect){
&& assert((res = object.doc([input])) == (doc || all), var res
'doc(text_cases['+i+']):' return assert((res = object[func](input)) == expect,
func +'(text_cases['+i+']):'
+'\n---input---\n' +'\n---input---\n'
+ input + (input instanceof Array ?
input[0]
: input)
+'\n---Expected---\n' +'\n---Expected---\n'
+ (doc || all) + expect
+'\n---Got---\n' +'\n---Got---\n'
+ res + res
+'\n---') +'\n---') }
;(text || all)
&& assert((res = object.text([input])) == (text || all), doc != null
'text(text_cases['+i+']):' && test('normalizeIndent', input, doc)
+'\n---input---\n' && test('doc', [input], doc)
+ input text != null
+'\n---Expected---\n' && test('normalizeTextIndent', input, text)
+ (text || all) && test('text', [input], text) }) },
+'\n---Got---\n'
+ res
+'\n---') }) },
}) })