/
nv-lang
/
nova
Обзор
Документация
Войти
/
nv-lang
/
nova
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
std/src/encoding/toml_test.nv
139 строк
5 KB
Evgeniy Golovin
195: std/ -> std/src/ (git mv, module-path без изменений)
13 июл 2026, 01:13
13 июл 2026, 01:13
be4fcab
Код
Авторство
О чём код?
// SPDX-License-Identifier: MIT OR Apache-2.0 // std/encoding/toml_test.nv — публичный контракт Toml (TOML 1.0.0 parse). module encoding.toml_test import std.encoding.toml.{Toml, ParseTomlError} test "parse: ключ-значение топ-уровня" { ro v = Toml.parse("name = \"nova\"\nversion = \"0.1.0\"\n") match v { TomlTable(t) => { assert(t.get("name") == Some(TomlStr("nova"))) assert(t.get("version") == Some(TomlStr("0.1.0"))) } _ => assert(false) } } test "parse: integer и float" { ro v = Toml.parse("port = 8080\npi = 3.14\n") match v { TomlTable(t) => { assert(t.get("port") == Some(TomlInt(8080))) assert(t.get("pi") == Some(TomlFloat(3.14))) } _ => assert(false) } } test "parse: bool" { ro v = Toml.parse("debug = true\nprod = false\n") match v { TomlTable(t) => { assert(t.get("debug") == Some(TomlBool(true))) assert(t.get("prod") == Some(TomlBool(false))) } _ => assert(false) } } test "parse: array" { ro v = Toml.parse("ports = [80, 443, 8080]\n") match v { TomlTable(t) => match t.get("ports") { Some(TomlArray(xs)) => { assert(xs.len() == 3) assert(xs[0] == TomlInt(80)) } _ => assert(false) } _ => assert(false) } } test "parse: comments игнорируются" { ro v = Toml.parse("# top comment\nname = \"x\" # inline\n") match v { TomlTable(t) => assert(t.get("name") == Some(TomlStr("x"))) _ => assert(false) } } test "parse: ошибка — незакрытая string" { ro r = with Fail[ParseTomlError] = |e| interrupt Some(e) { ro _ = Toml.parse("k = \"unclosed") None } assert(match r { Some(UnexpectedEof { .. }) => true _ => false }) } // ────────────────────────────────────────────────────────────────────────── // [M-toml-repeated-fail-call-run-fail] regression — repeated calls to a // Fail-effectful parser fn inside ONE `with`-scope. Investigated 2026-07-10: // the mechanism itself (fail-frame push/pop, `with Fail[E]` handler install/ // restore, D65 dispatch) is NOT broken — the original marker's hypothesis // was wrong. The real bugs were (a) `is_bare_key_char`'s multi-line `||` // chain silently miscompiling (see toml.nv) and (b) the retracted // `f64.try_from`/`i64.try_from(str)` numeric-parse surface (also toml.nv). // These positive tests pin the correct behaviour of REPEATED same-scope // Fail-effectful calls so a future regression on the fail-frame mechanism // itself would be caught here, separately from content bugs in the parser. // ────────────────────────────────────────────────────────────────────────── test "repeated Fail-effect calls in one with-scope: 2 successes back to back" { ro r = with Fail[ParseTomlError] = |e| interrupt Some(e) { ro a = Toml.parse("k1 = 1\n") ro b = Toml.parse("k2 = 2\n") match a { TomlTable(ta) => match b { TomlTable(tb) => assert(ta.get("k1") == Some(TomlInt(1)) && tb.get("k2") == Some(TomlInt(2))) _ => assert(false) } _ => assert(false) } None } assert(r == None) } test "repeated Fail-effect calls in one with-scope: success then failure" { ro r = with Fail[ParseTomlError] = |e| interrupt Some(e) { ro _ok = Toml.parse("k1 = 1\n") ro _bad = Toml.parse("k2 = \"unclosed") None } assert(match r { Some(UnexpectedEof { .. }) => true _ => false }) } test "repeated Fail-effect calls: match-on-Result between calls, then a third call" { // First call converted to a `Result` via a local Fail-handler, matched, // THEN a second Fail-effectful call happens in the SAME with-scope — // covers the "match-обработка Result между вызовами" scenario from the // marker's investigation ask. ro final = with Fail[ParseTomlError] = |e| interrupt Err(e) { ro r1 Result[TomlValue, ParseTomlError] = with Fail[ParseTomlError] = |e2| interrupt Err(e2) { Ok(Toml.parse("a = 1\n")) } match r1 { Ok(TomlTable(t1)) => assert(t1.get("a") == Some(TomlInt(1))) _ => assert(false) } // Second, independent Fail-effectful call in the SAME outer scope — // must not be affected by the inner with-scope/handler that already // ran and was torn down above. ro v2 = Toml.parse("b = 2\n") Ok(v2) } match final { Ok(TomlTable(t2)) => assert(t2.get("b") == Some(TomlInt(2))) _ => assert(false) } }