dart-sdk/tests/corelib/string_trim_nel_test.dart
Ömer Sinan Ağacan 55f2754d6b [dart2wasm] Fix JSStringImpl trim methods, add tests
Fix trim methods returning a new string (instead of the argument) when
there's nothing to trim.

A second bug fixed in NEL handling in `trim`: the last line should be
`result.substring(...)` instead of `this.substring(...)`. The bug wasn't
caught by any of the tests: NEL needs to be handled specially on the
browser, but mixing NEL with other whitespace wasn't tested in the
existing tests `string_trim_test` and `string_trimlr_test`, so a new
test file added with this case.

Change-Id: Ibf84e185de1b26c9811e3ea58c2ad3f223da8515
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363081
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-04-17 14:41:52 +00:00

35 lines
1.3 KiB
Dart

// Copyright (c) 2024, 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.
// NEXT LINE (NEL, 0x85) character is special in that some Unicode versions do
// not include it as a whitespace character.
//
// However all Dart backends handle it as a whitespace character. dart2js and
// dart2wasm do this by a calling JS (`String.prototype.trim` and its
// left/right variants) and doing post-processing. To check these
// implementations tests in this file mix the SPACE character with NEL in
// various positions.
//
// string_trim_lr_test.dart tests various NEL characters on the left and right,
// but they do not mix NEL with other whitespace characters.
// string_trim_test.dart tests do not test NEL.
import "package:expect/expect.dart";
const int space = 0x20;
const int nel = 0x85;
const int h = 0x68;
const int i = 0x69;
void main() {
Expect.equals(
"hi", String.fromCharCodes([space, nel, space, h, i]).trimLeft());
Expect.equals(
"hi", String.fromCharCodes([h, i, space, nel, space]).trimRight());
Expect.equals(
"hi",
String.fromCharCodes([space, nel, space, h, i, space, nel, space])
.trim());
}