Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements related to databake::test_bake!() #4182

Merged
merged 9 commits into from
Oct 20, 2023
6 changes: 3 additions & 3 deletions components/list/src/provider/serde_dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ mod test {
}

#[test]
#[ignore] // https://github.com/rust-lang/rust/issues/98906
fn databake() {
// This is the DFA for ".*"
databake::test_bake!(
SerdeDFA,
const: unsafe { crate::provider::SerdeDFA::from_dfa_bytes_unchecked(if cfg!(target_endian = "little") {
b"foo" // TODO: set this when activating the test
b"rust-regex-automata-dfa-sparse\0\0\xFF\xFE\0\0\x02\0\0\0\0\0\0\0\x0E\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\x01\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x06\x06\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x08\t\t\t\t\t\t\t\t\t\t\t\t\n\x0B\x0B\x0C\r\r\r\x0E\x0F\x0F\x0F\x0F\x0F\x0F\x0F\x0F\x0F\x0F\x0F\x98\x01\0\0\x01\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x0E\x80\0\0\x01\x01\x02\x02\x03\x06\x07\x07\x08\x08\t\t\n\n\x0B\x0B\x0C\x0C\r\r\x0E\x0E\x0F\x0F\0\0\x12\0\0\0q\0\0\0\x12\0\0\0q\0\0\0\x82\0\0\0\x99\0\0\0\xB0\0\0\0\xC7\0\0\0\xB0\0\0\0\xDE\0\0\0\xF5\0\0\0\x0C\x01\0\0q\0\0\0q\0\0\0\x01\0\0\0\0\0\0\0\0\x01\x80\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x03\x05\0\0#\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x05\x05\0\0\x89\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x03\x05\0\0\x89\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x03\x04\0\0\x89\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x04\x05\0\0z\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x03\x05\0\0z\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x02\x80\x03\x03\0\0z\x01\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\x0E\0\0\0\x01\x01\x02\x02\x03\x06\x07\x07\x08\x08\t\t\n\n\x0B\x0B\x0C\x0C\r\r\x0E\x0E\x0F\x0F\0\0\x12\0\0\0q\0\0\0\x12\0\0\0q\0\0\0\x82\0\0\0\x99\0\0\0\xB0\0\0\0\xC7\0\0\0\xB0\0\0\0\xDE\0\0\0\xF5\0\0\0\x0C\x01\0\0q\0\0\0q\0\0\0\0\x02\0\x03\x05\0\0\x89\x01\0\0\0\0\0\0\0\x02\0\x03\x05\0\0#\x01\0\0\0\0\0\0\0\x04\0\0\0\0\0\0\0#\x01\0\0#\x01\0\0#\x01\0\0#\x01\0\0#\x01\0\0\t\0\0\0\x12\0\0\0\x0C\x01\0\0\0\0\0\0\0\0\0\0#\x01\0\0#\x01\0\0"
} else {
b"bar" // TODO: set this when activating the test
b"rust-regex-automata-dfa-sparse\0\0\0\0\xFE\xFF\0\0\0\x02\0\0\0\0\0\0\0\x0E\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\x01\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x06\x06\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\x08\t\t\t\t\t\t\t\t\t\t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\0\0\0\0\0\0\0\0\0\x04\0\0\0\0#\x01\0\0#\x01\0\0#\x01\0\0#\x01\0\0\0\0\x01#\0\0\0\t\0\0\0\x12\0\0\x01\x0C\0\0\0\0\0\0\0\0\0\0\x01#\0\0\x01#"
})},
icu_list
);
Expand Down
1 change: 0 additions & 1 deletion experimental/zerotrie/tests/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ struct DeriveTest_ZeroTrieExtendedCapacity_ZeroVec<'data> {
}

#[test]
#[ignore] // https://github.com/rust-lang/rust/issues/98906
#[cfg(all(feature = "databake", feature = "alloc"))]
fn bake_ZeroTrieExtendedCapacity_ZeroVec() {
use databake::*;
Expand Down
2 changes: 1 addition & 1 deletion utils/databake/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions utils/databake/derive/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct GenericsExample<T> {
fn test_generics_example() {
test_bake!(
GenericsExample<isize>,
const: crate::GenericsExample { x: 17, y: 100isize },
const: crate::GenericsExample { x: 17u32, y: 100isize },
test
);
}
Expand All @@ -49,15 +49,14 @@ pub struct CowExample<'a> {
}

#[test]
#[ignore] // https://github.com/rust-lang/rust/issues/98906
fn test_cow_example() {
test_bake!(
CowExample<'static>,
const: CowExample {
const: crate::CowExample {
x: 17u8,
y: "foo",
z: alloc::borrow::Cow::Borrowed("bar"),
w: alloc::borrow::Cow::Borrowed(&[1u8, 2u8, 3u8, ]),
w: alloc::borrow::Cow::Borrowed(b"\x01\x02\x03"),
},
test
);
Expand Down
12 changes: 12 additions & 0 deletions utils/databake/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ fn cow() {
const: alloc::borrow::Cow::Borrowed("hi"),
alloc
);
assert_eq!(
Bake::bake(
&alloc::borrow::Cow::<'static, str>::Borrowed("hi"),
&Default::default(),
)
.to_string(),
Bake::bake(
&alloc::borrow::Cow::<'static, str>::Owned("hi".to_owned()),
&Default::default(),
)
.to_string(),
);
}

impl<T> Bake for Vec<T>
Expand Down
2 changes: 1 addition & 1 deletion utils/databake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! let data = [Some((18, Cow::Borrowed("hi")))];
//! assert_eq!(
//! data.bake(&Default::default()).to_string(),
//! r#"[Some ((18i32 , alloc :: borrow :: Cow :: Borrowed ("hi") ,)) ,]"#,
//! r#"[Some ((18i32 , alloc :: borrow :: Cow :: Borrowed ("hi")))]"#,
//! );
//! ```
//!
Expand Down
61 changes: 42 additions & 19 deletions utils/databake/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ where
}
let data = self.iter().map(|d| d.bake(ctx));
quote! {
[#(#data,)*]
[#(#data),*]
}
}
}
Expand All @@ -101,10 +101,17 @@ fn byte_string(bytes: &[u8]) -> TokenStream {
#[test]
fn slice() {
// Cannot use test_bake! as it's not possible to write a closed slice expression (&[1] has type &[usize; 1])
let slice: &[bool] = &[];
assert_eq!(Bake::bake(&slice, &Default::default()).to_string(), "& []");
let slice: &[bool] = &[true];
assert_eq!(
Bake::bake(&slice, &Default::default()).to_string(),
"& [true]",
);
let slice: &[bool] = &[true, false];
assert_eq!(
Bake::bake(&slice, &Default::default()).to_string(),
"& [true , false ,]",
"& [true , false]",
);
}

Expand All @@ -119,14 +126,17 @@ where

#[test]
fn array() {
// https://github.com/rust-lang/rust/issues/98906
// test_bake!(
// &[bool; 2],
// const: &[true, false,]
// );
assert_eq!(
[true, false].bake(&Default::default()).to_string(),
"[true , false ,]",
test_bake!(
&[bool; 0],
const: &[]
);
test_bake!(
&[bool; 1],
const: &[true]
);
test_bake!(
&[bool; 2],
const: &[true, false]
);
}

Expand Down Expand Up @@ -193,6 +203,16 @@ fn result() {
}

macro_rules! tuple {
($ty:ident, $ident:ident) => {
impl<$ty> Bake for ($ty,) where $ty: Bake {
fn bake(&self, ctx: &CrateEnv) -> TokenStream {
let $ident = self.0.bake(ctx);
quote! {
(#$ident,)
}
}
}
};
($($ty:ident, $ident:ident),*) => {
impl<$($ty),*> Bake for ($($ty,)*) where $($ty: Bake),* {
fn bake(&self, _ctx: &CrateEnv) -> TokenStream {
Expand All @@ -201,7 +221,7 @@ macro_rules! tuple {
let $ident = $ident.bake(_ctx);
)*
quote! {
($(#$ident,)*)
($(#$ident),*)
}
}
}
Expand All @@ -222,13 +242,16 @@ tuple!(A, a, B, b, C, c, D, d, E, e, F, f, G, g, H, h, I, i, J, j);

#[test]
fn tuple() {
// https://github.com/rust-lang/rust/issues/98906
// test_bake!(
// (u8, i8),
// const: (0u8, 0i8,)
// );
assert_eq!(
(0u8, 0i8).bake(&Default::default()).to_string(),
"(0u8 , 0i8 ,)",
test_bake!(
(),
const: ()
);
test_bake!(
(u8,),
const: (0u8,)
);
test_bake!(
(u8, i8),
const: (0u8, 0i8)
);
}
4 changes: 1 addition & 3 deletions utils/zerovec/src/yoke_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,11 @@ mod test {
}

#[test]
#[ignore] // https://github.com/rust-lang/rust/issues/98906
fn bake_FlexZeroVec() {
test_bake!(
DeriveTest_FlexZeroVec<'static>,
crate::yoke_impls::test::DeriveTest_FlexZeroVec {
_data: unsafe { crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(b"\x01") }
.as_flexzerovec(),
_data: crate::vecs::FlexZeroVec::new(),
},
zerovec,
);
Expand Down