/
nv-lang
/
nova
Обзор
Документация
Войти
/
nv-lang
/
nova
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
std/src/net/error_test.nv
72 строки
3 KB
Evgeniy Golovin
migrate(consume-a): std/src/net/*_test.nv — Ok(consume x) на TcpStream/TcpListener
20 июл 2026, 00:13
20 июл 2026, 00:13
0d058fc
Код
Авторство
О чём код?
// SPDX-License-Identifier: MIT OR Apache-2.0 // Plan 182 Ф.1 (migrated from nova_tests/plan91_15: net_error_to_str.nv, // net_connection_reset.nv, net_permission_denied.nv) — NetError @to_str() // renders each variant (D302). Pure: no network, no effects, except the last // test which does one real (OS-dependent) privileged bind to prove the // classification path never panics or yields a raw string. module std.net test "to_str — nullary variants" { ro refused = NetError.ConnectionRefused assert(refused.to_str() == "connection refused") ro in_use = NetError.AddressInUse assert(in_use.to_str() == "address already in use") ro not_avail = NetError.AddressNotAvailable assert(not_avail.to_str() == "address not available") ro nf = NetError.NotFound assert(nf.to_str() == "not found") ro eof = NetError.Eof assert(eof.to_str() == "end of file") ro closed = NetError.Closed assert(closed.to_str() == "connection closed") ro cancelled = NetError.Cancelled assert(cancelled.to_str() == "operation cancelled") ro timed = NetError.TimedOut assert(timed.to_str() == "operation timed out") ro pipe = NetError.BrokenPipe assert(pipe.to_str() == "broken pipe") ro reset = NetError.ConnectionReset assert(reset.to_str() == "connection reset by peer") ro perm = NetError.PermissionDenied assert(perm.to_str() == "permission denied") ro bad_port = NetError.InvalidPort assert(bad_port.to_str() == "invalid port") } test "to_str — payload variants" { ro io = NetError.IoError("disk gone") assert(io.to_str() == "disk gone") ro bad_addr = NetError.InvalidAddr("1.2.3") assert(bad_addr.to_str() == "invalid address: 1.2.3") } test "ConnectionReset is distinct from BrokenPipe" { // Distinct rendering proves they are separate variants (reset does not // alias BrokenPipe). ro reset = NetError.ConnectionReset ro pipe = NetError.BrokenPipe assert(reset.to_str() != pipe.to_str()) } test "bind result is always classified (no panic, typed error) _slow" { with Net = real_net() { // Port 1 is privileged on Unix (would yield PermissionDenied as non-root); // on Windows the bind typically succeeds. Either way the Result must be a // well-formed Ok/Err with a typed NetError — never a panic or raw string. ro r = TcpListener.bind(SocketAddr.loopback(1)) ro ok = match r { Ok(consume l) => { l.close() true } Err(e) => { // Whatever the OS reported, it must be a typed variant; render it // to confirm to_str() is total over the new variants. ro _msg = e.to_str() true } } assert(ok) } }