|
9 | 9 |
|
10 | 10 | import { expect } from 'chai';
|
11 | 11 | import { describe, it } from 'mocha';
|
12 |
| -import { dedentBlockStringValue, printBlockString } from '../blockString'; |
| 12 | +import { |
| 13 | + dedentBlockStringValue, |
| 14 | + getBlockStringIndentation, |
| 15 | + printBlockString, |
| 16 | +} from '../blockString'; |
13 | 17 |
|
14 | 18 | function joinLines(...args) {
|
15 | 19 | return args.join('\n');
|
@@ -99,6 +103,37 @@ describe('dedentBlockStringValue', () => {
|
99 | 103 | });
|
100 | 104 | });
|
101 | 105 |
|
| 106 | +describe('getBlockStringIndentation', () => { |
| 107 | + it('returns zero for an empty array', () => { |
| 108 | + expect(getBlockStringIndentation([])).to.equal(0); |
| 109 | + }); |
| 110 | + |
| 111 | + it('do not take first line into account', () => { |
| 112 | + expect(getBlockStringIndentation([' a'])).to.equal(0); |
| 113 | + expect(getBlockStringIndentation([' a', ' b'])).to.equal(2); |
| 114 | + }); |
| 115 | + |
| 116 | + it('returns minimal indentation length', () => { |
| 117 | + expect(getBlockStringIndentation(['', ' a', ' b'])).to.equal(1); |
| 118 | + expect(getBlockStringIndentation(['', ' a', ' b'])).to.equal(1); |
| 119 | + expect(getBlockStringIndentation(['', ' a', ' b', 'c'])).to.equal(0); |
| 120 | + }); |
| 121 | + |
| 122 | + it('count both tab and space as single character', () => { |
| 123 | + expect(getBlockStringIndentation(['', '\ta', ' b'])).to.equal(1); |
| 124 | + expect(getBlockStringIndentation(['', '\t a', ' b'])).to.equal(2); |
| 125 | + expect(getBlockStringIndentation(['', ' \t a', ' b'])).to.equal(3); |
| 126 | + }); |
| 127 | + |
| 128 | + it('do not take empty lines into account', () => { |
| 129 | + expect(getBlockStringIndentation(['a', '\t'])).to.equal(0); |
| 130 | + expect(getBlockStringIndentation(['a', ' '])).to.equal(0); |
| 131 | + expect(getBlockStringIndentation(['a', ' ', ' b'])).to.equal(2); |
| 132 | + expect(getBlockStringIndentation(['a', ' ', ' b'])).to.equal(2); |
| 133 | + expect(getBlockStringIndentation(['a', '', ' b'])).to.equal(1); |
| 134 | + }); |
| 135 | +}); |
| 136 | + |
102 | 137 | describe('printBlockString', () => {
|
103 | 138 | it('by default print block strings as single line', () => {
|
104 | 139 | const str = 'one liner';
|
|
0 commit comments