Skip to content

Commit 2be5cb8

Browse files
committed
Pass the alignment marker via the ctors
1 parent 29c4bf9 commit 2be5cb8

11 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/extension/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function activate(context: vscode.ExtensionContext): void {
3434
new RowViewModelFactory(
3535
new ContentPadCalculator(new PadCalculatorSelector(), " "),
3636
new SeparatorPadCalculator(new PadCalculatorSelector(), "-"),
37-
new AlignmentMarkerStrategy()
37+
new AlignmentMarkerStrategy(":")
3838
)
3939
),
4040
new TableStringWriter(),

src/viewModelFactories/alignmentMarking/alignmentMarkerStrategy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { IAlignmentMarker, LeftAlignmentMarker, RightAlignmentMarker, CenterAlig
33

44

55
export class AlignmentMarkerStrategy {
6+
constructor(private _markerChar: string) { }
67

78
public markerFor(alignment: Alignment): IAlignmentMarker {
89
switch (alignment) {
9-
case Alignment.Left: return new LeftAlignmentMarker();
10-
case Alignment.Right: return new RightAlignmentMarker();
11-
case Alignment.Center: return new CenterAlignmentMarker();
10+
case Alignment.Left: return new LeftAlignmentMarker(this._markerChar);
11+
case Alignment.Right: return new RightAlignmentMarker(this._markerChar);
12+
case Alignment.Center: return new CenterAlignmentMarker(this._markerChar);
1213
default: return new NotSetAlignmentMarker();
1314
}
1415
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { IAlignmentMarker } from ".";
22

33
export class CenterAlignmentMarker implements IAlignmentMarker {
4+
constructor(private _markerChar: string) { }
5+
46
public mark(padding: string): string {
57
if (padding == null || padding.length < 2)
68
return padding;
79

8-
return ":" + padding.substring(1, padding.length - 1) + ":";
10+
return this._markerChar + padding.substring(1, padding.length - 1) + this._markerChar;
911
}
1012
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { IAlignmentMarker } from ".";
22

33
export class LeftAlignmentMarker implements IAlignmentMarker {
4-
constructor() {
5-
}
4+
constructor(private _markerChar: string) { }
5+
66
public mark(padding: string): string {
77
if (padding == null || padding.length < 2)
88
return padding;
9-
return ":" + padding.substr(1);
9+
return this._markerChar + padding.substr(1);
1010
}
1111
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { IAlignmentMarker } from ".";
22

33
export class RightAlignmentMarker implements IAlignmentMarker {
4+
constructor(private _markerChar: string) { }
5+
46
public mark(padding: string): string {
57
if (padding == null || padding.length < 2)
68
return padding;
7-
return padding.substring(0, padding.length - 1) + ":";
9+
return padding.substring(0, padding.length - 1) + this._markerChar;
810
}
911
}

test/systemTests/tableRangePrettyfierFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class PrettyfierFromFile {
6464
new TableViewModelFactory(new RowViewModelFactory(
6565
new ContentPadCalculator(new PadCalculatorSelector(), " "),
6666
new SeparatorPadCalculator(new PadCalculatorSelector(), "-"),
67-
new AlignmentMarkerStrategy()
67+
new AlignmentMarkerStrategy(":")
6868
)),
6969
new TableStringWriter(),
7070
[ this._logger ]

test/unitTests/viewModelFactories/alignmentMarking/alignmentMarkerStrategy.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { Alignment } from '../../../../src/models/alignment';
55
suite("AlignmentMarkerStrategy tests", () => {
66

77
test("markerFor() returns a different marker strategy for the different alignemnts", () => {
8-
const sut = new AlignmentMarkerStrategy();
8+
const sut = new AlignmentMarkerStrategy(":");
99
const alignments = [ Alignment.NotSet, Alignment.Left, Alignment.Center, Alignment.Right ];
1010

11-
const markers: IAlignmentMarker[] = alignments.map(sut.markerFor);
11+
const markers: IAlignmentMarker[] = alignments.map(sut.markerFor, sut);
1212

1313
const distinctMarkers = markers.filter((v, i, a) => a.indexOf(v) == i);
1414

test/unitTests/viewModelFactories/alignmentMarking/centerAlignmentMarker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ suite("CenterAlignmentMarker tests", () => {
4343
});
4444

4545
function createSut() {
46-
return new CenterAlignmentMarker();
46+
return new CenterAlignmentMarker(":");
4747
}
4848
});

test/unitTests/viewModelFactories/alignmentMarking/leftAlignmentMarker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ suite("LeftAlignmentMarker tests", () => {
4141
});
4242

4343
function createSut() {
44-
return new LeftAlignmentMarker();
44+
return new LeftAlignmentMarker(":");
4545
}
4646
});

test/unitTests/viewModelFactories/alignmentMarking/rightAlignmentMarker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ suite("RightAlignmentMarker tests", () => {
4141
});
4242

4343
function createSut() {
44-
return new RightAlignmentMarker();
44+
return new RightAlignmentMarker(":");
4545
}
4646
});

0 commit comments

Comments
 (0)