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