From 39ac85c06ea76804be280e15cdddaaa956f7f5d9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 23 Apr 2026 21:48:35 +0300 Subject: [PATCH] v.tests: fix C compilation error (fixes #25787) --- .../options/option_unwrap_as_cast_test.v | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/vlib/v/tests/options/option_unwrap_as_cast_test.v b/vlib/v/tests/options/option_unwrap_as_cast_test.v index a63535256..352901427 100644 --- a/vlib/v/tests/options/option_unwrap_as_cast_test.v +++ b/vlib/v/tests/options/option_unwrap_as_cast_test.v @@ -12,6 +12,48 @@ fn get_opt_int(a int) ?int { return 12 } +struct TestResult { + cols map[string]int + rows []TestRow +} + +struct TestRow { + vals []?string +} + +struct TestDb {} + +struct TestPgConnection { + db TestDb +} + +fn (db TestDb) exec_result(_ string) !TestResult { + return TestResult{ + cols: { + 'present': 0 + 'empty': 1 + 'none': 2 + } + rows: [TestRow{ + vals: [?string('hello'), ?string(''), ?string(none)] + }] + } +} + +fn (c &TestPgConnection) query(q string) ![]map[string]string { + res := c.db.exec_result(q)! + mut rows := []map[string]string{} + + for row in res.rows { + mut values := map[string]string{} + for col, idx in res.cols { + values[col] = row.vals[idx] or { '' } as string + } + rows << values + } + return rows +} + fn test_option_unwrap_as_cast() { x := get_opt(1) d := get_opt_int(12) @@ -21,3 +63,15 @@ fn test_option_unwrap_as_cast() { assert d? as int == 12 assert x? as string == 'success' } + +fn test_option_array_index_or_block_followed_by_as_cast() { + conn := &TestPgConnection{ + db: TestDb{} + } + rows := conn.query('select') or { panic(err) } + + assert rows.len == 1 + assert rows[0]['present'] == 'hello' + assert rows[0]['empty'] == '' + assert rows[0]['none'] == '' +} -- 2.39.5