Skip to content

Commit ad4149b

Browse files
author
Sven Ulrich
committed
tests for stringbuilder, updated changelog
1 parent 497681d commit ad4149b

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#### 1.4.0
44
- added `AppendLine` and `AppendLineFormat`
55
- added hexadecimal conversion specifier
6-
- bugfix `StringBuilder` initialization without parameter adds empty string.
6+
- bugfix `StringBuilder` initialization without parameter adds empty string to internal Values Array.

dist/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,14 @@ export class String {
259259
}
260260

261261
export class StringBuilder {
262-
public Values: string[] = [];
262+
public Values: string[];
263263

264-
constructor(value: string = String.Empty) {
265-
this.Values = new Array(value);
264+
constructor(value?: string) {
265+
this.Values = [];
266+
267+
if (!String.IsNullOrWhiteSpace(value)) {
268+
this.Values = new Array(value);
269+
}
266270
}
267271

268272
public ToString() {

tests/tests.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,27 @@ describe('String.Join', () => {
269269
});
270270
});
271271

272-
describe('String.Append', () => {
272+
describe('StringBuilder initialization', () => {
273+
it('should not add empty string if there is no ctor parameter', () => {
274+
var builder = new StringBuilder();
275+
builder.Append('First Part... ');
276+
builder.Append('Second Part...');
277+
278+
expect(builder.ToString()).to
279+
.equal('First Part... Second Part...');
280+
});
281+
282+
it('should add a string if there is ctor parameter', () => {
283+
var builder = new StringBuilder(String.Format("First {0}... ", "Part"));
284+
builder.AppendFormat('Second {0}...', 'Part');
285+
286+
console.log(builder.ToString());
287+
expect(builder.ToString()).to
288+
.equal('First Part... Second Part...');
289+
});
290+
});
291+
292+
describe('StringBuilderng.Append', () => {
273293
it('should append characters', () => {
274294
var builder = new StringBuilder();
275295
builder.Append('First Part... ');
@@ -290,7 +310,7 @@ describe('String.Append', () => {
290310
});
291311
});
292312

293-
describe('String.AppendLine', () => {
313+
describe('StringBuilder.AppendLine', () => {
294314
it('should append characters and new line', () => {
295315
var builder = new StringBuilder();
296316
builder.AppendLine('First Line...');

0 commit comments

Comments
 (0)