1+ import * as assert from 'assert' ;
2+ import { assertExt } from "../../../assertExtensions" ;
3+ import { ContentPadCalculator } from "../../../../src/padCalculation/contentPadCalculator" ;
4+ import { Table } from '../../../../src/models/table' ;
5+ import { Alignment } from '../../../../src/models/alignment' ;
6+ import { Cell } from '../../../../src/models/cell' ;
7+ import { PadCalculator } from '../../../../src/padCalculation/padCalculator' ;
8+ import { PadCalculatorSelector } from '../../../../src/padCalculation/padCalculatorSelector' ;
9+ import { FirstColumnPadCalculator } from '../../../../src/padCalculation/center/firstColumnPadCalculator' ;
10+
11+ suite ( "CenterAlign - FirstColumnPadCalculator tests" , ( ) => {
12+
13+ test ( "getLeftPadding() First column left by half the length" , ( ) => {
14+ const sut = createCalculator ( ) ;
15+ const table = tableFor ( [
16+ [ "aaaa" , "bbbbb" , "ccccc" ] ,
17+ [ "aa" , "bbbbb" , "ccccc" ]
18+ ] ) ;
19+
20+ assert . equal ( sut . getLeftPadding ( " " , table , 0 , 0 ) , "" ) ;
21+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
22+ } ) ;
23+
24+ test ( "getLeftPadding() First column left padded with 1 extra character if there is a left border" , ( ) => {
25+ const sut = createCalculator ( ) ;
26+ const table = tableFor ( [
27+ [ "aaaa" , "bbbbb" , "ccccc" ] ,
28+ [ "aa" , "bbbbb" , "ccccc" ]
29+ ] ) ;
30+ table . hasLeftBorder = true ;
31+
32+ assert . equal ( sut . getLeftPadding ( " " , table , 0 , 0 ) , " " ) ;
33+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
34+ } ) ;
35+
36+ test ( "getRightPadding() First column equal to maxColLength gets padded with one character" , ( ) => {
37+ const sut = createCalculator ( ) ;
38+ const table = tableFor ( [
39+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
40+ [ "aaaaa" , "bbbbb" , "ccccc" ]
41+ ] ) ;
42+
43+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
44+ } ) ;
45+
46+ test ( "getLeftPadding() First column equal to maxColLength gets padded with one character" , ( ) => {
47+ const sut = createCalculator ( ) ;
48+ const table = tableFor ( [
49+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
50+ [ "aaaaa" , "bbbbb" , "ccccc" ]
51+ ] ) ;
52+
53+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
54+ } ) ;
55+
56+ test ( "getRightPadding() First column 1 char shorter than maxColLength gets padded with one character" , ( ) => {
57+ const sut = createCalculator ( ) ;
58+ const table = tableFor ( [
59+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
60+ [ "aaaa" , "bbbbb" , "ccccc" ]
61+ ] ) ;
62+
63+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
64+ } ) ;
65+
66+ test ( "getLeftPadding() First column 1 char shorter than maxColLength gets padded with one character" , ( ) => {
67+ const sut = createCalculator ( ) ;
68+ const table = tableFor ( [
69+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
70+ [ "aaaa" , "bbbbb" , "ccccc" ]
71+ ] ) ;
72+
73+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
74+ } ) ;
75+
76+ test ( "getRightPadding() First column 2 char shorter than maxColLength gets padded with 2 characters" , ( ) => {
77+ const sut = createCalculator ( ) ;
78+ const table = tableFor ( [
79+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
80+ [ "aaa" , "bbbbb" , "ccccc" ]
81+ ] ) ;
82+
83+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
84+ } ) ;
85+
86+ test ( "getLeftPadding() First column 2 char shorter than maxColLength gets padded with 2 characters" , ( ) => {
87+ const sut = createCalculator ( ) ;
88+ const table = tableFor ( [
89+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
90+ [ "aaa" , "bbbbb" , "ccccc" ]
91+ ] ) ;
92+
93+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
94+ } ) ;
95+
96+ test ( "getRightPadding() First column 3 char shorter than maxColLength gets padded with 2 characters" , ( ) => {
97+ const sut = createCalculator ( ) ;
98+ const table = tableFor ( [
99+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
100+ [ "aa" , "bbbbb" , "ccccc" ]
101+ ] ) ;
102+
103+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
104+ } ) ;
105+
106+ test ( "getLeftPadding() First column 3 char shorter than maxColLength gets padded with 2 characters" , ( ) => {
107+ const sut = createCalculator ( ) ;
108+ const table = tableFor ( [
109+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
110+ [ "aa" , "bbbbb" , "ccccc" ]
111+ ] ) ;
112+
113+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
114+ } ) ;
115+
116+ test ( "getRightPadding() First column 4 char shorter than maxColLength gets padded with 3 characters" , ( ) => {
117+ const sut = createCalculator ( ) ;
118+ const table = tableFor ( [
119+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
120+ [ "a" , "bbbbb" , "ccccc" ]
121+ ] ) ;
122+
123+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
124+ } ) ;
125+
126+ test ( "getLeftPadding() First column 4 char shorter than maxColLength gets padded with 3 characters" , ( ) => {
127+ const sut = createCalculator ( ) ;
128+ const table = tableFor ( [
129+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
130+ [ "a" , "bbbbb" , "ccccc" ]
131+ ] ) ;
132+
133+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
134+ } ) ;
135+
136+ test ( "getRightPadding() First column is empty string gets padded with 3 characters" , ( ) => {
137+ const sut = createCalculator ( ) ;
138+ const table = tableFor ( [
139+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
140+ [ "" , "bbbbb" , "ccccc" ]
141+ ] ) ;
142+
143+ assert . equal ( sut . getRightPadding ( " " , table , 1 , 0 ) , " " ) ;
144+ } ) ;
145+
146+ test ( "getLeftPadding() First column is empty string gets padded with 3 characters" , ( ) => {
147+ const sut = createCalculator ( ) ;
148+ const table = tableFor ( [
149+ [ "aaaaa" , "bbbbb" , "ccccc" ] ,
150+ [ "" , "bbbbb" , "ccccc" ]
151+ ] ) ;
152+
153+ assert . equal ( sut . getLeftPadding ( " " , table , 1 , 0 ) , " " ) ;
154+ } ) ;
155+
156+ function createCalculator ( ) : FirstColumnPadCalculator {
157+ return new FirstColumnPadCalculator ( ) ;
158+ }
159+
160+ function tableFor ( rows : string [ ] [ ] ) {
161+ const alignments : Alignment [ ] = rows [ 0 ] . map ( r => Alignment . Center ) ;
162+ let table = new Table ( rows . map ( row => row . map ( c => new Cell ( c ) ) ) , alignments ) ;
163+ return table ;
164+ }
165+ } ) ;
0 commit comments