| Index: utils/tests/string_encoding/UnicodeCoreTests.dart
|
| diff --git a/utils/tests/string_encoding/UnicodeCoreTests.dart b/utils/tests/string_encoding/UnicodeCoreTests.dart
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..a74148aa1957d2a2bc49b1e30c508c4b6ac9d674
|
| --- /dev/null
|
| +++ b/utils/tests/string_encoding/UnicodeCoreTests.dart
|
| @@ -0,0 +1,102 @@
|
| +#!/usr/bin/env dart
|
| +// Copyright (c) 2011, 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("UnicodeCoreTests");
|
| +#import("DUnit.dart");
|
| +#import("../../string_encoding/UnicodeCore.dart");
|
| +
|
| +void main() {
|
| + TestSuite suite = new TestSuite();
|
| + suite.registerTestClass(new UnicodeCoreTests());
|
| + suite.run();
|
| +}
|
| +
|
| +class UnicodeCoreTests extends TestClass {
|
| + void registerTests(TestSuite suite) {
|
| + register("testPlatform", testPlatform, suite);
|
| + register("testCodepointsToUtf16CodeUnits", testCodepointsToUtf16CodeUnits, suite);
|
| + register("testUtf16bytesToCodepoints", testUtf16bytesToCodepoints, suite);
|
| + }
|
| +
|
| + void testPlatform() {
|
| + Expect.isFalse(is16BitCodeUnit());
|
| + }
|
| +
|
| + void testCodepointsToUtf16CodeUnits() {
|
| + // boundary conditions
|
| + Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0");
|
| + Expect.listEquals([0xd800, 0xdc00],
|
| + codepointsToUtf16CodeUnits([0x10000]), "10000");
|
| +
|
| + Expect.listEquals([0xffff],
|
| + codepointsToUtf16CodeUnits([0xffff]), "ffff");
|
| + Expect.listEquals([0xdbff, 0xdfff],
|
| + codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
|
| +
|
| + Expect.listEquals([0xd7ff],
|
| + codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
|
| + Expect.listEquals([0xe000],
|
| + codepointsToUtf16CodeUnits([0xe000]), "e000");
|
| +
|
| + Expect.listEquals([REPLACEMENT_CHARACTER_CODEPOINT],
|
| + codepointsToUtf16CodeUnits([0xd800]), "d800");
|
| + Expect.listEquals([REPLACEMENT_CHARACTER_CODEPOINT],
|
| + codepointsToUtf16CodeUnits([0xdfff]), "dfff");
|
| + }
|
| +
|
| + void testUtf16bytesToCodepoints() {
|
| + // boundary conditions: First possible values
|
| + Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0");
|
| + Expect.listEquals([0x10000],
|
| + utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
|
| +
|
| + // boundary conditions: Last possible sequence of a certain length
|
| + Expect.listEquals([0xffff],
|
| + utf16CodeUnitsToCodepoints([0xffff]), "ffff");
|
| + Expect.listEquals([0x10ffff],
|
| + utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
|
| +
|
| + // other boundary conditions
|
| + Expect.listEquals([0xd7ff],
|
| + utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff");
|
| + Expect.listEquals([0xe000],
|
| + utf16CodeUnitsToCodepoints([0xe000]), "e000");
|
| +
|
| + // unexpected continuation bytes
|
| + Expect.listEquals([0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xdc00]),
|
| + "dc00 first unexpected continuation byte");
|
| + Expect.listEquals([0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xdfff]),
|
| + "dfff last unexpected continuation byte");
|
| + Expect.listEquals([0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xdc00]),
|
| + "1 unexpected continuation bytes");
|
| + Expect.listEquals([0xfffd, 0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]),
|
| + "2 unexpected continuation bytes");
|
| + Expect.listEquals([0xfffd, 0xfffd ,0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]),
|
| + "3 unexpected continuation bytes");
|
| +
|
| + // incomplete sequences
|
| + Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]),
|
| + "d800 last byte missing");
|
| + Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]),
|
| + "dbff last byte missing");
|
| +
|
| + // concatenation of incomplete sequences
|
| + Expect.listEquals([0xfffd, 0xfffd],
|
| + utf16CodeUnitsToCodepoints([0xd800, 0xdbff]),
|
| + "d800 dbff last byte missing");
|
| +
|
| + // impossible bytes
|
| + Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]),
|
| + "110000 out of bounds");
|
| +
|
| + // overlong sequences not possible in utf16 (nothing < x10000)
|
| + // illegal code positions d800-dfff not encodable (< x10000)
|
| + }
|
| +}
|
|
|