Mercurial > hgrepos > Python > libs > ConfigMix
changeset 710:ff0de14493f1
Test that "," is preferred over "|"
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Tue, 15 Aug 2023 14:31:46 +0200 |
| parents | 115de6fe420e |
| children | 6557cf9ecea5 |
| files | configmix/_speedups.c tests/test.py |
| diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/_speedups.c Tue Aug 15 11:40:18 2023 +0200 +++ b/configmix/_speedups.c Tue Aug 15 14:31:46 2023 +0200 @@ -613,6 +613,7 @@ Py_ssize_t sep; PyObject *res = NULL; PyObject *filters = NULL; + Py_ssize_t filters_len; PyObject *name = NULL; PyObject *tmp; @@ -657,7 +658,11 @@ } py_transfer_owned(&filters, &tmp); - if (PyObject_Not(filters)) { + filters_len = PyUnicode_GetLength(filters); + if (filters_len < 0) { + goto error; + } + if (filters_len == 0) { py_clear_ref(&filters); res = PyTuple_New(2); @@ -684,7 +689,7 @@ } if (direction == 1) { - if (PySequence_Contains(filters, sstate->FILTER_SEPARATOR_2)) { + if (PyUnicode_FindChar(filters, ',', 0, filters_len, 1) >= 0) { tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR_2, -1); } else {
--- a/tests/test.py Tue Aug 15 11:40:18 2023 +0200 +++ b/tests/test.py Tue Aug 15 14:31:46 2023 +0200 @@ -2233,6 +2233,11 @@ self.assertEqual((u"the-varname", [u"Empty", u"None"]), self.split_filters(u"the-varname|Empty,None", 1)) + def test_split_filters_many_alt_preferred(self): + # "," is preferred + self.assertEqual((u"the-varname", [u"Empty|", u"None"]), + self.split_filters(u"the-varname|Empty|,None", 1)) + def test_None_filter_single(self): cfg = configmix.load() x = getattr(cfg, self.interpolate_meth)(u"{{non-existing|None}}")
