Skip to content

Commit f37e6b7

Browse files
committed
Add positive test for builder available in const context
1 parent 97b21c6 commit f37e6b7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bitbybit-tests/src/bitfield_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,26 @@ fn default_value_const() {
422422
assert_eq!(t.raw_value, 0xBADCAFE);
423423
}
424424

425+
#[test]
426+
fn builder_available_in_const_context() {
427+
#[bitfield(u16)]
428+
#[derive(Debug)]
429+
pub struct Test {
430+
#[bits(0..=15, rw)]
431+
a: u16,
432+
}
433+
434+
assert_eq!(const { Test::builder().with_a(123).build().raw_value() }, 123);
435+
const {
436+
let raw = Test::builder().with_a(123).build().raw_value();
437+
if raw != 123 {
438+
panic!("builder didn't build the right value `123`");
439+
}
440+
}
441+
const TEST: Test = Test::builder().with_a(123).build();
442+
assert_eq!(TEST.raw_value(), 123);
443+
}
444+
425445
#[test]
426446
fn more_struct_attributes() {
427447
// Test that other attributes can be appended

0 commit comments

Comments
 (0)