OLD | NEW |
(Empty) | |
| 1 library converting_chars_nums_test; |
| 2 |
| 3 import 'package:unittest/unittest.dart'; |
| 4 |
| 5 |
| 6 void main() { |
| 7 group('converting between string characters and numerical codes', () { |
| 8 var smileyFace = '\u263A'; |
| 9 var clef = '\u{1F3BC}'; |
| 10 |
| 11 group('using runes', () { |
| 12 test('', () { |
| 13 expect('Dart'.runes.toList(), equals([68, 97, 114, 116])); |
| 14 |
| 15 var codePoints = smileyFace.runes.toList(); // [9786] |
| 16 expect(codePoints.first.toRadixString(16), equals('263a')); |
| 17 |
| 18 codePoints = clef.runes.toList(); // [127932] |
| 19 expect(codePoints.first.toRadixString(16), equals('1f3bc')); |
| 20 }); |
| 21 }); |
| 22 |
| 23 group('using codeUnits', () { |
| 24 test('', () { |
| 25 expect('Dart'.codeUnits.toList(), equals([68, 97, 114, 116])); |
| 26 |
| 27 var codeUnits = smileyFace.codeUnits.toList(); // [9786] |
| 28 expect(codeUnits.first.toRadixString(16), equals('263a')); |
| 29 |
| 30 codeUnits = clef.codeUnits.toList(); // [55356, 57276] |
| 31 expect(codeUnits.map((codeUnit) => codeUnit.toRadixString(16)).toList(),
equals(['d83c', 'dfbc'])); |
| 32 }); |
| 33 }); |
| 34 |
| 35 group('using codeUnitAt', () { |
| 36 test('', () { |
| 37 expect('Dart'.codeUnitAt(0), equals(68)); |
| 38 |
| 39 var codeUnit = smileyFace.codeUnitAt(0); // 9786 |
| 40 expect(codeUnit.toRadixString(16), equals('263a')); |
| 41 |
| 42 codeUnit = clef.codeUnitAt(0); // 55356 |
| 43 expect(codeUnit.toRadixString(16), equals('d83c')); |
| 44 |
| 45 codeUnit = clef.codeUnitAt(1); // 57276 |
| 46 expect(codeUnit.toRadixString(16), equals('dfbc')); |
| 47 }); |
| 48 }); |
| 49 |
| 50 group('using fromCharCodes', () { |
| 51 var heart = '\u2661'; |
| 52 |
| 53 test('', () { |
| 54 expect(new String.fromCharCodes([68, 97, 114, 116]), equals('Dart')); |
| 55 expect(new String.fromCharCodes([73, 32, 9825, 32, 76, 117, 99, 121]), |
| 56 equals("I $heart Lucy")); |
| 57 }); |
| 58 |
| 59 var smileyFace = '\u263A'; |
| 60 test('', () { |
| 61 expect(new String.fromCharCodes([9786]), equals(smileyFace)); |
| 62 }); |
| 63 |
| 64 test('with surrogate pair codeUnits', () { |
| 65 expect(new String.fromCharCodes([55356, 57276]), equals(clef)); |
| 66 }); |
| 67 |
| 68 test('with rune', () { |
| 69 expect(new String.fromCharCode(127932), equals(clef)); |
| 70 }); |
| 71 }); |
| 72 }); |
| 73 } |
OLD | NEW |