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

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: 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/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..34309c5485335c3f8459b42d4f22411697a7c6ae
--- /dev/null
+++ b/recipes/test/core/strings/interpolating_expressions_test.dart
@@ -0,0 +1,47 @@
+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', () {
+ var favFood = 'sushi';
+
+ test('without {}', () {
+ expect('I love $favFood', equals('I love sushi'));
+ });
+
+ test('with {}', () {
+ expect('I love ${favFood.toUpperCase()}', equals('I love SUSHI'));
+ });
+
+ test('with implicit toString()', () {
+ var four = 4;
+ var point = new Point(3, 4);
+ expect('The $four seasons', equals('The 4 seasons'));
+ expect('The '.concat(4.toString()).concat(' seasons'), equals('The 4 seasons'));
+ 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'));
+
+ });
+
+ test('inside a raw string', () {
+ expect(r'$favFood', equals('\$favFood'));
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698