diff --git a/object.js b/object.js index 67709f2..66731d7 100755 --- a/object.js +++ b/object.js @@ -92,7 +92,8 @@ function(text, tab_size, leading_tabs){ : text // trim the tail and remove leading blank lines... var lines = text.trimEnd().split(/\n/) - while(lines[0].trim() == ''){ + while(lines.length > 0 + && lines[0].trim() == ''){ // XXX we have two options here: // - indent everyline including the first non-blank // - do not indent anything (current) diff --git a/package.json b/package.json index 4897d65..d4fd046 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "5.2.7", + "version": "5.2.8", "description": "", "main": "object.js", "scripts": { diff --git a/test.js b/test.js index 8804387..7c278ce 100755 --- a/test.js +++ b/test.js @@ -673,6 +673,8 @@ var cases = test.Cases({ // XXX still need to test tab_size values (0, ...) text_cases: [ // sanity checks... + { input: '', + all: ''}, { input: 'abc', all: 'abc'}, { input: '\n\t\tabc', @@ -758,28 +760,33 @@ var cases = test.Cases({ text: function(assert){ this.text_cases .map(function({input, doc, text, all}, i){ - var res + doc = doc != null ? + doc + : all + text = text != null ? + text + : all - ;(doc || all) - && assert((res = object.doc([input])) == (doc || all), - 'doc(text_cases['+i+']):' + var test = function(func, input, expect){ + var res + return assert((res = object[func](input)) == expect, + func +'(text_cases['+i+']):' +'\n---input---\n' - + input + + (input instanceof Array ? + input[0] + : input) +'\n---Expected---\n' - + (doc || all) + + expect +'\n---Got---\n' + res - +'\n---') - ;(text || all) - && assert((res = object.text([input])) == (text || all), - 'text(text_cases['+i+']):' - +'\n---input---\n' - + input - +'\n---Expected---\n' - + (text || all) - +'\n---Got---\n' - + res - +'\n---') }) }, + +'\n---') } + + doc != null + && test('normalizeIndent', input, doc) + && test('doc', [input], doc) + text != null + && test('normalizeTextIndent', input, text) + && test('text', [input], text) }) }, })