mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:56:23 +00:00
e4cc3c98e5
TEST=ci Bug: Contributes to https://github.com/dart-lang/sdk/issues/49529 Change-Id: Ic129ef2d89f625d9ec6a7a1c301cffddd60b2ff7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258920 Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Michael Thomsen <mit@google.com> Reviewed-by: Slava Egorov <vegorov@google.com>
77 lines
1.8 KiB
Dart
77 lines
1.8 KiB
Dart
// Copyright (c) 2012, 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.
|
|
// Dart test program for testing class 'StringBase' (currently VM specific).
|
|
|
|
// @dart = 2.9
|
|
|
|
library string_base_test;
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class StringBaseTest {
|
|
StringBaseTest() {}
|
|
|
|
toString() {
|
|
return "StringBase Tester";
|
|
}
|
|
|
|
static testInterpolation() {
|
|
var answer = 40 + 2;
|
|
var s = "The answer is $answer.";
|
|
Expect.equals("The answer is 42.", s);
|
|
|
|
int numBottles = 33;
|
|
String wall = "wall";
|
|
s = "${numBottles*3} bottles of beer on the $wall.";
|
|
Expect.equals("99 bottles of beer on the wall.", s);
|
|
}
|
|
|
|
static testCreation() {
|
|
String s = "Hello";
|
|
List<int> a = new List.filled(s.length, null);
|
|
List<int> ga = [];
|
|
bool exception_caught = false;
|
|
for (int i = 0; i < a.length; i++) {
|
|
a[i] = s.codeUnitAt(i);
|
|
ga.add(s.codeUnitAt(i));
|
|
}
|
|
try {
|
|
String s4 = new String.fromCharCodes([-1]);
|
|
} on ArgumentError catch (ex) {
|
|
exception_caught = true;
|
|
}
|
|
Expect.equals(true, exception_caught);
|
|
}
|
|
|
|
static testSubstring() {
|
|
String s = "Hello World";
|
|
Expect.equals("World", s.substring(6, s.length));
|
|
Expect.equals("", s.substring(8, 8));
|
|
bool exception_caught = false;
|
|
try {
|
|
s.substring(5, 12);
|
|
} on RangeError catch (ex) {
|
|
exception_caught = true;
|
|
}
|
|
Expect.equals(true, exception_caught);
|
|
exception_caught = false;
|
|
try {
|
|
s.substring(5, 4);
|
|
} on RangeError catch (ex) {
|
|
exception_caught = true;
|
|
}
|
|
Expect.equals(true, exception_caught);
|
|
}
|
|
|
|
static void testMain() {
|
|
testInterpolation();
|
|
testCreation();
|
|
testSubstring();
|
|
}
|
|
}
|
|
|
|
main() {
|
|
StringBaseTest.testMain();
|
|
}
|