Преглед на файлове

ensure consistent formating for Array and enums

Nicolas Cannasse преди 13 години
родител
ревизия
22a9fe78b2
променени са 4 файла, в които са добавени 20 реда и са изтрити 12 реда
  1. 1 1
      std/neko/_std/Array.hx
  2. 4 4
      std/php/Boot.hx
  3. 14 4
      tests/unit/TestBasetypes.hx
  4. 1 3
      tests/unit/unit.hxml

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

@@ -102,7 +102,7 @@
 		for( i in it ) {
 			s.add(i);
 			if( it.hasNext() )
-				s.add(", ");
+				s.addChar(",".code);
 		}
 		s.add("]");
 		return s.toString();

+ 4 - 4
std/php/Boot.hx

@@ -121,7 +121,7 @@ class _hx_array implements ArrayAccess, IteratorAggregate {
 	}
 
 	function toString() {
-		return '['.implode(', ', $this->»a).']';
+		return '['.implode(',', $this->»a).']';
 	}
 
 	function __toString() {
@@ -515,7 +515,7 @@ function _hx_string_rec($o, $s) {
 				$b .= '(';
 				for($i = 0; $i < count($o->params); $i++) {
 					if($i > 0)
-						$b .= ', ' . _hx_string_rec($o->params[$i], $s);
+						$b .= ',' . _hx_string_rec($o->params[$i], $s);
 					else
 						$b .= _hx_string_rec($o->params[$i], $s);
 				}
@@ -560,7 +560,7 @@ function _hx_string_rec($o, $s) {
 	}
 	if(is_string($o)) {
 		if(_hx_is_lambda($o)) return '«function»';
-		if(strlen($s) > 0)    return '\"' . str_replace('\"', '\\\"', $o) . '\"';
+//		if(strlen($s) > 0)    return '\"' . str_replace('\"', '\\\"', $o) . '\"';
 		else                  return $o;
 	}
 	if(is_array($o)) {
@@ -573,7 +573,7 @@ function _hx_string_rec($o, $s) {
 		{
 			if ($first && $k === 0)
 				$assoc = false;
-			$str .= ($first ? '' : ', ') . ($assoc
+			$str .= ($first ? '' : ',') . ($assoc
 				? _hx_string_rec($k, $s) . '=>' . _hx_string_rec($o[$k], $s)
 				: _hx_string_rec($o[$k], $s)
 			);

+ 14 - 4
tests/unit/TestBasetypes.hx

@@ -94,13 +94,16 @@ class TestBasetypes extends Test {
 		
 		// Brackets around array values should not be stripped.
 		var x = [1, "hello"];
-		eq("" + x, "[1, hello]");
+		eq("" + x, "[1,hello]");
 		eq(x + "", "" + x);
+		
+		var x = [[1], [2, 3]];
+		eq("" + x, "[[1],[2,3]]");
 
 		// This is also true for iterables that are arrays.
 		var x:Iterable<Dynamic> = [1, "hello"];
-		eq("" + x, "[1, hello]");
-		eq(x + "", "" + x);		
+		eq("" + x, "[1,hello]");
+		eq(x + "", "" + x);
 		
 		// I don't think this should throw an exception on PHP.
 		try {
@@ -108,13 +111,20 @@ class TestBasetypes extends Test {
 		} catch (e:Dynamic)	{
 			Test.report("Could not convert Iterator to String");
 		}
+
+		var str = "he\nlo\"'";
+		eq( Std.string(str), str);
+		eq( Std.string([str]), "[" + str + "]");
+		
+		var e = MyEnum.C(0, "h");
+		eq( Std.string(e), "C(0,h)");
 		
 		// This also seems rather odd on some platforms.
 		var x = ["4", 1];
 		t(Std.is(x[0], String));
 		t(Std.is(x[0] + x[0], String));
 		t(Std.is(x[1] + x[1], Int));
-		t(Std.is(x[0] + x[1], String));		
+		t(Std.is(x[0] + x[1], String));
 	}
 
 	function testMath() {

+ 1 - 3
tests/unit/unit.hxml

@@ -7,7 +7,6 @@
 params.hxml
 --next
 -swf unit9.swf
--swf-header 300:650:30:FFFFFF
 -swf-version 11
 -main unit.Test
 params.hxml
@@ -17,8 +16,7 @@ params.hxml
 -main unit.Test
 --next
 -js unit.js
--main unit.Test
---js-modern
+unit.Test
 params.hxml
 --next
 -neko unit.n