iconmate 1.2.1

CLI to fetch icons and save them into your Vite, NextJS, or similar TypeScript project
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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
use std::process::Command;
use tempfile::TempDir;

#[test]
fn test_add_command_creates_folder_and_files() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    // Build the iconmate binary
    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    // Run the iconmate add command
    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--icon",
            "heroicons:heart",
            "--name",
            "Heart",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    // Check that the command executed successfully
    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    // Verify the folder was created
    assert!(test_folder.exists(), "Folder should be created");

    // Verify the files exist
    let index_file = test_folder.join("index.ts");
    let svg_file = test_folder.join("heroicons_heart.svg");

    assert!(index_file.exists(), "index.ts should be created");
    assert!(svg_file.exists(), "heroicons_heart.svg should be created");

    // Verify the content of index.ts
    let index_content = std::fs::read_to_string(&index_file).expect("Failed to read index.ts");

    assert!(
        index_content.contains("export { default as IconHeart } from './heroicons_heart.svg';"),
        "index.ts should contain the correct export statement"
    );

    // Verify the SVG file is not empty and contains SVG content
    let svg_content = std::fs::read_to_string(&svg_file).expect("Failed to read SVG file");

    assert!(!svg_content.is_empty(), "SVG file should not be empty");
    assert!(
        svg_content.contains("<svg"),
        "SVG file should contain SVG tag"
    );
}

#[test]
fn test_add_command_with_existing_folder() {
    // Create a temporary directory and pre-create the target folder
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    // Pre-create the folder
    std::fs::create_dir_all(&test_folder).expect("Failed to create test folder");

    // Create an existing index.ts file
    let existing_index = test_folder.join("index.ts");
    std::fs::write(
        &existing_index,
        "export { default as IconExisting } from './existing.svg';\n",
    )
    .expect("Failed to create existing index.ts");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    // Run the iconmate add command
    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--icon",
            "heroicons:heart",
            "--name",
            "Heart",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    // Check that the command executed successfully
    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    // Verify both old and new exports exist
    let index_content = std::fs::read_to_string(&existing_index).expect("Failed to read index.ts");

    assert!(
        index_content.contains("export { default as IconExisting } from './existing.svg';"),
        "index.ts should still contain the existing export"
    );
    assert!(
        index_content.contains("export { default as IconHeart } from './heroicons_heart.svg';"),
        "index.ts should contain the new export"
    );
}

#[test]
fn test_add_command_appends_after_non_newline_terminated_index() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    std::fs::create_dir_all(&test_folder).expect("Failed to create test folder");

    let existing_index = test_folder.join("index.ts");
    std::fs::write(
        &existing_index,
        "export { default as IconExisting } from './existing.svg';",
    )
    .expect("Failed to create existing index.ts");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Fresh",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let index_content = std::fs::read_to_string(&existing_index).expect("Failed to read index.ts");

    assert!(
        index_content.contains("export { default as IconExisting } from './existing.svg';\n"),
        "existing export should end with a newline before appending"
    );
    assert!(
        index_content.contains("export { default as IconFresh } from './fresh.svg';"),
        "index.ts should contain the new export"
    );
    assert!(
        !index_content.contains("existing.svg';export"),
        "new export should not be concatenated on the same line"
    );
}

#[test]
fn test_add_command_rejects_duplicate_icon() {
    // Test adding the same icon twice now fails on conflict
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    // First add
    let output1 = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Heart",
            "--filename",
            "heart",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute first command");

    assert!(output1.status.success(), "First command should succeed");

    // Second add of the same icon
    let output2 = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Heart",
            "--filename",
            "heart",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute second command");

    assert!(!output2.status.success(), "Second command should fail");
    assert!(
        String::from_utf8_lossy(&output2.stderr).contains("already exists"),
        "stderr should explain export/file conflict"
    );

    // Verify only one export exists
    let index_file = test_folder.join("index.ts");
    let index_content = std::fs::read_to_string(&index_file).expect("Failed to read index.ts");

    let heart_exports = index_content
        .matches("export { default as IconHeart }")
        .count();
    assert_eq!(heart_exports, 1, "Should only have one Heart export");
}

#[test]
fn test_add_command_rejects_duplicate_name_with_different_target() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let first = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Heart",
            "--filename",
            "heart-a",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute first command");
    assert!(first.status.success(), "First command should succeed");

    let second = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Heart",
            "--filename",
            "heart-b",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute second command");

    assert!(
        !second.status.success(),
        "Second command should fail on duplicate export alias"
    );
    assert!(
        String::from_utf8_lossy(&second.stderr).contains("Icon alias"),
        "stderr should mention duplicate alias"
    );

    assert!(!test_folder.join("heart-b.svg").exists());
}

#[test]
fn test_add_command_rejects_duplicate_target_with_different_name() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let first = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Heart",
            "--filename",
            "shared-target",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute first command");
    assert!(first.status.success(), "First command should succeed");

    let second = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "Star",
            "--filename",
            "shared-target",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute second command");

    assert!(
        !second.status.success(),
        "Second command should fail on duplicate export target"
    );
    assert!(
        String::from_utf8_lossy(&second.stderr).contains("Export target"),
        "stderr should mention duplicate export target"
    );

    let index_file = test_folder.join("index.ts");
    let index_content = std::fs::read_to_string(&index_file).expect("Failed to read index.ts");
    assert!(index_content.contains("IconHeart"));
    assert!(!index_content.contains("IconStar"));
}

#[tokio::test]
async fn test_add_command_invalid_icon() {
    // Test with an icon that likely doesn't exist
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--icon",
            "nonexistent:icon",
            "--name",
            "NonExistent",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    // This should fail since the icon doesn't exist
    assert!(
        !output.status.success(),
        "Command should fail for non-existent icon"
    );
}

#[test]
fn test_add_command_preset_empty_svg() {
    // Test using the preset instead of fetching an icon
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "emptysvg",
            "--name",
            "EmptyIcon",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    // Verify the files exist
    let index_file = test_folder.join("index.ts");
    let svg_file = test_folder.join("EmptyIcon.svg");

    assert!(index_file.exists(), "index.ts should be created");
    assert!(svg_file.exists(), "EmptyIcon.svg should be created");

    // Verify the SVG content is the empty SVG template
    let svg_content = std::fs::read_to_string(&svg_file).expect("Failed to read SVG file");

    assert!(
        svg_content.contains(r#"svg xmlns="http://www.w3.org/2000/svg""#),
        "SVG should contain the empty SVG template"
    );
}

#[test]
fn test_add_command_preset_normal_with_icon() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "normal",
            "--icon",
            "heroicons:heart",
            "--name",
            "Heart",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let svg_file = test_folder.join("heroicons_heart.svg");
    assert!(svg_file.exists(), "heroicons_heart.svg should be created");
}

#[test]
fn test_add_command_preset_normal_requires_icon() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            test_folder.to_str().unwrap(),
            "--preset",
            "normal",
            "--name",
            "NoIcon",
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(!output.status.success(), "Command should fail without icon");
    assert!(
        String::from_utf8_lossy(&output.stderr)
            .contains("--icon argument is required when --preset is normal"),
        "stderr should explain normal preset needs an icon"
    );
}

#[test]
fn test_list_command_prints_existing_icons() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");
    std::fs::create_dir_all(&test_folder).expect("Failed to create icons folder");

    let index_file = test_folder.join("index.ts");
    std::fs::write(
        &index_file,
        "export { default as IconHeart } from './heart.svg';\nexport { default as IconStar } from './star.svg';\n",
    )
    .expect("Failed to write index.ts");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");
    let output = Command::new(binary_path)
        .args(["list", "--folder", test_folder.to_str().unwrap()])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("IconHeart\t./heart.svg"),
        "stdout should include IconHeart row"
    );
    assert!(
        stdout.contains("IconStar\t./star.svg"),
        "stdout should include IconStar row"
    );
}

#[test]
fn test_list_command_uses_default_folder_when_no_flag_is_passed() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let default_folder = temp_dir.path().join("src/assets/icons");
    std::fs::create_dir_all(&default_folder).expect("Failed to create icons folder");

    let index_file = default_folder.join("index.ts");
    std::fs::write(
        &index_file,
        "export { default as IconHouse } from './house.svg';\n",
    )
    .expect("Failed to write index.ts");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");
    let output = Command::new(binary_path)
        .args(["list"])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("IconHouse\t./house.svg"),
        "stdout should include icon from default folder"
    );
}

#[test]
fn test_list_command_reports_no_icons_when_index_is_missing() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let test_folder = temp_dir.path().join("src/assets/icons");
    std::fs::create_dir_all(&test_folder).expect("Failed to create icons folder");

    let binary_path = env!("CARGO_BIN_EXE_iconmate");
    let output = Command::new(binary_path)
        .args(["list", "--folder", test_folder.to_str().unwrap()])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Command failed with stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("No icons found in"),
        "stdout should explain that no icons were found"
    );
}

#[test]
fn test_flutter_preset_add_creates_barrel_and_svg() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let icons_folder = temp_dir.path().join("assets/icons");
    let barrel_path = temp_dir.path().join("lib/icons.dart");
    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--preset",
            "flutter",
            "--folder",
            icons_folder.to_str().unwrap(),
            "--icon",
            "heroicons:heart",
            "--flutter-barrel-file",
            barrel_path.to_str().unwrap(),
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Flutter add command failed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(barrel_path.exists(), "lib/icons.dart should be created");
    let contents = std::fs::read_to_string(&barrel_path).expect("read barrel");
    assert!(contents.contains("class AppIcons {"), "barrel has class");
    assert!(
        contents.contains("static const String heart"),
        "barrel has heart entry"
    );
    assert!(
        contents.contains("heroicons_heart.svg"),
        "barrel references the svg file"
    );

    let svg_file = icons_folder.join("heroicons_heart.svg");
    assert!(svg_file.exists(), "SVG file should be written");
}

#[test]
fn test_flutter_project_add_autodetects_and_updates_dart_barrel() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let icons_folder = temp_dir.path().join("assets/icons");
    let barrel_path = temp_dir.path().join("lib/icons.dart");
    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    std::fs::write(
        temp_dir.path().join("pubspec.yaml"),
        "name: repro_app\nversion: 0.1.0\n\nflutter:\n  uses-material-design: true\n",
    )
    .expect("write pubspec");

    let output = Command::new(binary_path)
        .args([
            "add",
            "--folder",
            icons_folder.to_str().unwrap(),
            "--name",
            "Heart",
            "--icon",
            r#"<svg xmlns="http://www.w3.org/2000/svg"></svg>"#,
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Flutter autodetected add should succeed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );
    assert!(barrel_path.exists(), "lib/icons.dart should be created");
    assert!(
        !icons_folder.join("index.ts").exists(),
        "Flutter add should not create a JS index.ts"
    );

    let contents = std::fs::read_to_string(&barrel_path).expect("read barrel");
    assert!(contents.contains("static const String heart"));
    assert!(contents.contains("assets/icons/heart.svg"));

    let sync = Command::new(binary_path)
        .args(["sync", "--folder", icons_folder.to_str().unwrap()])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute sync");

    assert!(
        sync.status.success(),
        "sync should succeed: stderr={}",
        String::from_utf8_lossy(&sync.stderr)
    );
    let stdout = String::from_utf8_lossy(&sync.stdout);
    assert!(
        stdout.contains("Clean — no drift."),
        "sync should be clean after add: got {stdout}"
    );
}

#[test]
fn test_flutter_preset_add_infers_name_from_iconify_id() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let icons_folder = temp_dir.path().join("assets/icons");
    let barrel_path = temp_dir.path().join("lib/icons.dart");
    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    // Note: no --name passed; Flutter preset should infer `chevronRight`
    // from `heroicons:chevron-right`.
    let output = Command::new(binary_path)
        .args([
            "add",
            "--preset",
            "flutter",
            "--folder",
            icons_folder.to_str().unwrap(),
            "--icon",
            "heroicons:chevron-right",
            "--flutter-barrel-file",
            barrel_path.to_str().unwrap(),
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("Failed to execute command");

    assert!(
        output.status.success(),
        "Flutter add should succeed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );

    let contents = std::fs::read_to_string(&barrel_path).expect("read barrel");
    assert!(
        contents.contains("static const String chevronRight"),
        "identifier auto-inferred to lowerCamelCase: got {contents}"
    );
}

#[test]
fn test_flutter_preset_add_uses_collection_prefix_on_collision() {
    let temp_dir = TempDir::new().expect("Failed to create temp directory");
    let icons_folder = temp_dir.path().join("assets/icons");
    let barrel_path = temp_dir.path().join("lib/icons.dart");
    let binary_path = env!("CARGO_BIN_EXE_iconmate");

    // First add: `heart` identifier.
    let first = Command::new(binary_path)
        .args([
            "add",
            "--preset",
            "flutter",
            "--folder",
            icons_folder.to_str().unwrap(),
            "--icon",
            "heroicons:heart",
            "--flutter-barrel-file",
            barrel_path.to_str().unwrap(),
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("first add should run");
    assert!(first.status.success());

    // Second add with the same icon name from a different collection — should
    // fall back to `mdiHeart` because `heart` is taken.
    let second = Command::new(binary_path)
        .args([
            "add",
            "--preset",
            "flutter",
            "--folder",
            icons_folder.to_str().unwrap(),
            "--icon",
            "mdi:heart",
            "--flutter-barrel-file",
            barrel_path.to_str().unwrap(),
        ])
        .current_dir(temp_dir.path())
        .output()
        .expect("second add should run");
    assert!(
        second.status.success(),
        "second add should use fallback identifier: stderr={}",
        String::from_utf8_lossy(&second.stderr)
    );

    let contents = std::fs::read_to_string(&barrel_path).expect("read barrel");
    assert!(contents.contains("static const String heart"));
    assert!(
        contents.contains("static const String mdiHeart"),
        "collision fallback should produce mdiHeart: got {contents}"
    );
}