stern4rust/finding/model/test_file_item.rs
1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5use crate::finding::model::section::Section;
6
7// One top-level item, with the lines it occupies.
8//
9// first_line is the start of the item's whole block, comments included: a
10// comment introducing a test belongs to that test, so the blank line before the
11// comment is the separator and the comment itself is not a gap.
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct TestFileItem {
14 pub section: Section,
15 pub name: String,
16 pub first_line: usize,
17 pub last_line: usize,
18}
19
20impl TestFileItem {
21 pub fn new(section: Section, name: String, first_line: usize, last_line: usize) -> Self {
22 Self {
23 section,
24 name,
25 first_line,
26 last_line,
27 }
28 }
29
30 // Case-insensitive, because a constant is SHOUTED and a function is not, and
31 // sorting them by byte value would put every constant before every helper
32 // for reasons that have nothing to do with the alphabet.
33 pub fn sort_key(&self) -> String {
34 self.name.to_lowercase()
35 }
36}