Example #1
0
def test_Metaline_insert_adjustsindices_beyond_span():
    fores = RunLengthList([(0, "F"), (5, "B")])
    backs = RunLengthList([(0, "F"), (5, "B")])
    m = Metaline("foobar", fores, backs)
    m.insert(3, "baz")
    assert m.fores.items() == [(0, "F"), (8, "B")], m.fores.items()
    assert m.backs.items() == [(0, "F"), (8, "B")], m.backs.items()
Example #2
0
def test_Metaline_delete():
    fores = RunLengthList([(0, "F"), (4, "B"), (7, "Z")])
    backs = RunLengthList([(0, "F"), (4, "B"), (7, "Z")])
    m = Metaline("foobarbaz", fores, backs)
    m.delete(3, 6)
    assert m.line == "foobaz", m.line
    assert m.fores.items() == m.backs.items() == [(0, "F"), (3, "B"), (4, "Z")]
Example #3
0
def test_insert_metaline():
    ml_one = Metaline("foo baz", RunLengthList([(0, "foo"), (4, "baz")]), RunLengthList([(0, "foo"), (4, "baz")]))
    ml_two = simpleml("bar ", "bar", "bar")
    ml_one.insert_metaline(4, ml_two)
    assert ml_one == Metaline(
        "foo bar baz",
        RunLengthList([(0, "foo"), (4, "bar"), (8, "baz")]),
        RunLengthList([(0, "foo"), (4, "bar"), (8, "baz")]),
    )
Example #4
0
 def metaLine(self):
     line = "Shield|Aura|Barrier"
     fg = RunLengthList([(0, fg_code(YELLOW, True))])
     bg = RunLengthList([(0, bg_code(GREEN))])
     if self.shield:
         bg.add_change(0, bg_code(RED))
     else:
         bg.add_change(0, bg_code(GREEN))
     first_separator = line.find('|')
     if self.aura:
         bg.add_change(first_separator + 1, RED)
     else:
         bg.add_change(first_separator + 1, GREEN)
     second_separator = line.find('|', first_separator + 1)
     if self.barrier:
         bg.add_change(second_separator + 1, RED)
     else:
         bg.add_change(second_separator + 1, GREEN)
     ml = Metaline(line, fg, bg)
     return ml
Example #5
0
def test_change_fore_with_trailing_colours():
    ml = Metaline("foo bar", RunLengthList([(0, "foo"), (7, "bar")]), RunLengthList([(0, "bar")]))
    ml.change_fore(0, 3, "baz")
    assert ml.fores.items() == [(0, "baz"), (3, "foo"), (7, "bar")]
Example #6
0
 def test_changes_fg_right_at_end(self):
     metaline = Metaline("foobar", RunLengthList([(0, "FOO")]), None)
     metaline.change_fore(1, 6, "BAR")
     assert metaline.fores.items() == [(0, "FOO"), (1, "BAR"), (6, "FOO")]
Example #7
0
 def test_preserves_engulfed_colour_starts(self):
     metaline = Metaline("foobar", RunLengthList([(0, "FOO"), (2, "BAR")]), None)
     metaline.change_fore(1, 3, "BAZ")
     assert metaline.fores.items() == [(0, "FOO"), (1, "BAZ"), (3, "BAR")]
Example #8
0
 def test_changes_fg_normally(self):
     metaline = Metaline("foobar", RunLengthList([(0, "FOO")]), None)
     metaline.change_fore(1, 3, "BAR")
     assert metaline.fores.items() == [(0, "FOO"), (1, "BAR"), (3, "FOO")]
Example #9
0
def test_Metaline_change_fg_sets_colour():
    m = Metaline("foo", RunLengthList([(0, None)]), None)
    m.change_fore(0, 5, "foo")
    assert m.fores.items() == [(0, "foo"), (5, None)]
Example #10
0
def test_Metaline_insert_fg_bg_on_too_long():
    fores, backs = RunLengthList([(0, "foo")]), RunLengthList([(0, "bar")])
    m = Metaline("foo", fores.copy(), backs.copy())
    m.insert(2, "bar")
    assert m.fores == fores, m.backs == backs
Example #11
0
def test_Metaline_insert_inserts_text():
    m = Metaline("foobaz", RunLengthList([(0, None)]), RunLengthList([(0, None)]))
    m.insert(3, "bar")
    assert m.line == "foobarbaz", m.line
Example #12
0
def test_Metaline_change_bg_sets_colour():
    m = Metaline("foo", None, RunLengthList([(0, None)]))
    m.change_back(2, 3, "bar")
    assert m.backs.items() == [(0, None), (2, "bar"), (3, None)], m.backs.items()