Skip to content

Commit 85df1f6

Browse files
committed
✅ Add overflow tests
1 parent 8de2078 commit 85df1f6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
.vscode

tests/test.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn positive() {
132132
#[bits(3)]
133133
positive: u32,
134134
#[bits(29)]
135-
_p: (),
135+
__: (),
136136
}
137137

138138
let v = MyBitfield::new().with_positive(0);
@@ -150,7 +150,7 @@ fn negative() {
150150
#[bits(3)]
151151
negative: i32,
152152
#[bits(29)]
153-
_p: (),
153+
__: (),
154154
}
155155

156156
let v = MyBitfield::new().with_negative(-3);
@@ -163,6 +163,34 @@ fn negative() {
163163
assert_eq!(v.negative(), -4);
164164
}
165165

166+
#[test]
167+
#[should_panic]
168+
fn negative_pos_overflow() {
169+
#[bitfield(u32)]
170+
struct MyBitfield {
171+
#[bits(3)]
172+
negative: i32,
173+
#[bits(29)]
174+
__: (),
175+
}
176+
177+
MyBitfield::new().with_negative(4);
178+
}
179+
180+
#[test]
181+
#[should_panic]
182+
fn negative_neg_overflow() {
183+
#[bitfield(u32)]
184+
struct MyBitfield {
185+
#[bits(3)]
186+
negative: i32,
187+
#[bits(29)]
188+
__: (),
189+
}
190+
191+
MyBitfield::new().with_negative(-5);
192+
}
193+
166194
#[test]
167195
fn negative_signed() {
168196
#[bitfield(u64)]

0 commit comments

Comments
 (0)