7a83c82b4f
In preparation of a merge with the Dart2Js format in a follow up PR. - Treat default values as passed arguments - `foo(4)` is the same as `foo()` for all intents and purposes for a `foo([int i = 4])`. - Add signatures to lookup, as dart2js forgets them during compilation. - Encode non-constant arguments as `null`, while a `null` passed as an argument is a `NullConstant`. Tested:pkg/vm/test/transformations/record_use_test.dart Change-Id: Ifd2597d8d1b979627fa45fd4736a762031c17216 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415620 Commit-Queue: Moritz Sümmermann <mosum@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Auto-Submit: Moritz Sümmermann <mosum@google.com>
128 lines
3.7 KiB
Dart
128 lines
3.7 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.
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:record_use/record_use_internal.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'test_data.dart';
|
|
|
|
void main() {
|
|
test('All API calls', () {
|
|
expect(
|
|
RecordedUsages.fromJson(
|
|
jsonDecode(recordedUsesJson) as Map<String, Object?>,
|
|
).constArgumentsFor(
|
|
Identifier(
|
|
importUri:
|
|
Uri.parse(
|
|
'file://lib/_internal/js_runtime/lib/js_helper.dart',
|
|
).toString(),
|
|
scope: 'MyClass',
|
|
name: 'get:loadDeferredLibrary',
|
|
),
|
|
'''
|
|
void loadDeferredLibrary(String s, bool b, int i, {required String singer, String? character})''',
|
|
).length,
|
|
2,
|
|
);
|
|
});
|
|
|
|
test('All API instances', () {
|
|
final instance =
|
|
RecordedUsages.fromJson(
|
|
jsonDecode(recordedUsesJson) as Map<String, Object?>,
|
|
)
|
|
.constantsOf(
|
|
Identifier(
|
|
importUri:
|
|
Uri.parse(
|
|
'file://lib/_internal/js_runtime/lib/js_helper.dart',
|
|
).toString(),
|
|
name: 'MyAnnotation',
|
|
),
|
|
)
|
|
.first;
|
|
final instanceMap =
|
|
recordedUses.instancesForDefinition.values
|
|
.expand((usage) => usage)
|
|
.map(
|
|
(instance) => instance.instanceConstant.fields.map(
|
|
(key, constant) => MapEntry(key, constant.toValue()),
|
|
),
|
|
)
|
|
.first;
|
|
for (final entry in instanceMap.entries) {
|
|
expect(instance[entry.key], entry.value);
|
|
}
|
|
});
|
|
|
|
test('Specific API calls', () {
|
|
var arguments =
|
|
RecordedUsages.fromJson(
|
|
jsonDecode(recordedUsesJson) as Map<String, Object?>,
|
|
).constArgumentsFor(
|
|
Identifier(
|
|
importUri:
|
|
Uri.parse(
|
|
'file://lib/_internal/js_runtime/lib/js_helper.dart',
|
|
).toString(),
|
|
scope: 'MyClass',
|
|
name: 'get:loadDeferredLibrary',
|
|
),
|
|
'''
|
|
void loadDeferredLibrary(String s, bool b, int i, {required String freddy, String? leroy})''',
|
|
).toList();
|
|
var (named: named0, positional: positional0) = arguments[0];
|
|
expect(named0, const {'freddy': 'mercury', 'leroy': 'jenkins'});
|
|
expect(positional0, const ['lib_SHA1', false, 1]);
|
|
var (named: named1, positional: positional1) = arguments[1];
|
|
expect(named1, const {'freddy': 0, 'leroy': 'jenkins'});
|
|
expect(positional1, const [
|
|
[
|
|
'camus',
|
|
['einstein', 'insert', false],
|
|
'einstein',
|
|
],
|
|
'lib_SHA1',
|
|
{'key': 99},
|
|
]);
|
|
});
|
|
|
|
test('Specific API instances', () {
|
|
final instance =
|
|
RecordedUsages.fromJson(
|
|
jsonDecode(recordedUsesJson) as Map<String, Object?>,
|
|
)
|
|
.constantsOf(
|
|
Identifier(
|
|
importUri:
|
|
Uri.parse(
|
|
'file://lib/_internal/js_runtime/lib/js_helper.dart',
|
|
).toString(),
|
|
name: 'MyAnnotation',
|
|
),
|
|
)
|
|
.first;
|
|
expect(instance['a'], 42);
|
|
expect(instance['b'], null);
|
|
});
|
|
|
|
test('HasNonConstInstance', () {
|
|
expect(
|
|
RecordedUsages.fromJson(
|
|
jsonDecode(recordedUsesJson2) as Map<String, Object?>,
|
|
).hasNonConstArguments(
|
|
const Identifier(
|
|
importUri:
|
|
'package:drop_dylib_recording/src/drop_dylib_recording.dart',
|
|
name: 'getMathMethod',
|
|
),
|
|
),
|
|
false,
|
|
);
|
|
});
|
|
}
|