/*jslint nomen: true */
var InsertionText = require('../../lib/util/insertion-text'),
it;
module.exports = {
"with a regular insertion text": {
setUp: function (cb) {
it = new InsertionText("hello world");
cb();
},
"should be able to span hello": function (test) {
it.insertAt(0, '');
it.insertAt(5, '');
test.equals(it.toString(), 'hello world');
test.done();
},
"should be able to span world": function (test) {
it.insertAt(6, '');
it.insertAt(11, '');
test.equals(it.toString(), 'hello world');
test.done();
},
"should be able to nest spans around hello (improperly)": function (test) {
it.insertAt(0, '');
it.insertAt(5, '');
it.insertAt(0, '
');
it.insertAt(5, '
');
test.equals(it.toString(), 'hello
world');
test.done();
},
"should be able to nest spans around hello (properly)": function (test) {
it.insertAt(0, '', true);
it.insertAt(5, '');
it.insertAt(0, '', true);
it.insertAt(5, '
');
test.equals(it.toString(), 'hello
world');
test.done();
},
"should be able to use syntactic sugar for wrapping text": function (test) {
it.wrap(0, '', 5, '');
it.wrap(0, '', 5, '
');
test.equals(it.toString(), 'hello
world');
test.done();
},
"should be able to chain calls for wrapping text": function (test) {
it.wrap(0, '', 5, '').
wrap(0, '', 5, '
');
test.equals(it.toString(), 'hello
world');
test.done();
},
"should be able to insert text between two insertions": function (test) {
it.wrap(0, '', 5, '').
insertAt(3, "w");
test.equals(it.toString(), 'helwlo world');
test.done();
},
"should prepend on negative insertion index": function (test) {
it.insertAt(-3, "XXX");
test.equals(it.toString(), 'XXXhello world');
test.done();
},
"should append on out-of-bounds insertion index": function (test) {
it.insertAt(100, "XXX");
test.equals(it.toString(), 'hello worldXXX');
test.done();
},
"should wrap entire line correctly": function (test) {
it.wrapLine('', '');
test.equals(it.toString(), 'hello world');
test.done();
},
"should be able to consume blanks in an individual call": function (test) {
it = new InsertionText(" hello world ");
it.wrap(2, '', 13, '', true);
test.equals(it.toString(), ' hello world ');
test.done();
}
},
"with a blank consuming insertion text and input with spaces on either end": {
setUp: function (cb) {
it = new InsertionText(" hello world ", true);
cb();
},
"spanning first word should consume leading spaces": function (test) {
it.wrap(4, '', 9, '');
test.equals(it.toString(), ' hello world ');
test.done();
},
"spanning second word should consume trailing spaces": function (test) {
it.wrap(10, '', 15, '');
test.equals(it.toString(), ' hello world ');
test.done();
},
"should be able to suppress blank consumption in an individual call": function (test) {
it = new InsertionText(" hello world ");
it.wrap(2, '', 13, '', false);
test.equals(it.toString(), ' hello world ');
test.done();
}
}
};