shrinkpath 0.1.1

Smart cross-platform path shortening for CLIs, prompts, and tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//! # shrinkpath
//!
//! Smart, cross-platform path shortening for Rust.
//!
//! Intelligently shortens file paths while preserving the information that matters
//! most: the **filename** (never truncated) and the **user identity** (preserved
//! when possible).
//!
//! ## Quick Start
//!
//! ```
//! use shrinkpath::{shrink_to, shrink_fish};
//!
//! // Hybrid strategy with target length
//! let short = shrink_to("/home/john/projects/rust/myapp/src/lib.rs", 30);
//! assert!(short.len() <= 30);
//! assert!(short.ends_with("lib.rs"));
//!
//! // Fish-style abbreviation (no length target)
//! let fish = shrink_fish("/home/john/projects/rust/myapp/src/lib.rs");
//! assert_eq!(fish, "/h/j/p/r/m/s/lib.rs");
//! ```
//!
//! ## Strategies
//!
//! - **Hybrid** (default): Graduated approach — abbreviates expendable segments first,
//!   then context segments, then collapses runs into `...`, then abbreviates identity.
//! - **Fish**: Abbreviates every directory segment to its first character.
//! - **Ellipsis**: Replaces middle segments with `...`, keeping identity and tail.
//!
//! ## Platform Support
//!
//! Handles Windows (`C:\Users\...`, UNC `\\server\share\...`, `.\...`),
//! macOS (`/Users/...`), and Linux (`/home/...`) paths. Auto-detects the style
//! from the input string, or you can force it with [`PathStyle`].

pub mod path_info;
pub mod platform;
pub mod strategy;

#[cfg(feature = "fs")]
pub mod fs_aware;

pub use platform::PathStyle;
pub use strategy::Strategy;

/// Configuration for path shortening.
#[derive(Debug, Clone)]
pub struct ShrinkOptions {
    /// Target maximum length. The output will be at most this long, unless the
    /// filename itself exceeds it (filenames are never truncated).
    pub max_len: usize,
    /// Shortening strategy.
    pub strategy: Strategy,
    /// Force a specific path style instead of auto-detecting.
    pub path_style: Option<PathStyle>,
    /// Custom ellipsis string. Default: `"..."`.
    pub ellipsis: String,
    /// Number of characters to keep per abbreviated directory segment. Default: 1.
    pub dir_length: usize,
    /// Number of trailing directory segments to keep unabbreviated. Default: 0.
    pub full_length_dirs: usize,
    /// Custom path prefix substitutions applied before shortening.
    /// Each tuple is `(from, to)`: if the path starts with `from`, replace it with `to`.
    /// Sorted by longest match first at application time.
    pub mapped_locations: Vec<(String, String)>,
    /// Segment names that should never be abbreviated, regardless of strategy.
    pub anchors: Vec<String>,
}

impl ShrinkOptions {
    /// Create options with sensible defaults: Hybrid strategy, max_len as specified.
    pub fn new(max_len: usize) -> Self {
        ShrinkOptions {
            max_len,
            strategy: Strategy::Hybrid,
            path_style: None,
            ellipsis: "...".to_string(),
            dir_length: 1,
            full_length_dirs: 0,
            mapped_locations: Vec::new(),
            anchors: Vec::new(),
        }
    }

    /// Set the shortening strategy.
    pub fn strategy(mut self, s: Strategy) -> Self {
        self.strategy = s;
        self
    }

    /// Force a specific path style.
    pub fn path_style(mut self, s: PathStyle) -> Self {
        self.path_style = Some(s);
        self
    }

    /// Set a custom ellipsis string.
    pub fn ellipsis(mut self, e: impl Into<String>) -> Self {
        self.ellipsis = e.into();
        self
    }

    /// Set the number of characters to keep per abbreviated directory segment.
    pub fn dir_length(mut self, n: usize) -> Self {
        self.dir_length = n;
        self
    }

    /// Set the number of trailing directory segments to keep unabbreviated.
    pub fn full_length_dirs(mut self, n: usize) -> Self {
        self.full_length_dirs = n;
        self
    }

    /// Add a mapped location: if the path starts with `from`, replace it with `to`.
    pub fn map_location(mut self, from: impl Into<String>, to: impl Into<String>) -> Self {
        self.mapped_locations.push((from.into(), to.into()));
        self
    }

    /// Add an anchor segment name that should never be abbreviated.
    pub fn anchor(mut self, name: impl Into<String>) -> Self {
        self.anchors.push(name.into());
        self
    }
}

/// Metadata about a single component in the shortened path.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SegmentInfo {
    /// The original full text.
    pub original: String,
    /// The shortened text (may equal original if not abbreviated).
    pub shortened: String,
    /// Whether this component was abbreviated.
    pub was_abbreviated: bool,
    /// Whether this is the filename (sacred, always last).
    pub is_filename: bool,
}

/// Result of a shrink operation with metadata.
#[derive(Debug, Clone)]
pub struct ShrinkResult {
    /// The shortened path string.
    pub shortened: String,
    /// Length of the original path.
    pub original_len: usize,
    /// Length of the shortened path.
    pub shortened_len: usize,
    /// Whether the path was actually truncated.
    pub was_truncated: bool,
    /// Detected (or forced) path style.
    pub detected_style: PathStyle,
    /// Per-segment metadata for the shortened path.
    pub segments: Vec<SegmentInfo>,
}

/// Apply mapped location substitutions to a path, returning the transformed path.
/// Sorts by longest `from` prefix first so more specific mappings win.
fn apply_mapped_locations(path: &str, mapped_locations: &[(String, String)]) -> String {
    if mapped_locations.is_empty() {
        return path.to_string();
    }

    // Sort by longest from-prefix first
    let mut sorted: Vec<&(String, String)> = mapped_locations.iter().collect();
    sorted.sort_by(|a, b| b.0.len().cmp(&a.0.len()));

    for (from, to) in sorted {
        if path.starts_with(from.as_str()) {
            let remainder = &path[from.len()..];
            return format!("{to}{remainder}");
        }
    }

    path.to_string()
}

/// Shorten a path using the given options.
pub fn shrink(path: &str, opts: &ShrinkOptions) -> String {
    if path.is_empty() {
        return String::new();
    }

    // Apply mapped locations before parsing
    let path = apply_mapped_locations(path, &opts.mapped_locations);

    let info = path_info::PathInfo::parse(&path, opts.path_style);

    match opts.strategy {
        Strategy::Fish => strategy::fish::shrink_fish(
            &info,
            opts.dir_length,
            opts.full_length_dirs,
            &opts.anchors,
        ),
        Strategy::Ellipsis => {
            strategy::ellipsis::shrink_ellipsis(&info, opts.max_len, &opts.ellipsis)
        }
        Strategy::Hybrid => {
            strategy::hybrid::shrink_hybrid(&info, opts.max_len, &opts.ellipsis, &opts.anchors)
        }
        Strategy::Unique => strategy::unique::shrink_unique(&info, &opts.anchors),
    }
}

/// Shorten a path with detailed result metadata.
pub fn shrink_detailed(path: &str, opts: &ShrinkOptions) -> ShrinkResult {
    if path.is_empty() {
        return ShrinkResult {
            shortened: String::new(),
            original_len: 0,
            shortened_len: 0,
            was_truncated: false,
            detected_style: PathStyle::Unix,
            segments: Vec::new(),
        };
    }

    // Parse the original path (after mapped-location substitution, same as shrink())
    let mapped_path = apply_mapped_locations(path, &opts.mapped_locations);
    let original_info = path_info::PathInfo::parse(&mapped_path, opts.path_style);

    let shortened = shrink(path, opts);

    // Parse the shortened string to extract its segments
    let shortened_info = path_info::PathInfo::parse(&shortened, opts.path_style);

    let segments = build_segment_metadata(&original_info, &shortened_info);

    ShrinkResult {
        original_len: path.len(),
        shortened_len: shortened.len(),
        was_truncated: shortened != path,
        detected_style: original_info.style,
        shortened,
        segments,
    }
}

/// Build per-segment metadata by comparing original and shortened PathInfo.
fn build_segment_metadata(
    original: &path_info::PathInfo,
    shortened: &path_info::PathInfo,
) -> Vec<SegmentInfo> {
    let mut result = Vec::new();

    let orig_seg_count = original.segments.len();
    let short_seg_count = shortened.segments.len();

    if orig_seg_count == short_seg_count {
        // 1-to-1 mapping: Fish, Unique, Hybrid (when no collapse), or no truncation
        for (orig, short) in original.segments.iter().zip(shortened.segments.iter()) {
            result.push(SegmentInfo {
                original: orig.text.clone(),
                shortened: short.text.clone(),
                was_abbreviated: orig.text != short.text,
                is_filename: false,
            });
        }
    } else {
        // Shortened has fewer segments (ellipsis collapse or hybrid collapse).
        // Walk through shortened segments, mapping them back to originals.
        let short_texts: Vec<&str> = shortened.segments.iter().map(|s| s.text.as_str()).collect();

        // Find the ellipsis marker position in shortened segments
        let ellipsis_pos = short_texts
            .iter()
            .position(|t| t.contains("...") || t.contains(".."));

        match ellipsis_pos {
            Some(eidx) => {
                // Segments before ellipsis map to the first eidx original segments
                for i in 0..eidx {
                    if i < orig_seg_count {
                        result.push(SegmentInfo {
                            original: original.segments[i].text.clone(),
                            shortened: shortened.segments[i].text.clone(),
                            was_abbreviated: original.segments[i].text
                                != shortened.segments[i].text,
                            is_filename: false,
                        });
                    }
                }

                // The ellipsis itself represents collapsed segments
                let tail_count = short_seg_count - eidx - 1;
                let collapsed_start = eidx;
                let collapsed_end = orig_seg_count.saturating_sub(tail_count);
                for i in collapsed_start..collapsed_end {
                    result.push(SegmentInfo {
                        original: original.segments[i].text.clone(),
                        shortened: "...".to_string(),
                        was_abbreviated: true,
                        is_filename: false,
                    });
                }

                // Tail segments after ellipsis
                for i in (eidx + 1)..short_seg_count {
                    let orig_idx = orig_seg_count - (short_seg_count - i);
                    if orig_idx < orig_seg_count {
                        result.push(SegmentInfo {
                            original: original.segments[orig_idx].text.clone(),
                            shortened: shortened.segments[i].text.clone(),
                            was_abbreviated: original.segments[orig_idx].text
                                != shortened.segments[i].text,
                            is_filename: false,
                        });
                    }
                }
            }
            None => {
                // No ellipsis marker but different counts — fallback: use shortened as-is
                for seg in &shortened.segments {
                    result.push(SegmentInfo {
                        original: seg.text.clone(),
                        shortened: seg.text.clone(),
                        was_abbreviated: false,
                        is_filename: false,
                    });
                }
            }
        }
    }

    // Add filename segment
    if !original.filename.is_empty() {
        result.push(SegmentInfo {
            original: original.filename.clone(),
            shortened: shortened.filename.clone(),
            was_abbreviated: original.filename != shortened.filename,
            is_filename: true,
        });
    }

    result
}

// ── Convenience functions ────────────────────────────────────────────────────

/// Shorten a path using the Hybrid strategy with a target max length.
pub fn shrink_to(path: &str, max_len: usize) -> String {
    shrink(path, &ShrinkOptions::new(max_len))
}

/// Shorten a path using Fish-style abbreviation (no length target).
pub fn shrink_fish(path: &str) -> String {
    let info = path_info::PathInfo::parse(path, None);
    strategy::fish::shrink_fish(&info, 1, 0, &[])
}

/// Shorten a path using ellipsis with a target max length.
pub fn shrink_ellipsis(path: &str, max_len: usize) -> String {
    shrink(
        path,
        &ShrinkOptions::new(max_len).strategy(Strategy::Ellipsis),
    )
}

/// Shorten a path using unique-prefix disambiguation (no length target).
pub fn shrink_unique(path: &str) -> String {
    shrink(
        path,
        &ShrinkOptions::new(usize::MAX).strategy(Strategy::Unique),
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn convenience_shrink_to() {
        let result = shrink_to("/home/john/projects/rust/myapp/src/lib.rs", 30);
        assert!(result.len() <= 30);
        assert!(result.ends_with("lib.rs"));
    }

    #[test]
    fn convenience_shrink_fish() {
        let result = shrink_fish("/home/john/projects/rust/myapp/src/lib.rs");
        assert_eq!(result, "/h/j/p/r/m/s/lib.rs");
    }

    #[test]
    fn convenience_shrink_ellipsis() {
        let result = shrink_ellipsis("/home/john/projects/rust/myapp/src/lib.rs", 30);
        assert!(result.len() <= 30);
        assert!(result.ends_with("lib.rs"));
        assert!(result.contains("..."));
    }

    #[test]
    fn empty_path() {
        assert_eq!(shrink_to("", 30), "");
    }

    #[test]
    fn root_only() {
        assert_eq!(shrink_to("/", 5), "/");
    }

    #[test]
    fn filename_only() {
        assert_eq!(shrink_to("file.txt", 5), "file.txt");
    }

    #[test]
    fn detailed_result() {
        let result = shrink_detailed(
            "/home/john/projects/rust/myapp/src/lib.rs",
            &ShrinkOptions::new(30),
        );
        assert!(result.was_truncated);
        assert!(result.shortened_len <= 30);
        assert_eq!(result.detected_style, PathStyle::Unix);
    }

    #[test]
    fn detailed_no_truncation() {
        let result = shrink_detailed("/home/user/file.txt", &ShrinkOptions::new(50));
        assert!(!result.was_truncated);
        assert_eq!(result.shortened, "/home/user/file.txt");
    }

    #[test]
    fn custom_ellipsis() {
        let opts = ShrinkOptions::new(25)
            .strategy(Strategy::Ellipsis)
            .ellipsis("..");
        let result = shrink("/home/john/deep/nested/path/to/file.rs", &opts);
        assert!(result.len() <= 25, "got len {}: {}", result.len(), result);
        assert!(
            result.contains(".."),
            "should contain custom ellipsis: {result}"
        );
        assert!(
            !result.contains("..."),
            "should use '..' not '...': {result}"
        );
    }

    #[test]
    fn force_windows_style() {
        let result = shrink_to("C:\\Users\\Admin\\AppData\\Local\\Temp\\file.txt", 30);
        assert!(result.len() <= 30);
        assert!(result.ends_with("file.txt"));
    }

    #[test]
    fn force_path_style() {
        let opts = ShrinkOptions::new(30).path_style(PathStyle::Windows);
        let result = shrink("C:/Users/Admin/AppData/Local/Temp/file.txt", &opts);
        assert!(
            result.contains('\\'),
            "should use windows separators: {result}"
        );
    }

    #[test]
    fn unc_path() {
        let result = shrink_to("\\\\server\\share\\dept\\project\\reports\\q4.xlsx", 35);
        assert!(result.len() <= 35);
        assert!(result.ends_with("q4.xlsx"));
    }

    #[test]
    fn idempotent_on_short_paths() {
        let path = "/home/user/file.txt";
        let result = shrink_to(path, 50);
        assert_eq!(result, path);
    }

    #[test]
    fn cross_platform_windows_on_any_host() {
        // Windows path should be detected and handled regardless of host OS
        let result = shrink_to(
            ".\\Users\\Admin\\AppData\\Local\\Packages\\Microsoft\\file.txt",
            40,
        );
        assert!(result.len() <= 40, "got len {}: {}", result.len(), result);
        assert!(result.ends_with("file.txt"));
        assert!(result.contains('\\'));
    }

    #[test]
    fn dir_length_two() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .dir_length(2);
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert_eq!(result, "/ho/jo/pr/ru/my/sr/lib.rs");
    }

    #[test]
    fn full_length_dirs_one() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .full_length_dirs(1);
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert_eq!(result, "/h/j/p/r/m/src/lib.rs");
    }

    #[test]
    fn full_length_dirs_two() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .full_length_dirs(2);
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert_eq!(result, "/h/j/p/r/myapp/src/lib.rs");
    }

    // ── Mapped locations tests ───────────────────────────────────────────

    #[test]
    fn mapped_location_tilde() {
        let opts = ShrinkOptions::new(50).map_location("/home/john", "~");
        let result = shrink("/home/john/projects/rust/lib.rs", &opts);
        assert_eq!(result, "~/projects/rust/lib.rs");
    }

    #[test]
    fn mapped_location_custom() {
        let opts = ShrinkOptions::new(50).map_location("/home/john/projects", "PROJ:");
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert!(result.starts_with("PROJ:"), "got: {result}");
        assert!(result.ends_with("lib.rs"));
    }

    #[test]
    fn mapped_location_longest_match() {
        let opts = ShrinkOptions::new(50)
            .map_location("/home/john", "~")
            .map_location("/home/john/projects", "PROJ:");
        let result = shrink("/home/john/projects/rust/lib.rs", &opts);
        assert!(
            result.starts_with("PROJ:"),
            "longer match should win: {result}"
        );
    }

    #[test]
    fn mapped_location_no_match() {
        let opts = ShrinkOptions::new(50).map_location("/opt/data", "DATA:");
        let result = shrink("/home/john/file.rs", &opts);
        assert_eq!(result, "/home/john/file.rs");
    }

    #[test]
    fn mapped_location_windows() {
        let opts = ShrinkOptions::new(50).map_location("C:\\Users\\Admin", "~");
        let result = shrink("C:\\Users\\Admin\\Documents\\file.txt", &opts);
        assert!(result.starts_with("~"), "got: {result}");
        assert!(result.ends_with("file.txt"));
    }

    // ── Anchor segments tests ────────────────────────────────────────────

    #[test]
    fn anchor_preserves_segment_fish() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .anchor("src");
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert!(
            result.contains("/src/"),
            "should preserve anchored segment: {result}"
        );
        assert_eq!(result, "/h/j/p/r/m/src/lib.rs");
    }

    #[test]
    fn anchor_multiple() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .anchor("src")
            .anchor("myapp");
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert!(result.contains("myapp"), "got: {result}");
        assert!(result.contains("src"), "got: {result}");
    }

    #[test]
    fn anchor_in_hybrid() {
        let opts = ShrinkOptions::new(35).anchor("src");
        let result = shrink("/home/john/projects/rust/myapp/src/lib.rs", &opts);
        assert!(
            result.contains("src"),
            "anchor should survive hybrid: {result}"
        );
        assert!(result.len() <= 35, "got len {}: {result}", result.len());
    }

    #[test]
    fn anchor_no_match() {
        let opts = ShrinkOptions::new(50)
            .strategy(Strategy::Fish)
            .anchor("nonexistent");
        let result = shrink("/home/john/projects/lib.rs", &opts);
        assert_eq!(result, "/h/j/p/lib.rs");
    }

    #[test]
    fn convenience_shrink_unique() {
        let result = shrink_unique("/home/john/projects/rust/lib.rs");
        assert_eq!(result, "/h/j/p/r/lib.rs");
    }

    // ── Segment metadata tests ──────────────────────────────────────────

    #[test]
    fn segment_metadata_fish() {
        let opts = ShrinkOptions::new(usize::MAX).strategy(Strategy::Fish);
        let result = shrink_detailed("/home/john/projects/lib.rs", &opts);
        assert_eq!(result.segments.len(), 4); // home, john, projects, lib.rs

        assert_eq!(result.segments[0].original, "home");
        assert_eq!(result.segments[0].shortened, "h");
        assert!(result.segments[0].was_abbreviated);
        assert!(!result.segments[0].is_filename);

        assert_eq!(result.segments[1].original, "john");
        assert_eq!(result.segments[1].shortened, "j");

        assert_eq!(result.segments[3].original, "lib.rs");
        assert_eq!(result.segments[3].shortened, "lib.rs");
        assert!(!result.segments[3].was_abbreviated);
        assert!(result.segments[3].is_filename);
    }

    #[test]
    fn segment_metadata_no_truncation() {
        let result = shrink_detailed("/home/user/file.txt", &ShrinkOptions::new(50));
        assert_eq!(result.segments.len(), 3);
        assert!(!result.segments[0].was_abbreviated);
        assert!(!result.segments[1].was_abbreviated);
        assert!(result.segments[2].is_filename);
        assert_eq!(result.segments[2].original, "file.txt");
    }

    #[test]
    fn segment_metadata_filename_only() {
        let result = shrink_detailed("file.txt", &ShrinkOptions::new(50));
        assert_eq!(result.segments.len(), 1);
        assert!(result.segments[0].is_filename);
        assert_eq!(result.segments[0].original, "file.txt");
        assert!(!result.segments[0].was_abbreviated);
    }

    #[test]
    fn segment_metadata_empty() {
        let result = shrink_detailed("", &ShrinkOptions::new(50));
        assert!(result.segments.is_empty());
    }
}