Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/language/src/StringConcatTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // String concatenation test.
5
6 interface V {
7 static final Version = "7.3.5.3";
8 }
9
10
11 class StringConcatTest {
12
13 static final Tag = "version-" + V.Version;
14
15 static Answer() {
16 return 42;
17 }
18
19 static testMain() {
20 int nofExceptions = 0;
21
22 var x = 3;
23 var y = 5;
24 Expect.equals("" + x + y, "35");
25 Expect.equals(x + y, 8);
26
27 var s1 = "The answer is " + Answer() + '.';
28 Expect.equals(s1, "The answer is 42.");
29
30 Expect.equals("version-7.3.5.3", Tag);
31
32 // Adding a number to a string value creates a new, concatenated
33 // string.
34 s1 = "Grandmaster Flash and the Furious ";
35 s1 = "$s1${4 + 1}";
36 Expect.equals(true, s1.endsWith("Furious 5"));
37
38 // Adding a string to a number is not supported.
39 try {
40 String cantDo = x + " should't work"; // throws noSuchMethodException.
41 Expect.equals(1, 0); // this should never be executed.
42 } catch(NoSuchMethodException e) {
43 // In default mode.
44 nofExceptions++;
45 } catch (TypeError e) {
46 // In type checked mode.
47 nofExceptions++;
48 } catch (IllegalArgumentException e) {
49 // TODO(floitsch): IllegalArgumentException might not be correct. If
50 // number operations are supposed to be implemented as double-dispatch
51 // then we should get a NoSuchMethodException instead. In frog the
52 // argument is eagerly checked and throws an IllegalArgumentException.
53 nofExceptions++;
54 }
55
56 // Check that compile time constants are canonicalized.
57 // TODO(hausner): Add more examples once we concatenate
58 // CT constants other than string literals at compile time.
59 var fake = "Milli" + " " + "Vanilli";
60 Expect.equals(fake, "Milli Vanilli");
61 Expect.equals(true, fake === "Milli Vanilli");
62 Expect.equals(true, fake === "Milli " + 'Vanilli');
63
64 Expect.equals(nofExceptions, 1);
65 }
66 }
67
68 main() {
69 StringConcatTest.testMain();
70 }
OLDNEW
« no previous file with comments | « tests/language/src/StaticTopLevelTest.dart ('k') | tests/language/src/StringEscape1NegativeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698