mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
b05a57d5f3
Change-Id: I04e64359acb95c63d1b5dc5c7fdfaadcb6c55fd9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130965 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
74 lines
2.7 KiB
Dart
74 lines
2.7 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library utf8_test;
|
|
|
|
import "package:expect/expect.dart";
|
|
import 'dart:convert';
|
|
import 'dart:typed_data' show Uint8List;
|
|
|
|
/// [bytes] transforms the input into some representation (eg. plain list,
|
|
/// Uint8List).
|
|
test(List<int> bytes(List<int> input)) {
|
|
// Test that UTF8-decoder removes leading BOM.
|
|
Expect.equals("a", utf8.decode(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals("a", utf8.decoder.convert(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals(
|
|
"a", new Utf8Decoder().convert(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals(
|
|
"a", utf8.decode(bytes([0xEF, 0xBB, 0xBF, 0x61]), allowMalformed: true));
|
|
Expect.equals(
|
|
"a",
|
|
new Utf8Codec(allowMalformed: true)
|
|
.decode(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals(
|
|
"a",
|
|
new Utf8Codec(allowMalformed: true)
|
|
.decoder
|
|
.convert(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals(
|
|
"a",
|
|
new Utf8Decoder(allowMalformed: true)
|
|
.convert(bytes([0xEF, 0xBB, 0xBF, 0x61])));
|
|
Expect.equals("", utf8.decode(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals("", utf8.decoder.convert(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals("", new Utf8Decoder().convert(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"", utf8.decode(bytes([0xEF, 0xBB, 0xBF]), allowMalformed: true));
|
|
Expect.equals("",
|
|
new Utf8Codec(allowMalformed: true).decode(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"",
|
|
new Utf8Codec(allowMalformed: true)
|
|
.decoder
|
|
.convert(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals("",
|
|
new Utf8Decoder(allowMalformed: true).convert(bytes([0xEF, 0xBB, 0xBF])));
|
|
Expect.equals("a\u{FEFF}", utf8.decode(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"a\u{FEFF}", utf8.decoder.convert(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"a\u{FEFF}", new Utf8Decoder().convert(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
Expect.equals("a\u{FEFF}",
|
|
utf8.decode(bytes([0x61, 0xEF, 0xBB, 0xBF]), allowMalformed: true));
|
|
Expect.equals(
|
|
"a\u{FEFF}",
|
|
new Utf8Codec(allowMalformed: true)
|
|
.decode(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"a\u{FEFF}",
|
|
new Utf8Codec(allowMalformed: true)
|
|
.decoder
|
|
.convert(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
Expect.equals(
|
|
"a\u{FEFF}",
|
|
new Utf8Decoder(allowMalformed: true)
|
|
.convert(bytes([0x61, 0xEF, 0xBB, 0xBF])));
|
|
}
|
|
|
|
main() {
|
|
test((list) => list);
|
|
test((list) => new Uint8List.fromList(list));
|
|
}
|