Skip to content

Commit 5783475

Browse files
OttoAllmendingerllm-git
andcommitted
refactor(wasm-utxo): remove unnecessary test module nesting
Simplify the test file structure by removing the redundant tests module, as the file is already within a tests module. Issue: BTC-2652 Co-authored-by: llm-git <[email protected]>
1 parent 4efea55 commit 5783475

File tree

1 file changed

+109
-113
lines changed
  • packages/wasm-utxo/cli/src/format

1 file changed

+109
-113
lines changed
Lines changed: 109 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,110 @@
1-
#[cfg(test)]
2-
mod tests {
3-
use crate::format::fixtures::assert_or_update_fixture;
4-
use crate::node::{Node, Primitive};
5-
use num_bigint::BigInt;
6-
7-
#[test]
8-
fn test_simple_tree() -> std::io::Result<()> {
9-
// Create a simple tree
10-
let child1 = Node::new("name", Primitive::String("Alice".to_string()));
11-
let child2 = Node::new("age", Primitive::U8(30));
12-
let child3 = Node::new("active", Primitive::Boolean(true));
13-
14-
let mut parent = Node::new("person", Primitive::None);
15-
parent.add_child(child1);
16-
parent.add_child(child2);
17-
parent.add_child(child3);
18-
19-
// Check against fixture
20-
assert_or_update_fixture(&parent, "simple_tree")?;
21-
Ok(())
22-
}
23-
24-
#[test]
25-
fn test_complex_tree() -> std::io::Result<()> {
26-
// Create a more complex tree
27-
let address_street = Node::new("street", Primitive::String("123 Main St".to_string()));
28-
let address_city = Node::new("city", Primitive::String("Anytown".to_string()));
29-
let address_zip = Node::new("zip", Primitive::U16(12345));
30-
31-
let mut address = Node::new("address", Primitive::None);
32-
address.add_child(address_street);
33-
address.add_child(address_city);
34-
address.add_child(address_zip);
35-
36-
let phone1 = Node::new("home", Primitive::String("555-1234".to_string()));
37-
let phone2 = Node::new("work", Primitive::String("555-5678".to_string()));
38-
39-
let mut phones = Node::new("phones", Primitive::None);
40-
phones.add_child(phone1);
41-
phones.add_child(phone2);
42-
43-
let account_number = Node::new(
44-
"number",
45-
Primitive::Integer(BigInt::parse_bytes(b"9876543210123456", 10).unwrap()),
46-
);
47-
let account_balance = Node::new("balance", Primitive::I32(5000));
48-
49-
let mut account = Node::new("account", Primitive::None);
50-
account.add_child(account_number);
51-
account.add_child(account_balance);
52-
53-
let name = Node::new("name", Primitive::String("John Doe".to_string()));
54-
let age = Node::new("age", Primitive::U8(35));
55-
56-
let mut person = Node::new("person", Primitive::None);
57-
person.add_child(name);
58-
person.add_child(age);
59-
person.add_child(address);
60-
person.add_child(phones);
61-
person.add_child(account);
62-
63-
// Check against fixture
64-
assert_or_update_fixture(&person, "complex_tree")?;
65-
Ok(())
66-
}
67-
68-
#[test]
69-
fn test_buffer_display() -> std::io::Result<()> {
70-
// Test how binary data is formatted in the tree
71-
let small_buffer = Node::new("small", Primitive::Buffer(vec![1, 2, 3, 4]));
72-
assert_or_update_fixture(&small_buffer, "small_buffer")?;
73-
74-
let large_buffer = Node::new("large", Primitive::Buffer((0..100).collect()));
75-
assert_or_update_fixture(&large_buffer, "large_buffer")?;
76-
77-
Ok(())
78-
}
79-
80-
#[test]
81-
fn test_numeric_types() -> std::io::Result<()> {
82-
// Create a tree with all the numeric types
83-
let mut numbers = Node::new("numbers", Primitive::None);
84-
85-
// Add signed integers
86-
numbers.add_child(Node::new("i8_min", Primitive::I8(i8::MIN)));
87-
numbers.add_child(Node::new("i8_max", Primitive::I8(i8::MAX)));
88-
numbers.add_child(Node::new("i16_min", Primitive::I16(i16::MIN)));
89-
numbers.add_child(Node::new("i16_max", Primitive::I16(i16::MAX)));
90-
numbers.add_child(Node::new("i32_min", Primitive::I32(i32::MIN)));
91-
numbers.add_child(Node::new("i32_max", Primitive::I32(i32::MAX)));
92-
numbers.add_child(Node::new("i64_min", Primitive::I64(i64::MIN)));
93-
numbers.add_child(Node::new("i64_max", Primitive::I64(i64::MAX)));
94-
95-
// Add unsigned integers
96-
numbers.add_child(Node::new("u8_max", Primitive::U8(u8::MAX)));
97-
numbers.add_child(Node::new("u16_max", Primitive::U16(u16::MAX)));
98-
numbers.add_child(Node::new("u32_max", Primitive::U32(u32::MAX)));
99-
numbers.add_child(Node::new("u64_max", Primitive::U64(u64::MAX)));
100-
101-
// Add a big integer
102-
numbers.add_child(Node::new(
103-
"bigint",
104-
Primitive::Integer(
105-
BigInt::parse_bytes(b"12345678901234567890123456789012345678901234567890", 10)
106-
.unwrap(),
107-
),
108-
));
109-
110-
// Check against fixture
111-
assert_or_update_fixture(&numbers, "numeric_types")?;
112-
Ok(())
113-
}
1+
use crate::format::fixtures::assert_or_update_fixture;
2+
use crate::node::{Node, Primitive};
3+
use num_bigint::BigInt;
4+
5+
#[test]
6+
fn test_simple_tree() -> std::io::Result<()> {
7+
// Create a simple tree
8+
let child1 = Node::new("name", Primitive::String("Alice".to_string()));
9+
let child2 = Node::new("age", Primitive::U8(30));
10+
let child3 = Node::new("active", Primitive::Boolean(true));
11+
12+
let mut parent = Node::new("person", Primitive::None);
13+
parent.add_child(child1);
14+
parent.add_child(child2);
15+
parent.add_child(child3);
16+
17+
// Check against fixture
18+
assert_or_update_fixture(&parent, "simple_tree")?;
19+
Ok(())
20+
}
21+
22+
#[test]
23+
fn test_complex_tree() -> std::io::Result<()> {
24+
// Create a more complex tree
25+
let address_street = Node::new("street", Primitive::String("123 Main St".to_string()));
26+
let address_city = Node::new("city", Primitive::String("Anytown".to_string()));
27+
let address_zip = Node::new("zip", Primitive::U16(12345));
28+
29+
let mut address = Node::new("address", Primitive::None);
30+
address.add_child(address_street);
31+
address.add_child(address_city);
32+
address.add_child(address_zip);
33+
34+
let phone1 = Node::new("home", Primitive::String("555-1234".to_string()));
35+
let phone2 = Node::new("work", Primitive::String("555-5678".to_string()));
36+
37+
let mut phones = Node::new("phones", Primitive::None);
38+
phones.add_child(phone1);
39+
phones.add_child(phone2);
40+
41+
let account_number = Node::new(
42+
"number",
43+
Primitive::Integer(BigInt::parse_bytes(b"9876543210123456", 10).unwrap()),
44+
);
45+
let account_balance = Node::new("balance", Primitive::I32(5000));
46+
47+
let mut account = Node::new("account", Primitive::None);
48+
account.add_child(account_number);
49+
account.add_child(account_balance);
50+
51+
let name = Node::new("name", Primitive::String("John Doe".to_string()));
52+
let age = Node::new("age", Primitive::U8(35));
53+
54+
let mut person = Node::new("person", Primitive::None);
55+
person.add_child(name);
56+
person.add_child(age);
57+
person.add_child(address);
58+
person.add_child(phones);
59+
person.add_child(account);
60+
61+
// Check against fixture
62+
assert_or_update_fixture(&person, "complex_tree")?;
63+
Ok(())
64+
}
65+
66+
#[test]
67+
fn test_buffer_display() -> std::io::Result<()> {
68+
// Test how binary data is formatted in the tree
69+
let small_buffer = Node::new("small", Primitive::Buffer(vec![1, 2, 3, 4]));
70+
assert_or_update_fixture(&small_buffer, "small_buffer")?;
71+
72+
let large_buffer = Node::new("large", Primitive::Buffer((0..100).collect()));
73+
assert_or_update_fixture(&large_buffer, "large_buffer")?;
74+
75+
Ok(())
76+
}
77+
78+
#[test]
79+
fn test_numeric_types() -> std::io::Result<()> {
80+
// Create a tree with all the numeric types
81+
let mut numbers = Node::new("numbers", Primitive::None);
82+
83+
// Add signed integers
84+
numbers.add_child(Node::new("i8_min", Primitive::I8(i8::MIN)));
85+
numbers.add_child(Node::new("i8_max", Primitive::I8(i8::MAX)));
86+
numbers.add_child(Node::new("i16_min", Primitive::I16(i16::MIN)));
87+
numbers.add_child(Node::new("i16_max", Primitive::I16(i16::MAX)));
88+
numbers.add_child(Node::new("i32_min", Primitive::I32(i32::MIN)));
89+
numbers.add_child(Node::new("i32_max", Primitive::I32(i32::MAX)));
90+
numbers.add_child(Node::new("i64_min", Primitive::I64(i64::MIN)));
91+
numbers.add_child(Node::new("i64_max", Primitive::I64(i64::MAX)));
92+
93+
// Add unsigned integers
94+
numbers.add_child(Node::new("u8_max", Primitive::U8(u8::MAX)));
95+
numbers.add_child(Node::new("u16_max", Primitive::U16(u16::MAX)));
96+
numbers.add_child(Node::new("u32_max", Primitive::U32(u32::MAX)));
97+
numbers.add_child(Node::new("u64_max", Primitive::U64(u64::MAX)));
98+
99+
// Add a big integer
100+
numbers.add_child(Node::new(
101+
"bigint",
102+
Primitive::Integer(
103+
BigInt::parse_bytes(b"12345678901234567890123456789012345678901234567890", 10).unwrap(),
104+
),
105+
));
106+
107+
// Check against fixture
108+
assert_or_update_fixture(&numbers, "numeric_types")?;
109+
Ok(())
114110
}

0 commit comments

Comments
 (0)