| 1 |
/*jslint nomen: true */ |
| 2 |
var InsertionText = require('../../lib/util/insertion-text'), |
| 3 |
it; |
| 4 |
|
| 5 |
module.exports = { |
| 6 |
"with a regular insertion text": { |
| 7 |
setUp: function (cb) { |
| 8 |
it = new InsertionText("hello world"); |
| 9 |
cb(); |
| 10 |
}, |
| 11 |
"should be able to span hello": function (test) { |
| 12 |
it.insertAt(0, '<span class="h">'); |
| 13 |
it.insertAt(5, '</span>'); |
| 14 |
test.equals(it.toString(), '<span class="h">hello</span> world'); |
| 15 |
test.done(); |
| 16 |
}, |
| 17 |
"should be able to span world": function (test) { |
| 18 |
it.insertAt(6, '<span class="w">'); |
| 19 |
it.insertAt(11, '</span>'); |
| 20 |
test.equals(it.toString(), 'hello <span class="w">world</span>'); |
| 21 |
test.done(); |
| 22 |
}, |
| 23 |
"should be able to nest spans around hello (improperly)": function (test) { |
| 24 |
it.insertAt(0, '<span class="h">'); |
| 25 |
it.insertAt(5, '</span>'); |
| 26 |
it.insertAt(0, '<div class="w">'); |
| 27 |
it.insertAt(5, '</div>'); |
| 28 |
test.equals(it.toString(), '<span class="h"><div class="w">hello</span></div> world'); |
| 29 |
test.done(); |
| 30 |
}, |
| 31 |
"should be able to nest spans around hello (properly)": function (test) { |
| 32 |
it.insertAt(0, '<span class="w">', true); |
| 33 |
it.insertAt(5, '</span>'); |
| 34 |
it.insertAt(0, '<div class="h">', true); |
| 35 |
it.insertAt(5, '</div>'); |
| 36 |
test.equals(it.toString(), '<div class="h"><span class="w">hello</span></div> world'); |
| 37 |
test.done(); |
| 38 |
}, |
| 39 |
"should be able to use syntactic sugar for wrapping text": function (test) { |
| 40 |
it.wrap(0, '<span class="h">', 5, '</span>'); |
| 41 |
it.wrap(0, '<div class="w">', 5, '</div>'); |
| 42 |
test.equals(it.toString(), '<div class="w"><span class="h">hello</span></div> world'); |
| 43 |
test.done(); |
| 44 |
}, |
| 45 |
"should be able to chain calls for wrapping text": function (test) { |
| 46 |
it.wrap(0, '<span class="h">', 5, '</span>'). |
| 47 |
wrap(0, '<div class="w">', 5, '</div>'); |
| 48 |
test.equals(it.toString(), '<div class="w"><span class="h">hello</span></div> world'); |
| 49 |
test.done(); |
| 50 |
}, |
| 51 |
"should be able to insert text between two insertions": function (test) { |
| 52 |
it.wrap(0, '<span class="h">', 5, '</span>'). |
| 53 |
insertAt(3, "w"); |
| 54 |
test.equals(it.toString(), '<span class="h">helwlo</span> world'); |
| 55 |
test.done(); |
| 56 |
}, |
| 57 |
"should prepend on negative insertion index": function (test) { |
| 58 |
it.insertAt(-3, "XXX"); |
| 59 |
test.equals(it.toString(), 'XXXhello world'); |
| 60 |
test.done(); |
| 61 |
}, |
| 62 |
"should append on out-of-bounds insertion index": function (test) { |
| 63 |
it.insertAt(100, "XXX"); |
| 64 |
test.equals(it.toString(), 'hello worldXXX'); |
| 65 |
test.done(); |
| 66 |
}, |
| 67 |
"should wrap entire line correctly": function (test) { |
| 68 |
it.wrapLine('<span>', '</span>'); |
| 69 |
test.equals(it.toString(), '<span>hello world</span>'); |
| 70 |
test.done(); |
| 71 |
}, |
| 72 |
"should be able to consume blanks in an individual call": function (test) { |
| 73 |
it = new InsertionText(" hello world "); |
| 74 |
it.wrap(2, '<span>', 13, '</span>', true); |
| 75 |
test.equals(it.toString(), '<span> hello world </span>'); |
| 76 |
test.done(); |
| 77 |
} |
| 78 |
}, |
| 79 |
"with a blank consuming insertion text and input with spaces on either end": { |
| 80 |
setUp: function (cb) { |
| 81 |
it = new InsertionText(" hello world ", true); |
| 82 |
cb(); |
| 83 |
}, |
| 84 |
"spanning first word should consume leading spaces": function (test) { |
| 85 |
it.wrap(4, '<span class="h">', 9, '</span>'); |
| 86 |
test.equals(it.toString(), '<span class="h"> hello</span> world '); |
| 87 |
test.done(); |
| 88 |
}, |
| 89 |
"spanning second word should consume trailing spaces": function (test) { |
| 90 |
it.wrap(10, '<span class="h">', 15, '</span>'); |
| 91 |
test.equals(it.toString(), ' hello <span class="h">world </span>'); |
| 92 |
test.done(); |
| 93 |
}, |
| 94 |
"should be able to suppress blank consumption in an individual call": function (test) { |
| 95 |
it = new InsertionText(" hello world "); |
| 96 |
it.wrap(2, '<span>', 13, '</span>', false); |
| 97 |
test.equals(it.toString(), ' <span>hello world</span> '); |
| 98 |
test.done(); |
| 99 |
} |
| 100 |
} |
| 101 |
}; |
| 102 |
|