def test_function_flag_removal(): result = process(""": emit\n\n: def foo -> !buffer\n\n: emit\n\n: end\n\n: emit""") pre, mid, post = result assert str(pre).strip() == 'flags: buffer, init' assert str(mid).strip() == 'flags: init' assert str(post).strip() == 'flags: buffer, init'
def test_line_formatting(): assert Line(None, "\tHuzzah?").stripped == "Huzzah?" assert Line(None, "foo bar baz").partitioned == ('foo', 'bar baz') assert repr(Line(1, "First!")) == 'Line(1, text, "First!")' assert str(Line(None, "Flat.")) == "Flat." assert str(Line(None, "Indented.", 1)) == "\tIndented." assert bytes(Line(None, "Text.")) == b"Text."
def test_function_flag_addition(): result = process(""": emit\n\n: def foo -> example\n\n: emit\n\n: end\n\n: emit""") pre, mid, post = result assert str(pre).strip() == 'flags: buffer, init' assert str(mid).strip() == 'flags: buffer, example, init, text' assert str(post).strip() == 'flags: buffer, init'
def test_line_clone(): line = Line(27, "\t\tMy test line!", 2) clone = line.clone(line="New line.") assert line.number == clone.number assert line.line != clone.line assert line.scope == clone.scope assert str(clone) == '\t\tNew line.'
def test_pragma_removal(): result = process(""": emit\n\n: pragma !buffer\n\n: emit""") first, second = result assert str(first).strip() == 'flags: buffer, init' assert str(second).strip() == 'flags: init'
def test_pragma_additions(): result = process(""": emit\n\n: pragma foo\n\n: emit""") first, second = result assert str(first).strip() == 'flags: buffer, init' assert str(second).strip() == 'flags: buffer, foo, init'
def encode(value, encoding='utf8'): return str(value).encode(encoding)
def text(value): return str(value)