OLD | NEW |
(Empty) | |
| 1 library splitting_strings_test; |
| 2 |
| 3 import 'package:unittest/unittest.dart'; |
| 4 |
| 5 void main() { |
| 6 group('splitting a string', () { |
| 7 var clef = '\u{1F3BC}'; |
| 8 var smileyFace = '\u263A'; |
| 9 var happy = 'I am $smileyFace'; |
| 10 |
| 11 group('using split(string)', () { |
| 12 test('on code-unit boundary', () { |
| 13 expect('Dart'.split(''), equals(['D', 'a', 'r', 't'])); |
| 14 expect(smileyFace.split('').length, equals(1)); |
| 15 expect(clef.split('').length, equals(2)); |
| 16 }); |
| 17 |
| 18 test('on rune boundary', () { |
| 19 expect(happy.runes.map((charCode) => new String.fromCharCode(charCode)).
toList(), |
| 20 equals(['I', ' ', 'a', 'm', ' ', '\u263A'])); |
| 21 }); |
| 22 }); |
| 23 |
| 24 group('using split(regExp)', () { |
| 25 var nums = "2/7 3 4/5 3~/5"; |
| 26 var numsRegExp = new RegExp(r'(\s|/|~/)'); |
| 27 test('', () { |
| 28 expect(nums.split(numsRegExp), |
| 29 equals(['2', '7', '3', '4', '5', '3', '5'])); |
| 30 }); |
| 31 }); |
| 32 |
| 33 group('using splitMapJoin(regExp)', () { |
| 34 expect('Eats SHOOTS leaves'.splitMapJoin((new RegExp(r'SHOOTS')), |
| 35 onMatch: (m) => '*${m.group(0).toLowerCase()}*', |
| 36 onNonMatch: (n) => n.toUpperCase() |
| 37 ), equals('EATS *shoots* LEAVES')); |
| 38 }); |
| 39 }); |
| 40 } |
OLD | NEW |