Permalink
Browse files

StringBuilder and empty string handling

  • Loading branch information...
1 parent 7949d0c commit ae47e506c2e2846c2ac2c3479a429c42cf1f6f9d @nikhilk committed May 29, 2012
Showing with 20 additions and 2 deletions.
  1. +2 −2 src/Client/Runtime/Base/BCL.js
  2. +18 −0 tests/Client/Runtime/Core/StringBuilder.htm
@@ -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;
}
@@ -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>

0 comments on commit ae47e50

Please sign in to comment.