ranges_ext/
test_helper.rs1use crate::RangeOp;
2use core::ops::Range;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct TestRange {
7 pub start: u64,
8 pub end: u64,
9 pub kind: RangeKind,
10 pub overwritable: bool,
11}
12
13impl Default for TestRange {
14 fn default() -> Self {
15 Self {
16 start: 0,
17 end: 0,
18 kind: RangeKind::default(),
19 overwritable: true,
20 }
21 }
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum RangeKind {
26 TypeA,
27 TypeB,
28 TypeC,
29}
30
31impl Default for RangeKind {
32 fn default() -> Self {
33 RangeKind::TypeA
34 }
35}
36
37impl TestRange {
38 pub fn new(start: u64, end: u64, kind: RangeKind) -> Self {
39 Self {
40 start,
41 end,
42 kind,
43 overwritable: true,
44 }
45 }
46
47 pub fn new_with_overwritable(
48 start: u64,
49 end: u64,
50 kind: RangeKind,
51 overwritable: bool,
52 ) -> Self {
53 Self {
54 start,
55 end,
56 kind,
57 overwritable,
58 }
59 }
60}
61
62impl RangeOp for TestRange {
63 type Kind = RangeKind;
64 type Type = u64;
65
66 fn range(&self) -> Range<Self::Type> {
67 self.start..self.end
68 }
69
70 fn kind(&self) -> Self::Kind {
71 self.kind.clone()
72 }
73
74 fn overwritable(&self, _other: &Self) -> bool {
75 self.overwritable
76 }
77
78 fn clone_with_range(&self, range: Range<Self::Type>) -> Self {
79 Self {
80 start: range.start,
81 end: range.end,
82 kind: self.kind.clone(),
83 overwritable: self.overwritable,
84 }
85 }
86}