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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 library interpolating_expressions_test;
2
3 import 'package:unittest/unittest.dart';
4
5 class Point {
6 num x, y;
7 Point(this.x, this.y);
8 }
9
10 class PointWithToString {
11 num x, y;
12 PointWithToString(this.x, this.y);
13
14 String toString() => 'x: $x, y: $y';
15 }
16
17 void main() {
18 group('interpolating expressions', () {
19 test('without {}', () {
20 var favFood = 'sushi';
21 expect('I love ${favFood.toUpperCase()}', equals('I love SUSHI'));
22 expect('I love $favFood', equals('I love sushi'));
23 });
24
25 test('with implicit toString()', () {
26 var four = 4;
27 expect('The $four seasons', equals('The 4 seasons'));
28 expect('The '.concat(4.toString()).concat(' seasons'), equals('The 4 seaso ns'));
29
30 var point = new Point(3, 4);
31 expect('Point: $point', equals("Point: Instance of 'Point'"));
32 });
33
34 test('with explicit toString()', () {
35 var point = new PointWithToString(3, 4);
36 expect('Point: $point', equals('Point: x: 3, y: 4'));
37
38 });
39 });
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698