Commit 9753ca3a authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

stringview: function real_indices now ccall to be testable from python code

parent 86f625c0
......@@ -29,9 +29,15 @@ from typing import Optional, Iterable, Tuple
try:
import cython
except ImportError:
from DHParser import foreign_cython as cython
# from DHParser import foreign_cython as cython
pass
# needs to be imported because otherwise cython hickups on
# cpdef-functions with cython parameter annotations, like
# cpdef real_indices(begin, end, len: cython.int):
# ^
from DHParser import foreign_cython as cython
__all__ = ('StringView', 'EMPTY_STRING_VIEW', 'real_indices')
__all__ = ('StringView', 'EMPTY_STRING_VIEW')
@cython.cfunc
......@@ -40,7 +46,7 @@ def pack_index(index: cython.int, len: cython.int) -> cython.int:
return 0 if index < 0 else len if index > len else index
@cython.cfunc
@cython.ccall
def real_indices(begin, end, len: cython.int):
cython.declare(cbegin=cython.int, cend=cython.int)
cbegin = 0 if begin is None else begin
......
......@@ -17,4 +17,4 @@ permissions and limitations under the License.
"""
__all__ = ('__version__',)
__version__ = '0.7.7' # + '_dev' + str(os.stat(__file__).st_mtime)
__version__ = '0.7.8' # + '_dev' + str(os.stat(__file__).st_mtime)
......@@ -24,19 +24,19 @@ import sys
sys.path.extend(['../', './'])
from DHParser.toolkit import re
from DHParser.stringview import StringView, EMPTY_STRING_VIEW # , real_indices
from DHParser.stringview import StringView, EMPTY_STRING_VIEW, real_indices
class TestStringView:
# def test_real_indices(self):
# assert real_indices(3, 5, 10) == (3, 5)
# assert real_indices(None, None, 10) == (0, 10)
# assert real_indices(-2, -1, 10) == (8, 9)
# assert real_indices(-3, 11, 10) == (7, 10)
# assert real_indices(-5, -12, 10) == (5, 0)
# assert real_indices(-12, -5, 10) == (0, 5)
# assert real_indices(7, 6, 10) == (7, 6)
# assert real_indices(None, 0, 10) == (0, 0)
def test_real_indices(self):
assert real_indices(3, 5, 10) == (3, 5)
assert real_indices(None, None, 10) == (0, 10)
assert real_indices(-2, -1, 10) == (8, 9)
assert real_indices(-3, 11, 10) == (7, 10)
assert real_indices(-5, -12, 10) == (5, 0)
assert real_indices(-12, -5, 10) == (0, 5)
assert real_indices(7, 6, 10) == (7, 6)
assert real_indices(None, 0, 10) == (0, 0)
def test_creation(self):
s = "0123456789"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment