MCPcopy
hub / github.com/Textualize/rich / test_divide

Function test_divide

tests/test_text.py:406–446  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

404
405
406def test_divide():
407 lines = Text("foo").divide([])
408 assert len(lines) == 1
409 assert lines[0] == Text("foo")
410
411 text = Text()
412 text.append("foo", "bold")
413 lines = text.divide([1, 2])
414 assert len(lines) == 3
415 assert str(lines[0]) == "f"
416 assert str(lines[1]) == "o"
417 assert str(lines[2]) == "o"
418 assert lines[0]._spans == [Span(0, 1, "bold")]
419 assert lines[1]._spans == [Span(0, 1, "bold")]
420 assert lines[2]._spans == [Span(0, 1, "bold")]
421
422 text = Text()
423 text.append("foo", "red")
424 text.append("bar", "green")
425 text.append("baz", "blue")
426 lines = text.divide([8])
427 assert len(lines) == 2
428 assert str(lines[0]) == "foobarba"
429 assert str(lines[1]) == "z"
430 assert lines[0]._spans == [
431 Span(0, 3, "red"),
432 Span(3, 6, "green"),
433 Span(6, 8, "blue"),
434 ]
435 assert lines[1]._spans == [Span(0, 1, "blue")]
436
437 lines = text.divide([1])
438 assert len(lines) == 2
439 assert str(lines[0]) == "f"
440 assert str(lines[1]) == "oobarbaz"
441 assert lines[0]._spans == [Span(0, 1, "red")]
442 assert lines[1]._spans == [
443 Span(0, 2, "red"),
444 Span(2, 5, "green"),
445 Span(5, 8, "blue"),
446 ]
447
448
449def test_right_crop():

Callers

nothing calls this directly

Calls 4

divideMethod · 0.95
appendMethod · 0.95
TextClass · 0.90
SpanClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…