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

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: Fixed typos. 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 var favFood = 'sushi';
20
21 test('without {}', () {
22 expect('I love $favFood', equals('I love sushi'));
23 });
24
25 test('with {}', () {
26 expect('I love ${favFood.toUpperCase()}', equals('I love SUSHI'));
27 });
28
29 test('with implicit toString()', () {
30 var four = 4;
31 var point = new Point(3, 4);
32 expect('The $four seasons', equals('The 4 seasons'));
33 expect('The '.concat(4.toString()).concat(' seasons'), equals('The 4 seaso ns'));
34 expect('Point: $point', equals("Point: Instance of 'Point'"));
35 });
36
37 test('with explicit toString()', () {
38 var point = new PointWithToString(3, 4);
39 expect('Point: $point', equals('Point: x: 3, y: 4'));
40
41 });
42
43 test('inside a raw string', () {
44 expect(r'$favFood', equals('\$favFood'));
45 });
46 });
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698