Files
sdk/pkg/analysis_server/test/selection_mixin.dart
T
FMorschel 13e29e24ff [DAS] Starts refactoring tests migration to TestCode markers
Continuing the work to normalize all our tests to use the TestCode markers.

Bug: https://github.com/dart-lang/sdk/issues/60234
Change-Id: I687bc35409b1e37938c60206d07155fcc7ac2ac9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433800
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-07-24 10:03:59 -07:00

41 lines
1.2 KiB
Dart

// Copyright (c) 2025, 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 'abstract_single_unit.dart';
mixin SelectionMixin on AbstractSingleUnitTest {
late int offset;
late int length;
void setPosition(int index) {
if (index < 0 || index >= parsedTestCode.positions.length) {
throw ArgumentError('Index out of bounds for positions.');
}
offset = parsedTestCode.positions[index].offset;
length = 0;
}
void setPositionOrRange(int index) {
if (index < 0) {
throw ArgumentError('Index must be non-negative.');
}
if (parsedTestCode.positions.isNotEmpty) {
setPosition(index);
} else if (parsedTestCode.ranges.isNotEmpty) {
setRange(index);
} else {
throw ArgumentError('Test code must contain a position or range marker.');
}
}
void setRange(int index) {
if (index < 0 || index >= parsedTestCode.ranges.length) {
throw ArgumentError('Index out of bounds for ranges.');
}
var range = parsedTestCode.ranges[index].sourceRange;
offset = range.offset;
length = range.length;
}
}