MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_unit_split

Function test_unit_split

scripts/test_stringzilla.py:315–373  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

313
314
315def test_unit_split():
316 native = "line1\nline2\nline3"
317 big = Str(native)
318
319 # Splitting using a string
320 lines = sz.split(big, "\n")
321 assert lines == ["line1", "line2", "line3"]
322
323 lines = sz.rsplit(big, "\n")
324 assert lines == ["line1", "line2", "line3"]
325
326 lines = sz.split(big, "\n", keepseparator=True)
327 assert lines == ["line1\n", "line2\n", "line3"]
328
329 letters = sz.split("a b c d")
330 assert letters == ["a", "b", "c", "d"]
331
332 # Splitting using character sets
333 letters = sz.split_byteset("a b_c d", " _")
334 assert letters == ["a", "b", "c", "d"]
335
336 letters = sz.rsplit_byteset("a b_c d", " _")
337 assert letters == ["a", "b", "c", "d"]
338
339 # Check for equivalence with native Python strings for newline separators
340 assert native.splitlines() == list(big.splitlines())
341 assert native.splitlines(True) == list(big.splitlines(keeplinebreaks=True))
342
343 # Check for equivalence with native Python strings, including SWAR boundary conditions
344 assert native.split("l") == list(big.split("l"))
345 assert native.split("li") == list(big.split("li"))
346 assert native.split("lin") == list(big.split("lin"))
347 assert native.split("line") == list(big.split("line"))
348 assert native.split("line1") == list(big.split("line1"))
349 assert native.split("line3") == list(big.split("line3"))
350 assert native.split("\n", maxsplit=0) == list(big.split("\n", maxsplit=0))
351 assert native.split("\n", maxsplit=1) == list(big.split("\n", maxsplit=1))
352 assert native.split("\n", maxsplit=2) == list(big.split("\n", maxsplit=2))
353 assert native.split("\n", maxsplit=3) == list(big.split("\n", maxsplit=3))
354 assert native.split("\n", maxsplit=4) == list(big.split("\n", maxsplit=4))
355
356 # Check for equivalence with native Python strings in reverse order, including boundary conditions
357 assert native.rsplit("line1") == list(big.rsplit("line1"))
358 assert native.rsplit("line3") == list(big.rsplit("line3"))
359 assert native.rsplit("\n", maxsplit=0) == list(big.rsplit("\n", maxsplit=0))
360 assert native.rsplit("\n", maxsplit=1) == list(big.rsplit("\n", maxsplit=1))
361 assert native.rsplit("\n", maxsplit=2) == list(big.rsplit("\n", maxsplit=2))
362 assert native.rsplit("\n", maxsplit=3) == list(big.rsplit("\n", maxsplit=3))
363 assert native.rsplit("\n", maxsplit=4) == list(big.rsplit("\n", maxsplit=4))
364
365 # If the passed separator is an empty string, the library must raise a `ValueError`
366 with pytest.raises(ValueError):
367 sz.split(big, "")
368 with pytest.raises(ValueError):
369 sz.rsplit(big, "")
370 with pytest.raises(ValueError):
371 sz.split_byteset(big, "")
372 with pytest.raises(ValueError):

Callers

nothing calls this directly

Calls 3

splitMethod · 0.80
rsplitMethod · 0.80
splitlinesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…