Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-10-29 09:21:10 -05:00
commit defb8fa434
1625 files changed
+43449

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
# Tests of the containers: what they check of what they are asked for, what they
# close of their elements, and what they do where an allocator gives no memory,
# with the helpers of std they lean on.
import std::io;
import system;
import std::testing;
# A byte writer lays words out least significant byte first, and writes over
# what it wrote, as a length known only after what it counts.
@test def byte_writers_lay_out_words_and_lengths(t: &mut tester): void {
var w := byte_writer::new();
w.byte(0xAA);
val at := w.begin_length();
w.u16(0x0201);
w.u64(0x0807060504030201);
w.put_terminated("hi");
w.end_length(at);
t.expects(w.get_u32(at) == 13 && w.get_byte(5) == 0x01 && w.get_byte(6) == 0x02 && w.length == 18);
t.expects(w.align_to(8) == 24 && w.get_byte(23) == 0 && w.get_u64(7) == 0x0807060504030201);
w.set_u16(1, 0xBEEF);
w.set_byte(0, 1);
t.expects(w.view()[1] == 0xEF && w.view()[2] == 0xBE && w.get_byte(0) == 1);
w.zeros(3);
t.expects(w.length == 27 && pair_high(pair_key(5, 6)) == 5 && pair_low(pair_key(5, 6)) == 6);
w.rewind(5);
w.byte(9);
t.expects(w.length == 6 && w.get_byte(5) == 9 && w.get_u32(1) == 0xBEEF);
}