OLD | NEW |
(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 } |
OLD | NEW |