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

Side by Side Diff: tests/corelib/src/StringBaseVMTest.dart

Issue 10244009: test rename overhaul: step 7 - corelib 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 // Dart test program for testing class 'StringBase' (currently VM specific).
5
6 #library("StringBaseTest.dart");
7 #import("dart:coreimpl");
8
9
10 class StringBaseTest {
11
12 StringBaseTest() {}
13
14 toString() {
15 return "StringBase Tester";
16 }
17 static testSubstringMatches() {
18 Expect.equals(true, "Hello".substringMatches(0, "Hello"));
19 Expect.equals(true, "Hello World".substringMatches(0, "Hello"));
20 Expect.equals(false, "My Hello World".substringMatches(0, "Hello"));
21 Expect.equals(true, "My Hello World".substringMatches(6, "lo W"));
22 Expect.equals(false, "Hello".substringMatches(0, "low"));
23 }
24
25 static testInterpolation() {
26 var answer = 40 + 2;
27 var s = "The answer is $answer.";
28 Expect.equals("The answer is 42.", s);
29
30 int numBottles = 33;
31 String wall = "wall";
32 s = "${numBottles*3} bottles of beer on the $wall.";
33 Expect.equals("99 bottles of beer on the wall.", s);
34 }
35
36 static testCreation() {
37 String s = "Hello";
38 List<int> a = new List(s.length);
39 List<int> ga = new List();
40 bool exception_caught = false;
41 for (int i = 0; i < a.length; i++) {
42 a[i] = s.charCodeAt(i);
43 ga.add(s.charCodeAt(i));
44 }
45 String s2 = StringBase.createFromCharCodes(a);
46 Expect.equals(s, s2);
47 String s3 = StringBase.createFromCharCodes(ga);
48 Expect.equals(s, s3);
49 try {
50 String s4 = new String.fromCharCodes([0.0]);
51 } catch (IllegalArgumentException ex) {
52 exception_caught = true;
53 }
54 Expect.equals(true, exception_caught);
55 exception_caught = false;
56 try {
57 String s4 = new String.fromCharCodes([-1]);
58 } catch (IllegalArgumentException ex) {
59 exception_caught = true;
60 }
61 Expect.equals(true, exception_caught);
62 }
63
64 static testSubstring() {
65 String s = "Hello World";
66 Expect.equals("World", s.substring(6, s.length));
67 Expect.equals("", s.substring(8, 8));
68 bool exception_caught = false;
69 try {
70 s.substring(5, 12);
71 } catch (IndexOutOfRangeException ex) {
72 exception_caught = true;
73 }
74 Expect.equals(true, exception_caught);
75 exception_caught = false;
76 try {
77 s.substring(5, 4);
78 } catch (IndexOutOfRangeException ex) {
79 exception_caught = true;
80 }
81 Expect.equals(true, exception_caught);
82 }
83
84 static void testMain() {
85 testSubstringMatches();
86 testInterpolation();
87 testCreation();
88 testSubstring();
89 }
90 }
91
92 main() {
93 StringBaseTest.testMain();
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698