MockMontyPlatform class

A mock implementation of MontyPlatform for testing.

Configure expected return values before calling methods:

final mock = MockMontyPlatform();
mock.runResult = MontyResult(value: 42, usage: usage);
final result = await mock.run('1 + 1');
expect(mock.lastRunCode, '1 + 1');

For start, resume, and resumeWithError, enqueue progress values using enqueueProgress:

mock.enqueueProgress(MontyPending(functionName: 'fetch', arguments: []));
mock.enqueueProgress(MontyComplete(result: result));
Inheritance
Implemented types

Constructors

MockMontyPlatform()
Creates a MockMontyPlatform.

Properties

cancelCalled bool
Whether cancel has been called.
getter/setter pair
handleId int?
The monotonic handle ID for cross-isolate cancel.
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
isDisposed bool
Whether dispose has been called.
getter/setter pair
lastResolveFuturesErrors Map<int, String>?
The errors passed to the most recent resolveFutures call.
no setter
lastResolveFuturesResults Map<int, Object?>?
The results passed to the most recent resolveFutures call.
no setter
lastRestoreData Uint8List?
The snapshot data passed to the most recent restore call.
no setter
lastResumeErrorMessage String?
The error message passed to the most recent resumeWithError call.
no setter
lastResumeReturnValue Object?
The return value passed to the most recent resume call.
no setter
lastRunCode String?
The code passed to the most recent run call.
no setter
lastRunLimits MontyLimits?
The limits passed to the most recent run call.
no setter
lastRunScriptName String?
The script name passed to the most recent run call.
no setter
lastStartCode String?
The code passed to the most recent start call.
no setter
lastStartExternalFunctions List<String>?
The external functions passed to the most recent start call.
no setter
lastStartLimits MontyLimits?
The limits passed to the most recent start call.
no setter
lastStartScriptName String?
The script name passed to the most recent start call.
no setter
mockHandleId int?
The handle ID returned by handleId.
getter/setter pair
resolveFuturesErrorsList List<Map<int, String>?>
Errors passed to resolveFutures, in call order.
final
resolveFuturesResultsList List<Map<int, Object?>>
Results passed to resolveFutures, in call order.
final
restoreDataList List<Uint8List>
Snapshot data passed to restore, in call order.
final
restoreResult MontyPlatform?
The platform instance returned by restore.
getter/setter pair
resumeAsFutureCount int
Call count for resumeAsFuture, in call order.
getter/setter pair
resumeErrorMessages List<String>
Error messages passed to resumeWithError, in call order.
final
resumeReturnValues List<Object?>
Return values passed to resume, in call order.
final
runCodes List<String>
Codes passed to run, in call order.
final
runLimitsList List<MontyLimits?>
Limits passed to run, in call order.
final
runResult MontyResult?
The result returned by run.
getter/setter pair
runScriptNamesList List<String?>
Script names passed to run, in call order.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshotData Uint8List?
The snapshot data returned by snapshot.
getter/setter pair
startCodes List<String>
Codes passed to start, in call order.
final
startExternalFunctionsList List<List<String>?>
External functions passed to start, in call order.
final
startLimitsList List<MontyLimits?>
Limits passed to start, in call order.
final
startScriptNamesList List<String?>
Script names passed to start, in call order.
final

Methods

cancel() Future<void>
Cancels the current execution. Idempotent — safe to call multiple times.
override
dispose() Future<void>
Releases resources held by this interpreter instance.
override
enqueueProgress(MontyProgress progress) → void
Adds a MontyProgress to the FIFO queue consumed by start, resume, resumeWithError, resumeAsFuture, and resolveFutures.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveFutures(Map<int, Object?> results, {Map<int, String>? errors}) Future<MontyProgress>
Resolves pending futures with their results, and optionally errors.
override
restore(Uint8List data) Future<MontyPlatform>
Restores interpreter state from a binary snapshot data.
override
resume(Object? returnValue) Future<MontyProgress>
Resumes a paused execution with the given returnValue.
override
resumeAsFuture() Future<MontyProgress>
Resumes a paused execution by creating a future for the pending call.
override
resumeWithError(String errorMessage) Future<MontyProgress>
Resumes a paused execution by raising an error with errorMessage.
override
run(String code, {MontyLimits? limits, String? scriptName}) Future<MontyResult>
Executes code and returns the result.
override
snapshot() Future<Uint8List>
Captures the current interpreter state as a binary snapshot.
override
start(String code, {List<String>? externalFunctions, MontyLimits? limits, String? scriptName}) Future<MontyProgress>
Starts a multi-step execution of code.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited