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

Unified Diff: recipes/test/core/strings/determining_if_string_contains_test.dart

Issue 12335109: Strings recipes for the Dart Cookbook (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Fixed typos. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: recipes/test/core/strings/determining_if_string_contains_test.dart
diff --git a/recipes/test/core/strings/determining_if_string_contains_test.dart b/recipes/test/core/strings/determining_if_string_contains_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5b8e82f18c1af78b981f1ef3418423c455f50e97
--- /dev/null
+++ b/recipes/test/core/strings/determining_if_string_contains_test.dart
@@ -0,0 +1,32 @@
+library determining_if_string_contains_test;
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+
+ group('determining whether a string contains a substring', () {
+ var string = 'Dart strings are immutable';
+
+ test('using contains', () {
+ expect(string.contains('immutable'), isTrue);
+ expect(string.contains('Dart', 2), isFalse);
+ });
+
+ test('using startsWith()', () {
+ expect(string.startsWith('Dart'), isTrue);
+ });
+
+ test('using endsWith()', () {
+ assert(string.endsWith('e') == true);
+ });
+
+ test('using indexOf()', () {
+ expect(string.indexOf('art') != -1, isTrue);
+ });
+
+ test('using hasMatch()', () {
+ expect(new RegExp(r'ar[et]').hasMatch(string), isTrue);
+ });
+ });
+
+}

Powered by Google App Engine
This is Rietveld 408576698