Skip to content

Commit 3acdd07

Browse files
committed
push
1 parent 4424b57 commit 3acdd07

File tree

3 files changed

+68
-14
lines changed

3 files changed

+68
-14
lines changed

src/device.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ impl PhysicalDevice {
111111
f32::NAN
112112
};
113113

114-
// Initialize common GPUCharacteristics fields.
115114
let mut characteristics = GPUCharacteristics {
116115
memory_pressure,
117116
// Vendor-specific fields start as None.

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ mod tests {
254254

255255
/// For testing purposes we use the Unknown vendor variant.
256256
impl Vendor {
257-
/// For tests we force the vendor to Unknown.
258257
pub fn dummy() -> Self {
259258
Vendor::Unknown
260259
}
@@ -297,24 +296,19 @@ mod tests {
297296
assert_eq!(format_bytes(1024), "1.000 KB");
298297
assert_eq!(format_bytes(1024 * 1024), "1.000 MB");
299298
assert_eq!(format_bytes(1024 * 1024 * 1024), "1.000 GB");
300-
// 1 TB = 1024 GB
301299
assert_eq!(format_bytes(1024 * 1024 * 1024 * 1024), "1.000 TB");
302300
}
303301

304302
#[test]
305303
fn test_get_device_info() {
306304
let device = dummy_physical_device();
307-
// Use a test color (green).
308305
let color = "\x1B[32m";
309306
let info = get_device_info(&device, color);
310-
// Check that we got at least nine lines.
311307
assert!(info.len() >= 9);
312-
// Verify key substrings appear.
313308
assert!(info[0].contains("TestDevice"));
314309
assert!(info[0].contains(device.device_type.name()));
315310
assert!(info[2].contains("0xDEADBEEF"));
316311
assert!(info[2].contains("0xBEEF"));
317-
// Check optional fields are printed correctly.
318312
assert!(info[7].contains("10") || info[7].contains("N/A"));
319313
assert!(info[8].contains("32") || info[8].contains("N/A"));
320314
}

src/vendor.rs

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::ascii_art::*;
22

3-
#[derive(Debug)]
3+
/// Represents a GPU vendor.
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45
pub enum Vendor {
56
AMD = 0x1002,
67
ImgTec = 0x1010,
@@ -24,6 +25,7 @@ pub enum Vendor {
2425
const BLOCK: &str = "\x1B[7m \x1B[0m";
2526

2627
impl Vendor {
28+
/// Returns the vendor-specific ASCII art with color styling applied.
2729
pub fn get_ascii_art(&self) -> Vec<String> {
2830
let art: &[&str] = match self {
2931
Vendor::AMD => AMD,
@@ -34,8 +36,8 @@ impl Vendor {
3436
Vendor::Nvidia => NVIDIA,
3537
Vendor::Microsoft => MICROSOFT,
3638
Vendor::Qualcomm => QUALCOMM,
37-
Vendor::Mesa //=> MESA,
38-
| Vendor::Unknown
39+
Vendor::Mesa => VULKAN,
40+
Vendor::Unknown
3941
| Vendor::ImgTec
4042
| Vendor::VIV
4143
| Vendor::VSI
@@ -49,18 +51,19 @@ impl Vendor {
4951

5052
let mut modified_art: Vec<String> = art.iter().map(|&line| line.to_string()).collect();
5153

52-
for (char, style) in CHARS.iter().zip(styles.iter()) {
54+
for (symbol, style) in CHARS.iter().zip(styles.iter()) {
5355
if !style.is_empty() {
5456
modified_art = modified_art
5557
.iter()
56-
.map(|line| line.replace(*char, &format!("{}{}", style, BLOCK)))
58+
.map(|line| line.replace(*symbol, &format!("{}{}", style, BLOCK)))
5759
.collect();
5860
}
5961
}
6062

6163
modified_art
6264
}
6365

66+
/// Returns an array of style strings associated with the vendor.
6467
pub const fn get_styles(&self) -> [&str; LUT_SIZE] {
6568
match self {
6669
Vendor::AMD => AMD_STYLE,
@@ -71,8 +74,8 @@ impl Vendor {
7174
Vendor::Nvidia => NVIDIA_STYLE,
7275
Vendor::Microsoft => MICROSOFT_STYLE,
7376
Vendor::Qualcomm => QUALCOMM_STYLE,
74-
Vendor::Mesa //=> MESA_STYLE,
75-
| Vendor::Unknown
77+
Vendor::Mesa => VULKAN_STYLE,
78+
Vendor::Unknown
7679
| Vendor::ImgTec
7780
| Vendor::VIV
7881
| Vendor::VSI
@@ -83,6 +86,7 @@ impl Vendor {
8386
}
8487
}
8588

89+
/// Returns a human-readable name for the vendor.
8690
pub fn name(&self) -> &'static str {
8791
match self {
8892
Vendor::AMD => "AMD",
@@ -105,6 +109,7 @@ impl Vendor {
105109
}
106110
}
107111

112+
/// Constructs a Vendor from a vendor ID, if recognized.
108113
pub fn from_vendor_id(id: u32) -> Option<Self> {
109114
match id {
110115
0x1002 => Some(Vendor::AMD),
@@ -134,3 +139,59 @@ impl From<Vendor> for u32 {
134139
v as u32
135140
}
136141
}
142+
143+
/// Allows a vendor to be printed using its human‑readable name.
144+
impl std::fmt::Display for Vendor {
145+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146+
write!(f, "{}", self.name())
147+
}
148+
}
149+
150+
#[cfg(test)]
151+
mod tests {
152+
use super::*;
153+
154+
#[test]
155+
fn test_from_vendor_id() {
156+
assert_eq!(Vendor::from_vendor_id(0x1002), Some(Vendor::AMD));
157+
assert_eq!(Vendor::from_vendor_id(0x1010), Some(Vendor::ImgTec));
158+
assert_eq!(Vendor::from_vendor_id(0x10DE), Some(Vendor::Nvidia));
159+
assert_eq!(Vendor::from_vendor_id(0x9999), None);
160+
}
161+
162+
#[test]
163+
fn test_name() {
164+
assert_eq!(Vendor::AMD.name(), "AMD");
165+
assert_eq!(Vendor::Apple.name(), "Apple");
166+
assert_eq!(Vendor::Intel.name(), "Intel");
167+
assert_eq!(Vendor::Unknown.name(), "Unknown");
168+
}
169+
170+
#[test]
171+
fn test_display() {
172+
let vendor = Vendor::Nvidia;
173+
let s = format!("{}", vendor);
174+
assert_eq!(s, vendor.name());
175+
}
176+
177+
#[test]
178+
fn test_get_styles_length() {
179+
let vendor = Vendor::AMD;
180+
let styles = vendor.get_styles();
181+
assert_eq!(styles.len(), crate::ascii_art::LUT_SIZE);
182+
}
183+
184+
#[test]
185+
fn test_get_ascii_art() {
186+
let vendor = Vendor::AMD;
187+
let art = vendor.get_ascii_art();
188+
assert!(!art.is_empty(), "ASCII art should not be empty");
189+
190+
let styles = vendor.get_styles();
191+
let non_empty_style = styles.iter().any(|s| !s.is_empty());
192+
if non_empty_style {
193+
let block_found = art.iter().any(|line| line.contains(BLOCK));
194+
assert!(block_found, "Styled block should appear in ASCII art lines");
195+
}
196+
}
197+
}

0 commit comments

Comments
 (0)