Skip to content

Commit 515386e

Browse files
committed
Update tests
1 parent a37075b commit 515386e

4 files changed

Lines changed: 127 additions & 9 deletions

File tree

tests/unit/out/refcount/union_cross_arm_cast.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,39 @@ impl Default for anon_0 {
106106
}
107107
}
108108
}
109-
impl ByteRepr for anon_0 {}
109+
impl ByteRepr for anon_0 {
110+
fn byte_size() -> usize {
111+
64
112+
}
113+
fn to_bytes(&self, buf: &mut [u8]) {
114+
buf.copy_from_slice(&self.__bytes.borrow());
115+
}
116+
fn from_bytes(buf: &[u8]) -> Self {
117+
anon_0 {
118+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
119+
}
120+
}
121+
}
110122
#[derive(Default)]
111123
pub struct Container {
112124
pub len: Value<u32>,
113125
pub u: Value<anon_0>,
114126
}
115-
impl ByteRepr for Container {}
127+
impl ByteRepr for Container {
128+
fn byte_size() -> usize {
129+
68
130+
}
131+
fn to_bytes(&self, buf: &mut [u8]) {
132+
(*self.len.borrow()).to_bytes(&mut buf[0..4]);
133+
(*self.u.borrow()).to_bytes(&mut buf[4..68]);
134+
}
135+
fn from_bytes(buf: &[u8]) -> Self {
136+
Self {
137+
len: Rc::new(RefCell::new(<u32>::from_bytes(&buf[0..4]))),
138+
u: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[4..68]))),
139+
}
140+
}
141+
}
116142
pub fn main() {
117143
std::process::exit(main_0());
118144
}

tests/unit/out/refcount/union_nested.rs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,36 @@ impl Default for anon_0 {
6161
}
6262
}
6363
}
64-
impl ByteRepr for anon_0 {}
64+
impl ByteRepr for anon_0 {
65+
fn byte_size() -> usize {
66+
128
67+
}
68+
fn to_bytes(&self, buf: &mut [u8]) {
69+
buf.copy_from_slice(&self.__bytes.borrow());
70+
}
71+
fn from_bytes(buf: &[u8]) -> Self {
72+
anon_0 {
73+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
74+
}
75+
}
76+
}
6577
#[derive(Default)]
6678
pub struct inner {
6779
pub view: Value<anon_0>,
6880
}
69-
impl ByteRepr for inner {}
81+
impl ByteRepr for inner {
82+
fn byte_size() -> usize {
83+
128
84+
}
85+
fn to_bytes(&self, buf: &mut [u8]) {
86+
(*self.view.borrow()).to_bytes(&mut buf[0..128]);
87+
}
88+
fn from_bytes(buf: &[u8]) -> Self {
89+
Self {
90+
view: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[0..128]))),
91+
}
92+
}
93+
}
7094
pub struct anon_1 {
7195
__bytes: Value<Box<[u8]>>,
7296
}
@@ -92,7 +116,19 @@ impl Default for anon_1 {
92116
}
93117
}
94118
}
95-
impl ByteRepr for anon_1 {}
119+
impl ByteRepr for anon_1 {
120+
fn byte_size() -> usize {
121+
128
122+
}
123+
fn to_bytes(&self, buf: &mut [u8]) {
124+
buf.copy_from_slice(&self.__bytes.borrow());
125+
}
126+
fn from_bytes(buf: &[u8]) -> Self {
127+
anon_1 {
128+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
129+
}
130+
}
131+
}
96132
#[derive(Default)]
97133
pub struct Outer {
98134
pub kind: Value<i32>,
@@ -101,7 +137,27 @@ pub struct Outer {
101137
pub len: Value<u32>,
102138
pub body: Value<anon_1>,
103139
}
104-
impl ByteRepr for Outer {}
140+
impl ByteRepr for Outer {
141+
fn byte_size() -> usize {
142+
144
143+
}
144+
fn to_bytes(&self, buf: &mut [u8]) {
145+
(*self.kind.borrow()).to_bytes(&mut buf[0..4]);
146+
(*self.level.borrow()).to_bytes(&mut buf[4..8]);
147+
(*self.variant.borrow()).to_bytes(&mut buf[8..12]);
148+
(*self.len.borrow()).to_bytes(&mut buf[12..16]);
149+
(*self.body.borrow()).to_bytes(&mut buf[16..144]);
150+
}
151+
fn from_bytes(buf: &[u8]) -> Self {
152+
Self {
153+
kind: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
154+
level: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
155+
variant: Rc::new(RefCell::new(<i32>::from_bytes(&buf[8..12]))),
156+
len: Rc::new(RefCell::new(<u32>::from_bytes(&buf[12..16]))),
157+
body: Rc::new(RefCell::new(<anon_1>::from_bytes(&buf[16..144]))),
158+
}
159+
}
160+
}
105161
pub fn main() {
106162
std::process::exit(main_0());
107163
}

tests/unit/out/refcount/union_pointer_pun_address.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,19 @@ fn main_0() -> i32 {
6161
}
6262
}
6363
}
64-
impl ByteRepr for anon_0 {};
64+
impl ByteRepr for anon_0 {
65+
fn byte_size() -> usize {
66+
8
67+
}
68+
fn to_bytes(&self, buf: &mut [u8]) {
69+
buf.copy_from_slice(&self.__bytes.borrow());
70+
}
71+
fn from_bytes(buf: &[u8]) -> Self {
72+
anon_0 {
73+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
74+
}
75+
}
76+
};
6577
let ptr: Value<anon_0> = <Value<anon_0>>::default();
6678
(*ptr.borrow_mut()).to_a().write((a.as_pointer()));
6779
let out: Value<Ptr<node_b>> = Rc::new(RefCell::new(((*ptr.borrow()).to_b().read()).clone()));

tests/unit/out/refcount/union_struct_dual_use.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,36 @@ impl Default for anon_1 {
5858
}
5959
}
6060
}
61-
impl ByteRepr for anon_1 {}
61+
impl ByteRepr for anon_1 {
62+
fn byte_size() -> usize {
63+
16
64+
}
65+
fn to_bytes(&self, buf: &mut [u8]) {
66+
buf.copy_from_slice(&self.__bytes.borrow());
67+
}
68+
fn from_bytes(buf: &[u8]) -> Self {
69+
anon_1 {
70+
__bytes: Rc::new(RefCell::new(Box::from(buf))),
71+
}
72+
}
73+
}
6274
#[derive(Default)]
6375
pub struct Outer {
6476
pub u: Value<anon_1>,
6577
}
66-
impl ByteRepr for Outer {}
78+
impl ByteRepr for Outer {
79+
fn byte_size() -> usize {
80+
16
81+
}
82+
fn to_bytes(&self, buf: &mut [u8]) {
83+
(*self.u.borrow()).to_bytes(&mut buf[0..16]);
84+
}
85+
fn from_bytes(buf: &[u8]) -> Self {
86+
Self {
87+
u: Rc::new(RefCell::new(<anon_1>::from_bytes(&buf[0..16]))),
88+
}
89+
}
90+
}
6791
pub fn main() {
6892
std::process::exit(main_0());
6993
}

0 commit comments

Comments
 (0)