Skip to content

Commit 4e63e5a

Browse files
committed
test: improve coverage for builtin/bytes.mbt
**Disclaimer:** This PR was generated by an LLM agent as part of an experiment. ## Summary ``` coverage of `builtin/bytes.mbt`: 78.6% -> 100% ```
1 parent 20ccaae commit 4e63e5a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

builtin/bytes_test.mbt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,57 @@ test "fixedarray_byte_blit_from_bytes" {
166166
arr.blit_from_bytes(0, bytes, 0, bytes.length())
167167
inspect!(arr, content="[b'\\x48', b'\\x65', b'\\x6C', b'\\x6C', b'\\x6F']")
168168
}
169+
170+
///|
171+
test "Bytes::op_equal with differing bytes" {
172+
let bytes1 = b"\x01\x02\x03"
173+
let bytes2 = b"\x01\x02\xFF" // Same length as bytes1 but last byte differs
174+
inspect!(bytes1 == bytes2, content="false")
175+
}
176+
177+
///|
178+
test "blit_from_bytesview basic case" {
179+
let arr = FixedArray::make(4, b'\x00')
180+
let view = b"\x01\x02\x03"[1:] // view contains "\x02\x03"
181+
arr.blit_from_bytesview(1, view)
182+
inspect!(arr, content="[b'\\x00', b'\\x02', b'\\x03', b'\\x00']")
183+
}
184+
185+
///|
186+
test "panic FixedArray::set_utf8_char/invalid_code_point" {
187+
let buf = FixedArray::make(4, b'\x00')
188+
// Creating a character with code point greater than 0x10FFFF (1114111)
189+
let invalid_char = Char::from_int(0x110001)
190+
// This should trigger the "Char out of range" panic
191+
let _ = buf.set_utf8_char(0, invalid_char)
192+
193+
}
194+
195+
///|
196+
test "set_utf16be_char with surrogate pairs" {
197+
let buf = FixedArray::make(4, b'\x00')
198+
// Test surrogate pair encoding for a supplementary plane character (U+10437)
199+
let c = '\u{10437}'
200+
let len = buf.set_utf16be_char(0, c)
201+
inspect!(len, content="4")
202+
// Check the generated bytes for correct UTF-16BE encoding
203+
// High surrogate: D801, Low surrogate: DC37
204+
inspect!(buf[0], content="b'\\xD8'")
205+
inspect!(buf[1], content="b'\\x01'")
206+
inspect!(buf[2], content="b'\\xDC'")
207+
inspect!(buf[3], content="b'\\x37'")
208+
}
209+
210+
///|
211+
test "panic set_utf16be_char with out of range code point" {
212+
let buf = FixedArray::make(4, b'\x00')
213+
ignore(buf.set_utf16be_char(0, Char::from_int(0x110000)))
214+
}
215+
216+
///|
217+
test "Bytes::makei with non-positive length" {
218+
let bytes = Bytes::makei(0, fn(_i) { b'\x00' })
219+
inspect!(bytes, content="b\"\"")
220+
let bytes2 = Bytes::makei(-1, fn(_i) { b'\x00' })
221+
inspect!(bytes2, content="b\"\"")
222+
}

0 commit comments

Comments
 (0)