Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions testing/dart/plugin_utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import 'package:test/test.dart';
typedef StringFunction = String Function();
typedef IntFunction = int Function();

@pragma('vm:entry-point', 'get')
String top() => 'top';

@pragma('vm:entry-point')
class Foo {
const Foo();
@pragma('vm:entry-point')
static int getInt() => 1;
@pragma('vm:entry-point')
double getDouble() => 1.0;
}

Expand All @@ -23,22 +27,25 @@ void main() {
final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top)!;
expect(hTop, isNot(0));
expect(PluginUtilities.getCallbackHandle(top), hTop);
final StringFunction topClosure = PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction;
final StringFunction topClosure =
PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction;
expect(topClosure(), 'top');

// Static method callback.
final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt)!;
expect(hGetInt, isNot(0));
expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt);
final IntFunction getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction;
final IntFunction getIntClosure =
PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction;
expect(getIntClosure(), 1);

// Instance method callbacks cannot be looked up.
const Foo foo = Foo();
expect(PluginUtilities.getCallbackHandle(foo.getDouble), isNull);

// Anonymous closures cannot be looked up.
final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables
final Function anon = // ignore: prefer_function_declarations_over_variables
(int a, int b) => a + b;
expect(PluginUtilities.getCallbackHandle(anon), isNull);
});
}
1 change: 1 addition & 0 deletions testing/dart/spawn_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@pragma('vm:entry-point', 'get')
void main() {}

@pragma('vm:entry-point')
Expand Down
Loading