Files
sdk/pkg/js_ast/test/string_escape_test.dart
T
Sigmund Cherem d358abfd1f [web] do not run most 'pkg' suite on web compilers
Many tests under `pkg`, like `pkg/js_ast` and `pkg/analyzer_cli` are
meant to run as unit tests in the Dart VM. These were also being run in
dart2js and causing flakiness because they took a long time to build on
our CQ.

Locally some of these tests compile in under 5s, but we see the
compile-time vary among the bots a lot. I've observed cases close to 30s
and some that reach the 1-minute timeout cutoff. Flakiness data show
that this is happening between 5-7% of the runs, especially on linux
bots.

This CL stops running these tests on the dart2js configuration by
changing which subset of the `pkg` suite is provided to dart2js. It also
adjusts the .status file to skip a few suites for convenience on local
testing only. This allows developers locally to run `test.py -n... pkg`
without worrying about filtering out skipped suites.

Addendum: after discussions on the CL we decided not to cmpletely drop
coverage of js_ast tests on JS to ensure it can be used in browser
environments in the future. To support this we made made the tests
cheaper by removing the dependency on package:test. They will now only
be run in a single configuration, which is all we need for this purpose.
We can reevaluate and remove this if we continue to see timeouts.

Change-Id: Idf0dbdd37e412ef71ba117ec979cb1e52585c431
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330704
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-10-20 19:08:17 +00:00

143 lines
3.9 KiB
Dart

// Copyright (c) 2015, 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 js_ast.string_escape_test;
import 'package:expect/minitest.dart';
import 'package:js_ast/js_ast.dart';
import 'package:js_ast/src/characters.dart';
const int $LCURLY = $OPEN_CURLY_BRACKET;
const int $RCURLY = $CLOSE_CURLY_BRACKET;
void main() {
void check(Object input, Object expected, {bool utf8 = false}) {
String string = input is String
? input
: String.fromCharCodes(List<int>.from(input as Iterable));
String actual = DebugPrint(js.string(string), utf8: utf8);
if (expected is List) {
expect(actual.codeUnits, expected);
} else {
expect(actual, expected);
}
}
test('simple', () {
check('', [$DQ, $DQ]);
check('a', [$DQ, $a, $DQ]);
});
test('simple-escapes', () {
check([$BS], [$DQ, $BACKSLASH, $b, $DQ]);
check([$BS], [$DQ, $BACKSLASH, $b, $DQ], utf8: true);
check([$LF], [$DQ, $BACKSLASH, $n, $DQ]);
check([$LF], [$DQ, $BACKSLASH, $n, $DQ], utf8: true);
check([$FF], [$DQ, $BACKSLASH, $f, $DQ]);
check([$FF], [$DQ, $BACKSLASH, $f, $DQ], utf8: true);
check([$CR], [$DQ, $BACKSLASH, $r, $DQ]);
check([$CR], [$DQ, $BACKSLASH, $r, $DQ], utf8: true);
check([$TAB], [$DQ, $BACKSLASH, $t, $DQ]);
check([$TAB], [$DQ, $BACKSLASH, $t, $DQ], utf8: true);
check([$VTAB], [$DQ, $BACKSLASH, $v, $DQ]);
check([$VTAB], [$DQ, $BACKSLASH, $v, $DQ], utf8: true);
});
test('unnamed-control-codes-escapes', () {
check([0, 1, 2, 3], r'''"\x00\x01\x02\x03"''');
check([0, 1, 2, 3], [$DQ, 0, 1, 2, 3, $DQ], utf8: true);
});
test('line-separator', () {
check([$LS], [$DQ, $BACKSLASH, $u, $2, $0, $2, $8, $DQ]);
check([$LS], [$DQ, $BACKSLASH, $u, $2, $0, $2, $8, $DQ], utf8: true);
});
test('page-separator', () {
check([$PS], [$DQ, $BACKSLASH, $u, $2, $0, $2, $9, $DQ]);
check([$PS], [$DQ, $BACKSLASH, $u, $2, $0, $2, $9, $DQ], utf8: true);
});
test('choose-quotes', () {
check('"', [$SQ, $DQ, $SQ]);
check("'", [$DQ, $SQ, $DQ]);
// Using single quotes saves us one backslash:
check([$DQ, $DQ, $SQ], [$SQ, $DQ, $DQ, $BACKSLASH, $SQ, $SQ]);
check([$DQ, $SQ, $SQ], [$DQ, $BACKSLASH, $DQ, $SQ, $SQ, $DQ]);
});
test('u1234', () {
check('\u1234', [$DQ, $BACKSLASH, $u, $1, $2, $3, $4, $DQ]);
check('\u1234', [$DQ, 0x1234, $DQ], utf8: true);
});
test('u12345', () {
// TODO: ES6 option:
//check([0x12345],
// [$DQ, $BACKSLASH, $u, $LCURLY, $1, $2, $3, $4, $5, $RCURLY, $DQ]);
check([0x12345], r'''"\ud808\udf45"''');
check([
0x12345
], [
$DQ,
$BACKSLASH,
$u,
$d,
$8,
$0,
$8,
$BACKSLASH,
$u,
$d,
$f,
$4,
$5,
$DQ
]);
check([0x12345], [$DQ, 55304, 57157, $DQ], utf8: true);
});
test('unpaired-surrogate', () {
// (0xD834, 0xDD1E) = 0x1D11E
// Strings containing unpaired surrogates must be encoded to prevent
// problems with the utf8 file-level encoding.
check([0xD834], [$DQ, $BACKSLASH, $u, $d, $8, $3, $4, $DQ]);
check([0xD834], [$DQ, $BACKSLASH, $u, $d, $8, $3, $4, $DQ], utf8: true);
check([0xDD1E], [$DQ, $BACKSLASH, $u, $d, $d, $1, $e, $DQ]);
check([0xDD1E], [$DQ, $BACKSLASH, $u, $d, $d, $1, $e, $DQ], utf8: true);
check([0xD834, $A], [$DQ, $BACKSLASH, $u, $d, $8, $3, $4, $A, $DQ]);
check([0xD834, $A], [$DQ, $BACKSLASH, $u, $d, $8, $3, $4, $A, $DQ],
utf8: true);
check([
0xD834,
0xDD1E
], [
$DQ,
$BACKSLASH,
$u,
$d,
$8,
$3,
$4,
$BACKSLASH,
$u,
$d,
$d,
$1,
$e,
$DQ
]);
check([0xD834, 0xDD1E], r'''"\ud834\udd1e"''');
check([0xD834, 0xDD1E], [$DQ, 0xD834, 0xDD1E, $DQ], utf8: true);
});
}