Skip to content

Commit

Permalink
StringBuilder and empty string handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilk committed May 29, 2012
1 parent 7949d0c commit ae47e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Client/Runtime/Base/BCL.js
Expand Up @@ -9,12 +9,12 @@ function Tuple(first, second, third) {
}

function StringBuilder(s) {
this._parts = isValue(s) ? [s] : [];
this._parts = isValue(s) && s !== '' ? [s] : [];
this.isEmpty = this._parts.length == 0;
}
var StringBuilder$proto = {
append: function(s) {
if (isValue(s)) {
if (isValue(s) && s !== '') {
this._parts.push(s);
this.isEmpty = false;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Client/Runtime/Core/StringBuilder.htm
Expand Up @@ -79,6 +79,24 @@ <h2 id="qunit-userAgent"></h2>
sb.append([1,2]);
QUnit.equal(sb.toString(':'), 'abc:123:true:false:1,2');
});

test('isEmpty', function() {
var sb = new ss.StringBuilder();
QUnit.equal(sb.isEmpty, true);

sb.append('');
QUnit.equal(sb.isEmpty, true);

sb.append(null);
QUnit.equal(sb.isEmpty, true);

sb.append(undefined);
QUnit.equal(sb.isEmpty, true);

sb.append(0);
QUnit.equal(sb.isEmpty, false);
QUnit.equal(sb.toString(), '0');
});
</script>
</body>

Expand Down

0 comments on commit ae47e50

Please sign in to comment.