浏览代码

fixed StringBuf.add(null) on php and js

Nicolas Cannasse 14 年之前
父节点
当前提交
09981f3218
共有 5 个文件被更改,包括 21 次插入4 次删除
  1. 1 0
      doc/CHANGES.txt
  2. 4 2
      std/StringBuf.hx
  3. 1 1
      std/neko/_std/StringBuf.hx
  4. 2 1
      std/php/_std/StringBuf.hx
  5. 13 0
      tests/unit/TestMisc.hx

+ 1 - 0
doc/CHANGES.txt

@@ -39,6 +39,7 @@
 		spod_macro now uses wrappers for Bytes (require neko 1.8.2)
 	php : added --php-prefix for prefixing generated files and class names
 	all : added type_expr_with_type enum support
+	php/js : fixed adding 'null' to StringBuf
 
 2011-01-30: 2.07
 	all : fixed completion support with --remap

+ 4 - 2
std/StringBuf.hx

@@ -43,8 +43,10 @@ class StringBuf {
 	/**
 		Adds the representation of any value to the string buffer.
 	**/
-	public inline function add( ?x : Dynamic ) {
-		#if (js || cpp)
+	public inline function add( x : Dynamic ) {
+		#if js
+			b[b.length] = x == null ? 'null' : x;
+		#elseif cpp
 			b[b.length] = x;
 		#else
 			b += x;

+ 1 - 1
std/neko/_std/StringBuf.hx

@@ -31,7 +31,7 @@
 		b = __make();
 	}
 
-	public inline function add( ?x : Dynamic ) : Void {
+	public inline function add( x : Dynamic ) : Void {
 		__add(b,x);
 	}
 

+ 2 - 1
std/php/_std/StringBuf.hx

@@ -30,7 +30,8 @@
 		b = "";
 	}
 
-	public inline function add( ?x : Dynamic ) : Void {
+	public inline function add( x : Dynamic ) : Void {
+		untyped if( __call__('is_null',x) ) x = 'null' else if( __call__('is_bool',x) ) x = x?'true':'false';
 		b += x;
 	}
 

+ 13 - 0
tests/unit/TestMisc.hx

@@ -299,4 +299,17 @@ class TestMisc extends Test {
 		eq( e.get(), 7 );
 	}
 
+	function testStringBuf() {
+		var b = new StringBuf();
+		b.add( -45);
+		b.add(1.456);
+		b.add(null);
+		b.add(true);
+		b.add(false);
+		b.add("Hello!");
+		b.addSub("Bla", 1, 2);
+		b.addChar("R".code);
+		eq(b.toString(), "-451.456nulltruefalseHello!laR");
+	}
+	
 }