Fix tests in language suite: eliminate String +

The language suite runs clean without String + after this change.

string_concat_test.dart is obsolete, removed.
Review URL: https://chromiumcodereview.appspot.com//10383238

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7745 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
hausner@google.com 2012-05-18 15:33:05 +00:00
parent 98bb9e8526
commit 6fece3e398
14 changed files with 42 additions and 112 deletions

View file

@ -146,7 +146,7 @@ String _filePathFromPackageUri(Uri uri) {
var right = 'package:$path';
var wrong = 'package://$path';
throw "URIs using the 'package:' scheme should look like " +
throw "URIs using the 'package:' scheme should look like "
"'$right', not '$wrong'.";
}

View file

@ -61,7 +61,7 @@ class DateImplementation implements Date {
// - "2012-02-27T14Z"
// - "-123450101 00:00:00 Z" // In the year -12345.
final RegExp re = const RegExp(
@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d)' + // The day part.
@'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d)' // The day part.
@'(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)? ?([zZ])?)?$');
Match match = re.firstMatch(formattedString);
if (match !== null) {

View file

@ -52,7 +52,7 @@ class CallThroughNullGetterTest {
var exception = catchException(fn);
if (!(exception is NullPointerException)) {
Expect.fail("Wrong exception. Expected: NullPointerException"
+ " got: ${exception}");
" got: ${exception}");
}
}
@ -60,7 +60,7 @@ class CallThroughNullGetterTest {
var exception = catchException(fn);
if (!(exception is ObjectNotClosureException)) {
Expect.fail("Wrong exception. Expected: ObjectNotClosureException"
+ " got: ${exception}");
" got: ${exception}");
}
}

View file

@ -12,24 +12,24 @@ main() {
Expect.isTrue('ab\'cd' === "ab'cd");
// String concatenation works even when quotes are different.
Expect.isTrue("abcd" === "ab" + "cd");
Expect.isTrue("abcd" === "ab" + 'cd');
Expect.isTrue("abcd" === 'ab' + 'cd');
Expect.isTrue("abcd" === 'ab' + "cd");
Expect.isTrue("abcd" === "ab" "cd");
Expect.isTrue("abcd" === "ab" 'cd');
Expect.isTrue("abcd" === 'ab' 'cd');
Expect.isTrue("abcd" === 'ab' "cd");
// Or when there are more than 2 contatenations.
Expect.isTrue("abcd" === "a" + "b" + "cd");
Expect.isTrue("abcd" === "a" + "b" + "c" + "d");
Expect.isTrue('abcd' === 'a' + 'b' + 'c' + 'd');
Expect.isTrue("abcd" === "a" + "b" + 'c' + "d");
Expect.isTrue("abcd" === 'a' + 'b' + 'c' + 'd');
Expect.isTrue("abcd" === 'a' + "b" + 'c' + "d");
Expect.isTrue("abcd" === "a" "b" "cd");
Expect.isTrue("abcd" === "a" "b" "c" "d");
Expect.isTrue('abcd' === 'a' 'b' 'c' 'd');
Expect.isTrue("abcd" === "a" "b" 'c' "d");
Expect.isTrue("abcd" === 'a' 'b' 'c' 'd');
Expect.isTrue("abcd" === 'a' "b" 'c' "d");
Expect.isTrue("a'b'cd" === "a" + "'b'" + 'c' + "d");
Expect.isTrue("a\"b\"cd" === "a" + '"b"' + 'c' + "d");
Expect.isTrue("a\"b\"cd" === "a" + '"b"' + 'c' + "d");
Expect.isTrue("a'b'cd" === 'a' + "'b'" + 'c' + "d");
Expect.isTrue('a\'b\'cd' === "a" + "'b'" + 'c' + "d");
Expect.isTrue('a"b"cd' === 'a' + '"b"' + 'c' + "d");
Expect.isTrue("a\"b\"cd" === 'a' + '"b"' + 'c' + "d");
Expect.isTrue("a'b'cd" === "a" "'b'" 'c' "d");
Expect.isTrue("a\"b\"cd" === "a" '"b"' 'c' "d");
Expect.isTrue("a\"b\"cd" === "a" '"b"' 'c' "d");
Expect.isTrue("a'b'cd" === 'a' "'b'" 'c' "d");
Expect.isTrue('a\'b\'cd' === "a" "'b'" 'c' "d");
Expect.isTrue('a"b"cd' === 'a' '"b"' 'c' "d");
Expect.isTrue("a\"b\"cd" === 'a' '"b"' 'c' "d");
}

View file

@ -26,7 +26,7 @@ main() {
Expect.isTrue(C0.X is C1);
Expect.isTrue(C0.X.x is C1); /// 09: compile-time error
Expect.equals("Hello42", B2);
Expect.equals("Hello 42", B2);
Expect.equals("42Hello", B3); /// 10: compile-time error
}
@ -69,5 +69,5 @@ class C1 {
// Check that sub-expressions of binary + are numeric.
final B0 = 42;
final B1 = "Hello";
final B2 = B1 + B0;
final B2 = "$B1 $B0";
final B3 = B0 + B1; /// 10: continued

View file

@ -49,7 +49,7 @@ class PseudoKWTest {
}
}
typedef(x) => "typedef " + x;
typedef(x) => "typedef $x";
static(abstract) {
return abstract == true;

View file

@ -11,9 +11,9 @@ class RegEx2Test {
if (match != null) {
print("got match");
int groupCount = match.groupCount();
print("groupCount is " + groupCount);
print("group 0 is " + match.group(0));
print("group 1 is " + match.group(1));
print("groupCount is $groupCount");
print("group 0 is ${match.group(0)}");
print("group 1 is ${match.group(1)}");
} else {
print("match not round");
}

View file

@ -6,9 +6,9 @@
class RegExp2Test {
static String findImageTag_(String text, String extensions) {
final re = new RegExp('src="(http://\\S+\\.(${extensions}))"');
print('REGEXP findImageTag_ ' + extensions + ' text: \n' + text);
print('REGEXP findImageTag_ $extensions text: \n$text');
final match = re.firstMatch(text);
print('REGEXP findImageTag_ ' + extensions + ' SUCCESS');
print('REGEXP findImageTag_ $extensions SUCCESS');
if (match != null) {
return match[1];
} else {

View file

@ -45,8 +45,8 @@ class SavannahTest {
var count = savannah.length;
print("getCount is $count");
Expect.equals(2, count);
print("giraffe1: " + savannah[giraffe1]);
print("giraffe2: " + savannah[giraffe2]);
print("giraffe1: ${savannah[giraffe1]}");
print("giraffe2: ${savannah[giraffe2]}");
Expect.equals("Tony", savannah[giraffe1]);
Expect.equals("Rose", savannah[giraffe2]);
@ -68,8 +68,8 @@ class SavannahTest {
caught = false;
try {
print("zebra1: " + savannah[zebra1]);
print("zebra2: " + savannah[zebra2]);
print("zebra1: ${savannah[zebra1]}");
print("zebra2: ${savannah[zebra2]}");
} catch (NoSuchMethodException e) {
print("Caught: $e");
caught = true;

View file

@ -1,70 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// String concatenation test.
interface V {
static final Version = "7.3.5.3";
}
class StringConcatTest {
static final Tag = "version-" + V.Version;
static Answer() {
return 42;
}
static testMain() {
int nofExceptions = 0;
var x = 3;
var y = 5;
Expect.equals("" + x + y, "35");
Expect.equals(x + y, 8);
var s1 = "The answer is " + Answer() + '.';
Expect.equals(s1, "The answer is 42.");
Expect.equals("version-7.3.5.3", Tag);
// Adding a number to a string value creates a new, concatenated
// string.
s1 = "Grandmaster Flash and the Furious ";
s1 = "$s1${4 + 1}";
Expect.equals(true, s1.endsWith("Furious 5"));
// Adding a string to a number is not supported.
try {
String cantDo = x + " should't work"; // throws noSuchMethodException.
Expect.equals(1, 0); // this should never be executed.
} catch(NoSuchMethodException e) {
// In default mode.
nofExceptions++;
} catch (TypeError e) {
// In type checked mode.
nofExceptions++;
} catch (IllegalArgumentException e) {
// TODO(floitsch): IllegalArgumentException might not be correct. If
// number operations are supposed to be implemented as double-dispatch
// then we should get a NoSuchMethodException instead. In frog the
// argument is eagerly checked and throws an IllegalArgumentException.
nofExceptions++;
}
// Check that compile time constants are canonicalized.
// TODO(hausner): Add more examples once we concatenate
// CT constants other than string literals at compile time.
var fake = "Milli" + " " + "Vanilli";
Expect.equals(fake, "Milli Vanilli");
Expect.equals(true, fake === "Milli Vanilli");
Expect.equals(true, fake === "Milli " + 'Vanilli');
Expect.equals(nofExceptions, 1);
}
}
main() {
StringConcatTest.testMain();
}

View file

@ -18,7 +18,7 @@ class A {
class B extends A {
B() : super() {}
String greeting() {
return "Hola " + super.greeting();
return "Hola ".concat(super.greeting());
}
}
@ -26,10 +26,10 @@ class B extends A {
class C extends B {
C() : super() {}
String greeting() {
return "Servus " + super.greeting();
return "Servus ".concat(super.greeting());
}
String get city() {
return "Basel " + super.city;
return "Basel ".concat(super.city);
}
}

View file

@ -9,7 +9,7 @@ class Base {
String get value() { return value_; }
String set value(String newValue) {
value_ = 'Base:' + newValue;
value_ = 'Base:$newValue';
}
}
@ -18,7 +18,7 @@ class Derived extends Base {
Derived() : super() {}
String set value(String newValue) {
super.value = 'Derived:' + newValue;
super.value = 'Derived:$newValue';
}
String get value() { return super.value; }
}

View file

@ -40,7 +40,7 @@ int Sum(List<int> v) {
return s;
}
get Window() { return "win" + "dow"; }
get Window() { return "win" "dow"; }
String rgb;

View file

@ -12,12 +12,12 @@ class Bar<T> implements Foo<T> {
Bar() {}
factory Bar.from() {
var func = (T arg) {
var func = (T arg) {
T foo = arg;
bool isString = foo is String;
print(arg);
print(" String=" + isString);
};
print(" String=$isString");
};
func("Hello World!"); // If T is not String, dynamic type checks should fail
return new Bar<T>();