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
//! Bug reproducer for negative number parsing with separator conflict.
//!
//! This test demonstrates a critical issue in the `derive_tools_trivial.rs` example
//! where using `-` as a separator in Display format `"{a}-{b}"` creates parsing
//! ambiguity when values are negative.
//!
//! The issue occurs because the separator character `-` is identical to the
//! negative sign for integers, making it impossible for the `FromStr` parser to
//! correctly parse strings like "-5-10" (should be a=-5, b=10).
//!
//! ## Root Cause
//!
//! The Display format `"{a}-{b}"` uses hyphen `-` as the field separator. When field
//! `b` is negative, the output contains consecutive hyphens (e.g., `5--10` for
//! `Struct1{a:5, b:-10}`), creating parsing ambiguity. The `FromStr` parser cannot
//! distinguish between the separator `-` and the negative sign `-` in `-10`.
//!
//! ## Why Not Caught
//!
//! The original example only tested positive values (`1-3`), missing the edge case
//! of negative numbers. No comprehensive corner case testing was performed before
//! the example was written. The test suite lacked round-trip verification for
//! negative values.
//!
//! ## Fix Applied
//!
//! Changed the separator in `derive_tools_trivial.rs` from `-` to `:` in the Display
//! format attribute: `#[display("{a}:{b}")]`. The colon separator does not conflict
//! with any number representation characters, enabling correct round-trip conversion
//! for all i32 values including negatives.
//!
//! ## Prevention
//!
//! When choosing format separators for Display/FromStr derives:
//! - Avoid characters used in number representation: `-` (negative), `.` (decimal), `e` (scientific)
//! - Prefer unambiguous separators: `:`, `,`, `|`, `_`, or whitespace
//! - Always test round-trip conversion with edge cases: MIN, MAX, negative, zero
//! - Include comprehensive corner case testing before finalizing examples
//!
//! ## Pitfall
//!
//! **Never use number representation characters as format separators.** The hyphen `-`
//! is particularly dangerous as it's both a common separator choice and the negative
//! sign. Always verify round-trip conversion: `value → Display → FromStr → value` for
//! all edge cases including negative values, MIN, MAX, and zero.
use *;
use FromStr;
/// Struct demonstrating the separator conflict issue.
/// Using `-` as separator creates ambiguity with negative number sign.
/// Reproduces bug where `FromStr` fails to parse negative numbers with `-` separator.
///
/// This test documents the expected failure until the example is fixed.
// test_kind: bug_reproducer(example-negative-parsing)
/// Demonstrates the round-trip failure for both negative values.
// test_kind: bug_reproducer(example-negative-parsing)
/// Demonstrates successful round-trip with positive values only.
/// This test shows the format works correctly when no negative signs are involved.