diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2025-06-09 10:50:03 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2025-06-09 10:50:03 +0200 |
commit | 62ae476eab4e600d6b7d662735910db0db2c4aa1 (patch) | |
tree | cb3f8e53587ee51cd0201765e6140dcc423ba4b0 /test/RegexpReplace.vala | |
parent | e10377c3781fe84f10b3758b35bf403f91e6603a (diff) | |
parent | 361eb97e74a85fd3cbbb67a7a17281c49e2585f4 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'test/RegexpReplace.vala')
-rw-r--r-- | test/RegexpReplace.vala | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/RegexpReplace.vala b/test/RegexpReplace.vala new file mode 100644 index 0000000..b9aaac7 --- /dev/null +++ b/test/RegexpReplace.vala @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// SPDX-FileCopyrightText: 2025 Jens Georg <mail@jensge.org> + +namespace Db { + public static unowned string IN_MEMORY_NAME = ":memory:"; +} + +class AppWindow { + public static void panic(string args) {} +} + +// Helper class to expose protected members +abstract class TestDb : DatabaseTable { + public static unowned Sqlite.Database get_db() { + DatabaseTable.init(Db.IN_MEMORY_NAME); + return DatabaseTable.db; + } +} + +void main(string[] args) { + GLib.Intl.setlocale(LocaleCategory.ALL, ""); + Test.init(ref args); + Test.add_func("/functional/regexp_replace", () => { + unowned Sqlite.Database db = TestDb.get_db(); + + { + Sqlite.Statement s; + assert(db.prepare_v2("SELECT regexp_replace('^charset=\\w+\\s*', 'charset=Unicode This is a comment, äöü, some encoding perhjaps', '')", -1, out s) == Sqlite.OK); + assert(s.step() == Sqlite.ROW); + assert(s.column_text(0) == "This is a comment, äöü, some encoding perhjaps"); + } + + { + Sqlite.Statement s; + assert(db.prepare_v2("SELECT regexp_replace('^charset=\\w+\\s*', 'test charset=Unicode This is a comment, äöü, some encoding perhjaps', '')", -1, out s) == Sqlite.OK); + assert(s.step() == Sqlite.ROW); + assert(s.column_text(0) == "test charset=Unicode This is a comment, äöü, some encoding perhjaps"); + } + }); + Test.add_func("/functional/catch_invalid_regexp", () => { + unowned Sqlite.Database db = TestDb.get_db(); + assert(db.exec("regexp_replace('charset=\\X*', '', '')") == Sqlite.ERROR); + assert(db.exec("regexp_replace(NULL, '', '')") == Sqlite.ERROR); + assert(db.exec("regexp_replace('pattern', NULL, '')") == Sqlite.ERROR); + + Sqlite.Statement s; + + // NULL replacement should return the original text, even if it matches + assert(db.prepare_v2("SELECT regexp_replace('test\\s+', 'test some pattern', NULL)", -1, out s) == Sqlite.OK); + assert(s.step() == Sqlite.ROW); + assert(s.column_text(0) == "test some pattern"); + + }); + Test.run(); +}
\ No newline at end of file |