Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

erlang term format

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jul 14, 2026, 12:57 PM +0100) commit e7483e78 parent 52ed981e change-id vnvmopvw
+516 -1
+9
Cargo.lock
··· 864 864 checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 865 865 866 866 [[package]] 867 + name = "erlang-term-format" 868 + version = "1.0.0" 869 + dependencies = [ 870 + "num-bigint", 871 + "num-traits", 872 + "pretty_assertions", 873 + ] 874 + 875 + [[package]] 867 876 name = "errno" 868 877 version = "0.3.8" 869 878 source = "registry+https://github.com/rust-lang/crates.io-index"
+2
Cargo.toml
··· 17 17 "hexpm", 18 18 "pretty-arena", 19 19 "format", 20 + "erlang-term-format", 20 21 ] 21 22 22 23 # common dependencies ··· 81 82 ignore = "0" 82 83 # Parsing of arbitrary width int values 83 84 num-bigint = { version = "0.4.6", features = ["serde"] } 85 + num-traits = "0.2.19" 84 86 # Unicode grapheme traversal 85 87 unicode-segmentation = "1.13.2" 86 88 # Checksums
+1 -1
compiler-core/Cargo.toml
··· 37 37 id-arena = "2" 38 38 # Bijective (bi-directional) hashmap 39 39 bimap = { version = "0.6.3", features = ["serde"] } 40 - num-traits = "0.2.19" 41 40 # Encryption 42 41 age = { version = "0.11", features = ["armor"] } 43 42 radix_trie = "0.3" ··· 50 49 indexmap = "2.12.1" 51 50 52 51 num-bigint.workspace = true 52 + num-traits.workspace = true 53 53 async-trait.workspace = true 54 54 base16.workspace = true 55 55 camino = { workspace = true, features = ["serde1"] }
+11
erlang-term-format/Cargo.toml
··· 1 + [package] 2 + name = "erlang-term-format" 3 + version = "1.0.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + num-bigint.workspace = true 8 + num-traits.workspace = true 9 + 10 + [dev-dependencies] 11 + pretty_assertions.workspace = true
+493
erlang-term-format/src/lib.rs
··· 1 + use num_bigint::{BigInt, Sign}; 2 + 3 + #[cfg(test)] 4 + #[macro_use] 5 + extern crate pretty_assertions; 6 + 7 + /// A data structure used to encode values into the Erlang Term Format: 8 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html. 9 + /// 10 + /// Hello!! 11 + /// 12 + pub struct Etf { 13 + bytes: Vec<u8>, 14 + } 15 + 16 + #[must_use] 17 + pub struct List { 18 + size_index: usize, 19 + used: bool, 20 + } 21 + 22 + impl Drop for List { 23 + fn drop(&mut self) { 24 + assert!(self.used, "list not closed"); 25 + } 26 + } 27 + 28 + impl Etf { 29 + pub fn new() -> Self { 30 + Self { bytes: vec![131] } 31 + } 32 + 33 + /// Get the binary representation of the data structure built so far. 34 + pub fn into_vec(self) -> Vec<u8> { 35 + self.bytes 36 + } 37 + 38 + fn push(&mut self, byte: u8) { 39 + self.bytes.push(byte); 40 + } 41 + 42 + fn extend(&mut self, bytes: impl IntoIterator<Item = u8>) { 43 + self.bytes.extend(bytes); 44 + } 45 + 46 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#small_integer_ext 47 + fn small_integer(&mut self, value: u8) { 48 + self.push(97); 49 + self.push(value); 50 + } 51 + 52 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#integer_ext 53 + fn integer(&mut self, value: i32) { 54 + self.push(98); 55 + self.extend(value.to_be_bytes()); 56 + } 57 + 58 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#new_float_ext 59 + fn new_float(&mut self, value: f64) { 60 + self.push(70); 61 + self.extend(value.to_be_bytes()); 62 + } 63 + 64 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#small_tuple_ext 65 + pub fn small_tuple(&mut self, arity: u8) { 66 + self.push(104); 67 + self.push(arity); 68 + } 69 + 70 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#large_tuple_ext 71 + pub fn large_tuple(&mut self, arity: u32) { 72 + self.push(105); 73 + self.extend(arity.to_be_bytes()); 74 + } 75 + 76 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#nil_ext 77 + fn nil(&mut self) { 78 + self.push(106); 79 + } 80 + 81 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#list_ext 82 + fn start_list(&mut self) -> List { 83 + self.push(108); 84 + let size_index = self.bytes.len(); 85 + self.push(0); 86 + self.push(0); 87 + self.push(0); 88 + self.push(0); 89 + List { 90 + size_index, 91 + used: false, 92 + } 93 + } 94 + 95 + fn end_list(&mut self, mut list: List, items: u32) { 96 + self.nil(); 97 + self.bytes[list.size_index..list.size_index + 4].copy_from_slice(&items.to_be_bytes()); 98 + list.used = true; 99 + } 100 + 101 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#binary_ext 102 + fn binary(&mut self, bytes: Vec<u8>) { 103 + self.push(109); 104 + self.extend((bytes.len() as u32).to_be_bytes()); 105 + self.extend(bytes); 106 + } 107 + 108 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#small_big_ext 109 + fn small_big(&mut self, number: BigInt) { 110 + let (sign, bytes) = number.to_bytes_le(); 111 + self.push(110); 112 + self.push(bytes.len() as u8); 113 + match sign { 114 + Sign::NoSign | Sign::Plus => self.push(0), 115 + Sign::Minus => self.push(1), 116 + } 117 + self.extend(bytes); 118 + } 119 + 120 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#large_big_ext 121 + fn large_big(&mut self, number: BigInt) { 122 + let (sign, bytes) = number.to_bytes_le(); 123 + self.push(111); 124 + self.extend((bytes.len() as u32).to_be_bytes()); 125 + match sign { 126 + Sign::NoSign | Sign::Plus => self.push(0), 127 + Sign::Minus => self.push(1), 128 + } 129 + self.extend(bytes); 130 + } 131 + 132 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#small_atom_utf8_ext 133 + fn small_atom_utf8(&mut self, name: &str) { 134 + self.push(119); 135 + self.push(name.len() as u8); 136 + self.extend(name.bytes()); 137 + } 138 + 139 + /// https://www.erlang.org/doc/apps/erts/erl_ext_dist.html#atom_utf8_ext 140 + fn atom_utf8(&mut self, name: &str) { 141 + self.push(118); 142 + self.extend((name.len() as u16).to_be_bytes()); 143 + self.extend(name.bytes()); 144 + } 145 + } 146 + 147 + #[cfg(test)] 148 + mod tests { 149 + use std::{ops::Neg, str::FromStr}; 150 + 151 + use num_bigint::BigInt; 152 + 153 + use crate::Etf; 154 + 155 + #[test] 156 + fn small_atom() { 157 + let mut etf = Etf::new(); 158 + etf.small_atom_utf8("atom"); 159 + assert_eq!(etf.into_vec(), [131, 119, 4, 97, 116, 111, 109]) 160 + } 161 + 162 + #[test] 163 + fn small_atom_utf8() { 164 + let mut etf = Etf::new(); 165 + etf.small_atom_utf8("ksiąskę"); 166 + assert_eq!( 167 + etf.into_vec(), 168 + [131, 119, 9, 107, 115, 105, 196, 133, 115, 107, 196, 153] 169 + ) 170 + } 171 + 172 + #[test] 173 + fn atom() { 174 + let mut etf = Etf::new(); 175 + etf.atom_utf8(&"ą".repeat(128)); 176 + assert_eq!( 177 + etf.into_vec(), 178 + [ 179 + 131, 118, 1, 0, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 180 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 181 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 182 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 183 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 184 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 185 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 186 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 187 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 188 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 189 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 190 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 191 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 192 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 193 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 194 + 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 133, 196, 195 + 133, 196, 133 196 + ] 197 + ) 198 + } 199 + 200 + #[test] 201 + fn small_integer() { 202 + let mut etf = Etf::new(); 203 + etf.small_integer(1); 204 + assert_eq!(etf.into_vec(), [131, 97, 1]); 205 + } 206 + 207 + #[test] 208 + fn integer() { 209 + let mut etf = Etf::new(); 210 + etf.integer(-2); 211 + assert_eq!(etf.into_vec(), [131, 98, 255, 255, 255, 254]); 212 + } 213 + 214 + #[test] 215 + fn integer_2() { 216 + let mut etf = Etf::new(); 217 + etf.integer(1048576); 218 + assert_eq!(etf.into_vec(), [131, 98, 0, 16, 0, 0]); 219 + } 220 + 221 + #[test] 222 + fn float() { 223 + let mut etf = Etf::new(); 224 + etf.new_float(1.2); 225 + assert_eq!(etf.into_vec(), [131, 70, 63, 243, 51, 51, 51, 51, 51, 51]) 226 + } 227 + 228 + #[test] 229 + fn small_big() { 230 + let mut etf = Etf::new(); 231 + 232 + etf.small_big(BigInt::from(123123123123123123 as i64)); 233 + assert_eq!( 234 + etf.into_vec(), 235 + [131, 110, 8, 0, 179, 243, 99, 1, 212, 107, 181, 1] 236 + ); 237 + } 238 + 239 + #[test] 240 + fn negative_small_big() { 241 + let mut etf = Etf::new(); 242 + etf.small_big(BigInt::from(-123123123123123123 as i64)); 243 + assert_eq!( 244 + etf.into_vec(), 245 + [131, 110, 8, 1, 179, 243, 99, 1, 212, 107, 181, 1] 246 + ); 247 + } 248 + 249 + #[test] 250 + fn empty_list() { 251 + let mut etf = Etf::new(); 252 + etf.nil(); 253 + assert_eq!(etf.into_vec(), [131, 106]); 254 + } 255 + 256 + #[test] 257 + fn proper_list_with_a_single_item() { 258 + let mut etf = Etf::new(); 259 + let list = etf.start_list(); 260 + etf.small_integer(1); 261 + etf.end_list(list, 1); 262 + assert_eq!(etf.into_vec(), [131, 108, 0, 0, 0, 1, 97, 1, 106]) 263 + } 264 + 265 + #[test] 266 + fn proper_list() { 267 + let mut etf = Etf::new(); 268 + let list = etf.start_list(); 269 + etf.small_integer(1); 270 + etf.small_tuple(0); 271 + etf.small_integer(2); 272 + etf.end_list(list, 3); 273 + assert_eq!( 274 + etf.into_vec(), 275 + [131, 108, 0, 0, 0, 3, 97, 1, 104, 0, 97, 2, 106] 276 + ) 277 + } 278 + 279 + #[test] 280 + fn empty_binary() { 281 + let mut etf = Etf::new(); 282 + etf.binary(vec![]); 283 + assert_eq!(etf.into_vec(), [131, 109, 0, 0, 0, 0]) 284 + } 285 + #[test] 286 + fn binary() { 287 + let mut etf = Etf::new(); 288 + etf.binary(vec![1, 2, 3]); 289 + assert_eq!(etf.into_vec(), [131, 109, 0, 0, 0, 3, 1, 2, 3]) 290 + } 291 + 292 + #[test] 293 + fn small_empty_tuple() { 294 + let mut etf = Etf::new(); 295 + etf.small_tuple(0); 296 + assert_eq!(etf.into_vec(), [131, 104, 0]) 297 + } 298 + 299 + #[test] 300 + fn small_single_item_tuple() { 301 + let mut etf = Etf::new(); 302 + etf.small_tuple(1); 303 + etf.small_integer(1); 304 + assert_eq!(etf.into_vec(), [131, 104, 1, 97, 1]) 305 + } 306 + 307 + #[test] 308 + fn small_tuple() { 309 + let mut etf = Etf::new(); 310 + etf.small_tuple(3); 311 + etf.new_float(1.1); 312 + etf.integer(-1); 313 + etf.small_integer(11); 314 + 315 + assert_eq!( 316 + etf.into_vec(), 317 + [ 318 + 131, 104, 3, 70, 63, 241, 153, 153, 153, 153, 153, 154, 98, 255, 255, 255, 255, 97, 319 + 11 320 + ] 321 + ) 322 + } 323 + 324 + #[test] 325 + fn small_nested_tuple() { 326 + let mut etf = Etf::new(); 327 + etf.small_tuple(2); 328 + 329 + etf.small_tuple(2); 330 + etf.small_integer(1); 331 + etf.small_integer(11); 332 + 333 + etf.small_tuple(1); 334 + etf.new_float(1.1); 335 + 336 + assert_eq!( 337 + etf.into_vec(), 338 + [ 339 + 131, 104, 2, 104, 2, 97, 1, 97, 11, 104, 1, 70, 63, 241, 153, 153, 153, 153, 153, 340 + 154 341 + ] 342 + ) 343 + } 344 + 345 + #[test] 346 + fn large_tuple() { 347 + let mut etf = Etf::new(); 348 + etf.large_tuple(500); 349 + for _ in 1..=500 { 350 + etf.small_integer(1); 351 + } 352 + 353 + assert_eq!( 354 + etf.into_vec(), 355 + [ 356 + 131, 105, 0, 0, 1, 244, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 357 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 358 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 359 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 360 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 361 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 362 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 363 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 364 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 365 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 366 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 367 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 368 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 369 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 370 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 371 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 372 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 373 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 374 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 375 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 376 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 377 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 378 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 379 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 380 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 381 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 382 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 383 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 384 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 385 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 386 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 387 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 388 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 389 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 390 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 391 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 392 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 393 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 394 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 395 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 396 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 397 + 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1, 97, 1 398 + ] 399 + ) 400 + } 401 + 402 + #[test] 403 + fn large_big() { 404 + let mut etf = Etf::new(); 405 + etf.large_big(BigInt::from_str(&"1".repeat(1500)).unwrap()); 406 + assert_eq!( 407 + etf.into_vec(), 408 + [ 409 + 131, 111, 0, 0, 2, 111, 0, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 410 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 411 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 412 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 413 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 414 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 415 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 416 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 417 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 418 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 419 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 1, 169, 242, 20, 147, 420 + 190, 32, 128, 194, 36, 247, 163, 33, 20, 52, 44, 99, 21, 192, 66, 245, 84, 128, 97, 421 + 156, 59, 26, 49, 215, 19, 60, 165, 65, 99, 28, 91, 91, 132, 187, 191, 48, 27, 217, 422 + 244, 127, 22, 229, 191, 10, 184, 4, 38, 105, 182, 90, 90, 141, 23, 179, 148, 140, 423 + 187, 169, 145, 218, 132, 199, 136, 139, 1, 228, 120, 218, 220, 103, 20, 164, 155, 424 + 60, 1, 158, 242, 71, 1, 60, 69, 6, 13, 244, 52, 42, 222, 129, 25, 127, 251, 133, 425 + 199, 37, 61, 61, 94, 35, 52, 38, 9, 114, 0, 173, 92, 189, 59, 8, 14, 253, 129, 64, 426 + 238, 18, 222, 214, 221, 45, 236, 250, 62, 255, 237, 241, 149, 145, 143, 93, 41, 2, 427 + 156, 28, 29, 102, 103, 8, 227, 146, 128, 117, 183, 231, 113, 20, 148, 190, 253, 95, 428 + 114, 208, 224, 186, 125, 28, 74, 117, 131, 197, 189, 238, 208, 96, 253, 134, 27, 429 + 108, 58, 63, 97, 183, 248, 49, 174, 205, 42, 129, 196, 241, 71, 237, 83, 136, 127, 430 + 61, 225, 107, 199, 146, 30, 212, 53, 215, 141, 147, 198, 3, 37, 170, 175, 29, 43, 431 + 85, 98, 73, 198, 113, 9, 121, 149, 228, 107, 200, 16, 159, 117, 150, 91, 90, 121, 432 + 11, 5, 27, 25, 110, 69, 194, 57, 21, 91, 173, 149, 40, 5, 126, 101, 113, 247, 14, 433 + 130, 154, 249, 36, 143, 183, 129, 4, 174, 108, 164, 122, 95, 105, 77, 243, 58, 158, 434 + 223, 166, 79, 103, 131, 161, 110, 57, 79, 214, 142, 141, 39, 101, 6, 176, 22, 182, 435 + 89, 247, 229, 80, 244, 24, 62, 101, 128, 174, 253, 86, 233, 138, 130, 115, 157, 80, 436 + 21, 83, 187, 222, 43, 19, 105, 97, 230, 7, 167, 25, 6, 69, 207, 149, 32, 199, 44, 437 + 85, 27, 223, 133, 46, 234, 3, 59, 113, 228, 246, 29, 157, 4, 83, 207, 234, 85, 122, 438 + 148, 64, 125, 49, 48, 123, 226, 213, 154, 212, 102, 6, 154, 91, 67, 242, 232, 99, 439 + 154, 238, 73, 72, 122, 170, 27, 110, 83, 110, 146, 159, 87, 87, 163, 151, 196, 47, 440 + 134, 198, 170, 197, 189, 176, 82, 247, 130, 95, 159, 217, 228, 52, 214, 63, 247, 441 + 169, 152, 216, 23, 182, 142, 26, 218, 248, 47, 161, 238, 180, 122, 54, 239, 38, 95, 442 + 65, 114, 128, 93, 233, 71, 177, 101, 2, 236, 244, 88, 249, 104, 210, 4, 249, 5, 443 + 172, 107, 216, 222, 165, 242, 106, 222, 22, 158, 50, 13 444 + ] 445 + ); 446 + } 447 + 448 + #[test] 449 + fn negative_large_big() { 450 + let mut etf = Etf::new(); 451 + etf.large_big(BigInt::from_str(&"1".repeat(1500)).unwrap().neg()); 452 + assert_eq!( 453 + etf.into_vec(), 454 + [ 455 + 131, 111, 0, 0, 2, 111, 1, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 456 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 457 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 458 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 459 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 460 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 461 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 462 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 463 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 464 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 465 + 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 113, 28, 199, 1, 169, 242, 20, 147, 466 + 190, 32, 128, 194, 36, 247, 163, 33, 20, 52, 44, 99, 21, 192, 66, 245, 84, 128, 97, 467 + 156, 59, 26, 49, 215, 19, 60, 165, 65, 99, 28, 91, 91, 132, 187, 191, 48, 27, 217, 468 + 244, 127, 22, 229, 191, 10, 184, 4, 38, 105, 182, 90, 90, 141, 23, 179, 148, 140, 469 + 187, 169, 145, 218, 132, 199, 136, 139, 1, 228, 120, 218, 220, 103, 20, 164, 155, 470 + 60, 1, 158, 242, 71, 1, 60, 69, 6, 13, 244, 52, 42, 222, 129, 25, 127, 251, 133, 471 + 199, 37, 61, 61, 94, 35, 52, 38, 9, 114, 0, 173, 92, 189, 59, 8, 14, 253, 129, 64, 472 + 238, 18, 222, 214, 221, 45, 236, 250, 62, 255, 237, 241, 149, 145, 143, 93, 41, 2, 473 + 156, 28, 29, 102, 103, 8, 227, 146, 128, 117, 183, 231, 113, 20, 148, 190, 253, 95, 474 + 114, 208, 224, 186, 125, 28, 74, 117, 131, 197, 189, 238, 208, 96, 253, 134, 27, 475 + 108, 58, 63, 97, 183, 248, 49, 174, 205, 42, 129, 196, 241, 71, 237, 83, 136, 127, 476 + 61, 225, 107, 199, 146, 30, 212, 53, 215, 141, 147, 198, 3, 37, 170, 175, 29, 43, 477 + 85, 98, 73, 198, 113, 9, 121, 149, 228, 107, 200, 16, 159, 117, 150, 91, 90, 121, 478 + 11, 5, 27, 25, 110, 69, 194, 57, 21, 91, 173, 149, 40, 5, 126, 101, 113, 247, 14, 479 + 130, 154, 249, 36, 143, 183, 129, 4, 174, 108, 164, 122, 95, 105, 77, 243, 58, 158, 480 + 223, 166, 79, 103, 131, 161, 110, 57, 79, 214, 142, 141, 39, 101, 6, 176, 22, 182, 481 + 89, 247, 229, 80, 244, 24, 62, 101, 128, 174, 253, 86, 233, 138, 130, 115, 157, 80, 482 + 21, 83, 187, 222, 43, 19, 105, 97, 230, 7, 167, 25, 6, 69, 207, 149, 32, 199, 44, 483 + 85, 27, 223, 133, 46, 234, 3, 59, 113, 228, 246, 29, 157, 4, 83, 207, 234, 85, 122, 484 + 148, 64, 125, 49, 48, 123, 226, 213, 154, 212, 102, 6, 154, 91, 67, 242, 232, 99, 485 + 154, 238, 73, 72, 122, 170, 27, 110, 83, 110, 146, 159, 87, 87, 163, 151, 196, 47, 486 + 134, 198, 170, 197, 189, 176, 82, 247, 130, 95, 159, 217, 228, 52, 214, 63, 247, 487 + 169, 152, 216, 23, 182, 142, 26, 218, 248, 47, 161, 238, 180, 122, 54, 239, 38, 95, 488 + 65, 114, 128, 93, 233, 71, 177, 101, 2, 236, 244, 88, 249, 104, 210, 4, 249, 5, 489 + 172, 107, 216, 222, 165, 242, 106, 222, 22, 158, 50, 13 490 + ] 491 + ); 492 + } 493 + }