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

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

Issue 12335109: Strings recipes for the Dart Cookbook (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Made most changes requested my Kathy. Created 7 years, 9 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/interpolating_expressions_test.dart
diff --git a/recipes/test/core/strings/interpolating_expressions_test.dart b/recipes/test/core/strings/interpolating_expressions_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..29d92ae2a11e88fe27084fd96435dfd77a3c2a7c
--- /dev/null
+++ b/recipes/test/core/strings/interpolating_expressions_test.dart
@@ -0,0 +1,40 @@
+library interpolating_expressions_test;
+
+import 'package:unittest/unittest.dart';
+
+class Point {
+ num x, y;
+ Point(this.x, this.y);
+}
+
+class PointWithToString {
+ num x, y;
+ PointWithToString(this.x, this.y);
+
+ String toString() => 'x: $x, y: $y';
+}
+
+void main() {
+ group('interpolating expressions', () {
+ test('without {}', () {
+ var favFood = 'sushi';
+ expect('I love ${favFood.toUpperCase()}', equals('I love SUSHI'));
+ expect('I love $favFood', equals('I love sushi'));
+ });
+
+ test('with implicit toString()', () {
+ var four = 4;
+ expect('The $four seasons', equals('The 4 seasons'));
+ expect('The '.concat(4.toString()).concat(' seasons'), equals('The 4 seasons'));
+
+ var point = new Point(3, 4);
+ expect('Point: $point', equals("Point: Instance of 'Point'"));
+ });
+
+ test('with explicit toString()', () {
+ var point = new PointWithToString(3, 4);
+ expect('Point: $point', equals('Point: x: 3, y: 4'));
+
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698