Skip to content

Commit 7280469

Browse files
committed
Pass the pad chars to the constructors
1 parent eb395be commit 7280469

10 files changed

Lines changed: 143 additions & 93 deletions

File tree

src/extension/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export function activate(context: vscode.ExtensionContext): void {
3131
new TableValidator(new SelectionInterpreter()),
3232
new TableViewModelFactory(
3333
new RowViewModelFactory(
34-
new ContentPadCalculator(new ColumnBasedPadCalculatorSelector()),
35-
new SeparatorPadCalculator(new ColumnBasedPadCalculatorSelector())
34+
new ContentPadCalculator(new ColumnBasedPadCalculatorSelector(), " "),
35+
new SeparatorPadCalculator(new ColumnBasedPadCalculatorSelector(), "-")
3636
)
3737
),
3838
new TableStringWriter(),

src/padCalculation/contentPadCalculator.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { ColumnBasedPadCalculatorSelector } from "./columnBasedPadCalculatorSele
44

55
export class ContentPadCalculator implements PadCalculator {
66

7-
constructor(private _padCalculatorSelector: ColumnBasedPadCalculatorSelector) { }
7+
constructor(
8+
protected _padCalculatorSelector: ColumnBasedPadCalculatorSelector,
9+
protected _paddingChar: string)
10+
{ }
811

9-
public getLeftPadding(paddingChar: string, table: Table, row: number, column: number): string {
10-
return this._padCalculatorSelector.select(table, column).getLeftPadding(paddingChar, table, table.rows[row][column]);
12+
public getLeftPadding(table: Table, row: number, column: number): string {
13+
return this._padCalculatorSelector.select(table, column).getLeftPadding(this._paddingChar, table, table.rows[row][column]);
1114
}
1215

13-
public getRightPadding(paddingChar: string, table: Table, row: number, column: number): string {
14-
return this._padCalculatorSelector.select(table, column).getRightPadding(paddingChar, table, row, column);
16+
public getRightPadding(table: Table, row: number, column: number): string {
17+
return this._padCalculatorSelector.select(table, column).getRightPadding(this._paddingChar, table, row, column);
18+
}
19+
20+
public getPadChar(): string{
21+
return this._paddingChar;
1522
}
1623
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Table } from "../models/table";
22

33
export interface PadCalculator {
4-
getLeftPadding(paddingChar: string, table: Table, row: number, column: number): string;
5-
getRightPadding(paddingChar: string, table: Table, row: number, column: number): string;
4+
getLeftPadding(table: Table, row: number, column: number): string;
5+
getRightPadding(table: Table, row: number, column: number): string;
6+
getPadChar(): string;
67
}

src/padCalculation/separatorPadCalculator.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { PadCalculator } from "./padCalculator";
22
import { ContentPadCalculator } from "./contentPadCalculator";
33
import { Table } from "../models/table";
4+
import { ColumnBasedPadCalculatorSelector } from "./columnBasedPadCalculatorSelector";
45

56
export class SeparatorPadCalculator extends ContentPadCalculator implements PadCalculator {
6-
public getRightPadding(paddingChar: string, table: Table, row: number, column: number): string {
7-
return paddingChar.repeat(this.getRightPadCountForSeparator(table, column));
7+
8+
constructor(
9+
padCalculatorSelector: ColumnBasedPadCalculatorSelector,
10+
paddingChar: string)
11+
{
12+
super(padCalculatorSelector, paddingChar);
13+
}
14+
15+
public getRightPadding(table: Table, row: number, column: number): string {
16+
return this._paddingChar.repeat(this.getRightPadCountForSeparator(table, column));
817
}
918

1019
private getRightPadCountForSeparator(table: Table, column: number): number {

src/viewModelFactories/rowViewModelFactory.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class RowViewModelFactory {
1212
if (table == null) throw new Error("Paramter can't be null");
1313

1414
let resultRow = new Array(table.columnCount);
15-
const padChar = " ";
1615

1716
for(let col = 0; col < table.columnCount; col++) {
1817
let text = "";
@@ -21,34 +20,32 @@ export class RowViewModelFactory {
2120
if (!table.hasRightBorder)
2221
text = "";
2322
else
24-
text = padChar;
23+
text = this._contentPadCalculator.getPadChar();
2524
}
2625
else {
2726
text = table.rows[row][col].getValue();
2827
}
2928
}
3029
else {
3130
text = table.rows[row][col].getValue() == ""
32-
? padChar
31+
? this._contentPadCalculator.getPadChar()
3332
: table.rows[row][col].getValue();
3433
}
3534

3635
resultRow[col] =
37-
this._contentPadCalculator.getLeftPadding(padChar, table, row, col) +
36+
this._contentPadCalculator.getLeftPadding(table, row, col) +
3837
text +
39-
this._contentPadCalculator.getRightPadding(padChar, table, row, col);
38+
this._contentPadCalculator.getRightPadding(table, row, col);
4039
}
4140
return new RowViewModel(resultRow);
4241
}
4342

4443
public buildSeparator(table: Table): RowViewModel {
4544
let resultRow = new Array(table.columnCount);
46-
const padChar = "-";
47-
4845
for(let col = 0; col < table.columnCount; col++) {
4946
resultRow[col] =
50-
this._separatorPadCalculator.getLeftPadding(padChar, table, 1, col) +
51-
this._separatorPadCalculator.getRightPadding(padChar, table, 0, col);
47+
this._separatorPadCalculator.getLeftPadding( table, 1, col) +
48+
this._separatorPadCalculator.getRightPadding( table, 0, col);
5249
}
5350
return new RowViewModel(resultRow);
5451
}

test/systemTests/tableRangePrettyfierFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export class PrettyfierFromFile {
6161
),
6262
new TableValidator(new SelectionInterpreter()),
6363
new TableViewModelFactory(new RowViewModelFactory(
64-
new ContentPadCalculator(new ColumnBasedPadCalculatorSelector()),
65-
new SeparatorPadCalculator(new ColumnBasedPadCalculatorSelector())
64+
new ContentPadCalculator(new ColumnBasedPadCalculatorSelector(), " "),
65+
new SeparatorPadCalculator(new ColumnBasedPadCalculatorSelector(), "-")
6666
)),
6767
new TableStringWriter(),
6868
[ this._logger ]

test/unitTests/padCalculation/contentPadCalculator.test.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ suite("ContentPadCalculator tests", () => {
1616
[ "aaaaa", "bbbbb", "ccccc" ]
1717
]);
1818

19-
const pad = sut.getLeftPadding(" ", table, 1, 0);
19+
const pad = sut.getLeftPadding(table, 1, 0);
2020

2121
assert.equal(pad, "");
2222
});
@@ -28,7 +28,7 @@ suite("ContentPadCalculator tests", () => {
2828
[ "aaaaa", "bbbbb", "ccccc" ]
2929
]);
3030
table.hasLeftBorder = true;
31-
const pad = sut.getLeftPadding(" ", table, 1, 1);
31+
const pad = sut.getLeftPadding(table, 1, 1);
3232

3333
assert.equal(pad, " ");
3434
});
@@ -40,7 +40,7 @@ suite("ContentPadCalculator tests", () => {
4040
[ "aaaaa", "bbbbb", "ccccc" ]
4141
]);
4242

43-
const pad = sut.getLeftPadding(" ", table, 1, 1);
43+
const pad = sut.getLeftPadding(table, 1, 1);
4444

4545
assert.equal(pad, " ");
4646
});
@@ -52,7 +52,7 @@ suite("ContentPadCalculator tests", () => {
5252
[ "a", "", "c" ]
5353
]);
5454

55-
const pad = sut.getLeftPadding(" ", table, 1, 1);
55+
const pad = sut.getLeftPadding(table, 1, 1);
5656

5757
assert.equal(pad, " ");
5858
});
@@ -64,9 +64,9 @@ suite("ContentPadCalculator tests", () => {
6464
[ "aaaaa", "bbbbb", "ccccc" ]
6565
]);
6666

67-
const pad = sut.getLeftPadding("X", table, 1, 2);
67+
const pad = sut.getLeftPadding(table, 1, 2);
6868

69-
assert.equal(pad, "X");
69+
assert.equal(pad, " ");
7070
});
7171

7272
test("getRightPadding() First column equal to maxColLength gets right padded with one character", () => {
@@ -76,7 +76,7 @@ suite("ContentPadCalculator tests", () => {
7676
[ "aaaaa", "bbbbb", "ccccc" ]
7777
]);
7878

79-
const pad = sut.getRightPadding(" ", table, 1, 0);
79+
const pad = sut.getRightPadding(table, 1, 0);
8080

8181
assert.equal(pad, " ");
8282
});
@@ -88,7 +88,7 @@ suite("ContentPadCalculator tests", () => {
8888
[ "aaaa", "bbbbb", "ccccc" ]
8989
]);
9090

91-
const pad = sut.getRightPadding(" ", table, 1, 0);
91+
const pad = sut.getRightPadding(table, 1, 0);
9292

9393
assert.equal(pad, " ");
9494
});
@@ -100,7 +100,7 @@ suite("ContentPadCalculator tests", () => {
100100
[ "aaa", "bbbbb", "ccccc" ]
101101
]);
102102

103-
const pad = sut.getRightPadding(" ", table, 1, 0);
103+
const pad = sut.getRightPadding(table, 1, 0);
104104

105105
assert.equal(pad, " ");
106106
});
@@ -112,7 +112,7 @@ suite("ContentPadCalculator tests", () => {
112112
[ "aa", "bbbbb", "ccccc" ]
113113
]);
114114

115-
const pad = sut.getRightPadding(" ", table, 1, 0);
115+
const pad = sut.getRightPadding(table, 1, 0);
116116

117117
assert.equal(pad, " ");
118118
});
@@ -124,7 +124,7 @@ suite("ContentPadCalculator tests", () => {
124124
[ "a", "bbbbb", "ccccc" ]
125125
]);
126126

127-
const pad = sut.getRightPadding(" ", table, 1, 0);
127+
const pad = sut.getRightPadding(table, 1, 0);
128128

129129
assert.equal(pad, " ");
130130
});
@@ -136,7 +136,7 @@ suite("ContentPadCalculator tests", () => {
136136
[ "", "bbbbb", "ccccc" ]
137137
]);
138138

139-
const pad = sut.getRightPadding(" ", table, 1, 0);
139+
const pad = sut.getRightPadding(table, 1, 0);
140140

141141
assert.equal(pad, " ");
142142
});
@@ -148,7 +148,7 @@ suite("ContentPadCalculator tests", () => {
148148
[ "aaaaa", "", "ccccc" ]
149149
]);
150150

151-
const pad = sut.getRightPadding(" ", table, 1, 1);
151+
const pad = sut.getRightPadding(table, 1, 1);
152152

153153
assert.equal(pad, " ");
154154
});
@@ -160,7 +160,7 @@ suite("ContentPadCalculator tests", () => {
160160
[ "aaaaa", "bbbbb", "ccccc" ]
161161
]);
162162

163-
const pad = sut.getRightPadding(" ", table, 1, 1);
163+
const pad = sut.getRightPadding(table, 1, 1);
164164

165165
assert.equal(pad, " ");
166166
});
@@ -172,7 +172,7 @@ suite("ContentPadCalculator tests", () => {
172172
[ "aaaaa", "bbbb", "ccccc" ]
173173
]);
174174

175-
const pad = sut.getRightPadding(" ", table, 1, 1);
175+
const pad = sut.getRightPadding(table, 1, 1);
176176

177177
assert.equal(pad, " ");
178178
});
@@ -184,7 +184,7 @@ suite("ContentPadCalculator tests", () => {
184184
[ "aaaaa", "bbb", "ccccc" ]
185185
]);
186186

187-
const pad = sut.getRightPadding(" ", table, 1, 1);
187+
const pad = sut.getRightPadding(table, 1, 1);
188188

189189
assert.equal(pad, " ");
190190
});
@@ -196,7 +196,7 @@ suite("ContentPadCalculator tests", () => {
196196
[ "aaaaa", "bb", "ccccc" ]
197197
]);
198198

199-
const pad = sut.getRightPadding(" ", table, 1, 1);
199+
const pad = sut.getRightPadding(table, 1, 1);
200200

201201
assert.equal(pad, " ");
202202
});
@@ -208,7 +208,7 @@ suite("ContentPadCalculator tests", () => {
208208
[ "aaaaa", "", "ccccc" ]
209209
]);
210210

211-
const pad = sut.getRightPadding(" ", table, 1, 1);
211+
const pad = sut.getRightPadding(table, 1, 1);
212212

213213
assert.equal(pad, " ");
214214
});
@@ -220,7 +220,7 @@ suite("ContentPadCalculator tests", () => {
220220
[ "aaaaa", "", "ccccc" ]
221221
]);
222222

223-
const pad = sut.getRightPadding(" ", table, 1, 1);
223+
const pad = sut.getRightPadding(table, 1, 1);
224224

225225
assert.equal(pad, " ");
226226
});
@@ -232,7 +232,7 @@ suite("ContentPadCalculator tests", () => {
232232
[ "aaaaa", "bbbbb", "c" ]
233233
]);
234234

235-
const pad = sut.getRightPadding(" ", table, 1, 2);
235+
const pad = sut.getRightPadding(table, 1, 2);
236236

237237
assert.equal(pad, "");
238238
});
@@ -248,7 +248,7 @@ suite("ContentPadCalculator tests", () => {
248248
]);
249249
table.hasRightBorder = true;
250250

251-
const pad = sut.getRightPadding(" ", table, 1, 2);
251+
const pad = sut.getRightPadding(table, 1, 2);
252252

253253
assert.equal(pad, " ");
254254
});
@@ -261,7 +261,7 @@ suite("ContentPadCalculator tests", () => {
261261
]);
262262
table.hasRightBorder = true;
263263

264-
const pad = sut.getRightPadding(" ", table, 1, 2);
264+
const pad = sut.getRightPadding(table, 1, 2);
265265

266266
assert.equal(pad, " ");
267267
});
@@ -274,7 +274,7 @@ suite("ContentPadCalculator tests", () => {
274274
]);
275275
table.hasRightBorder = true;
276276

277-
const pad = sut.getRightPadding(" ", table, 1, 2);
277+
const pad = sut.getRightPadding(table, 1, 2);
278278

279279
assert.equal(pad, " ");
280280
});
@@ -287,7 +287,7 @@ suite("ContentPadCalculator tests", () => {
287287
]);
288288
table.hasRightBorder = true;
289289

290-
const pad = sut.getRightPadding(" ", table, 1, 2);
290+
const pad = sut.getRightPadding(table, 1, 2);
291291

292292
assert.equal(pad, " ");
293293
});
@@ -300,7 +300,7 @@ suite("ContentPadCalculator tests", () => {
300300
]);
301301
table.hasRightBorder = true;
302302

303-
const pad = sut.getRightPadding(" ", table, 1, 2);
303+
const pad = sut.getRightPadding(table, 1, 2);
304304

305305
assert.equal(pad, " ");
306306
});
@@ -313,7 +313,7 @@ suite("ContentPadCalculator tests", () => {
313313
]);
314314
table.hasRightBorder = true;
315315

316-
const pad = sut.getRightPadding(" ", table, 1, 2);
316+
const pad = sut.getRightPadding(table, 1, 2);
317317

318318
assert.equal(pad, " ");
319319
});
@@ -325,8 +325,8 @@ suite("ContentPadCalculator tests", () => {
325325
[ "aaaaa", "b", "ccccc" ]
326326
]);
327327

328-
const leftPad = sut.getLeftPadding(" ", table, 1, 1);
329-
const rightPad = sut.getRightPadding(" ", table, 1, 1);
328+
const leftPad = sut.getLeftPadding(table, 1, 1);
329+
const rightPad = sut.getRightPadding(table, 1, 1);
330330

331331
assert.equal(leftPad, " ");
332332
assert.equal(rightPad, " ");
@@ -339,6 +339,6 @@ suite("ContentPadCalculator tests", () => {
339339
}
340340

341341
function createCalculator(): PadCalculator {
342-
return new ContentPadCalculator(new ColumnBasedPadCalculatorSelector());
342+
return new ContentPadCalculator(new ColumnBasedPadCalculatorSelector(), " ");
343343
}
344344
});

0 commit comments

Comments
 (0)