From e23096740aa6c929daa7965929648ff49fb6b631 Mon Sep 17 00:00:00 2001 From: vennyy3 Date: Tue, 21 Jul 2026 14:27:36 +0200 Subject: [PATCH] DAT-534 tests for bugfixes --- py_maplib/tests/test_custom_functions.py | 72 +++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/py_maplib/tests/test_custom_functions.py b/py_maplib/tests/test_custom_functions.py index cce8e484..1592ce00 100644 --- a/py_maplib/tests/test_custom_functions.py +++ b/py_maplib/tests/test_custom_functions.py @@ -1,6 +1,9 @@ +import polars as pl import pytest +from polars.testing import assert_frame_equal + +from maplib import Model, RDFType, MaplibException, rdf -from maplib import Model, RDFType, MaplibException def test_struuidv5_dns(): m = Model() @@ -77,3 +80,70 @@ def test_struuidv5_valid(): """) assert df.height == 3 +def test_concat_lang_string_same_lang(): + m = Model() + df = m.query(""" + SELECT * WHERE { + VALUES ?name {"bar"@en} + BIND(concat("foo"@en, ?name) AS ?concatstr) + } + """) + expected_df = pl.from_repr( + """ + ┌─────────────┬──────────┐ + │ concatstr ┆ name │ + │ --- ┆ --- │ + │ str ┆ str │ + ╞═════════════╪══════════╡ + │ "foobar"@en ┆ "bar"@en │ + └─────────────┴──────────┘ + """ + ) + sm = m.query(""" + SELECT * WHERE { + VALUES ?name {"bar"@en} + BIND(concat("foo"@en, ?name) AS ?concatstr) + } + """, solution_mappings=True) + assert_frame_equal(df, expected_df) + assert sm.rdf_types["concatstr"] == RDFType.Literal(rdf.langString) + +def test_concat_lang_string_diff_lang(): + m = Model() + df = m.query(""" + SELECT * WHERE { + VALUES ?name {"bar"@en} + BIND(concat(?name, "noe"@no) AS ?concatstr) + } + """) + expected_df = pl.from_repr(""" + ┌─────────────┬──────────┐ + │ concatstr ┆ name │ + │ --- ┆ --- │ + │ str ┆ str │ + ╞═════════════╪══════════╡ + │ "barnoe"@en ┆ "bar"@en │ + └─────────────┴──────────┘ + """ + ) + assert_frame_equal(df, expected_df) + +def test_encoding_of_parenthesis(): + m = Model() + df = m.query(""" + SELECT * WHERE { + VALUES ?name {"Foo(bar)"} + BIND(ENCODE_FOR_URI(?name) AS ?encodedstr) + } + """) + expected_df = pl.from_repr(""" + ┌──────────────┬──────────┐ + │ encodedstr ┆ name │ + │ --- ┆ --- │ + │ str ┆ str │ + ╞══════════════╪══════════╡ + │ Foo%28bar%29 ┆ Foo(bar) │ + └──────────────┴──────────┘ + """ + ) + assert_frame_equal(df, expected_df) \ No newline at end of file