def test_append(): src = "__src__" create_file(src, "a") try: assert_true(""" open('%s', append, S), put_char(S, a), put_char(S, 'ü'), put_char(S, '¼'), close(S). """ % src) assert file_content(src) == "aaü¼" finally: delete_file(src) create_file(src, "") try: assert_true(""" open('%s', append, S), put_byte(S, 97), put_byte(S, 98), put_byte(S, 99), close(S). """ % src) assert file_content(src) == "abc" finally: delete_file(src) try: assert_true(""" open('%s', append, S), put_char(S, a), close(S). """ % src) assert file_content(src) == "a" finally: delete_file(src) term = "f(a, b, c)" try: assert_true(""" open('%s', append, S), write(S, %s), close(S). """ % (src, term)) assert file_content(src) == term finally: delete_file(src)
def test_write_term(): src = "__src__" try: assert_true(""" open('%s', write, S), write_term(S, f(g(h(c))), [max_depth(1)]), close(S). """ % src) assert "f(...)" == file_content(src) finally: delete_file(src) try: assert_true(""" open('%s', write, S), write_term(S, f(g(h(c))), [max_depth(0)]), close(S). """ % src) assert "f(g(h(c)))" == file_content(src) finally: delete_file(src)
def test_nl(): src = "__src__" create_file(src, "") try: assert_true(""" open('%s', write, S), nl(S), close(S). """ % src) assert "\n" == file_content(src) finally: delete_file(src)
def test_write(): src = "__src__" term = "f(a, b, g(e))" create_file(src, "") try: assert_true(""" open('%s', write, S), write(S, %s), close(S). """ % (src, term)) assert term == file_content(src) finally: delete_file(src)
def test_put_byte(): target = "__target__" create_file(target, "") try: assert_true(""" open('%s', write, S), put_byte(S, 97), put_byte(S, 194), put_byte(S, 165), close(S). """ % target) assert file_content(target) == "a¥" finally: delete_file(target)
def test_put_char(): src = "__src__" target = "__target__" content = "aö½" create_file(src, content) create_file(target, "") try: assert_true(""" open('%s', read, R), open('%s', write, W), get_char(R, C1), put_char(W, C1), get_char(R, C2), put_char(W, C2), get_char(R, C3), put_char(W, C3), close(R), close(W). """ % (src, target)) assert content == file_content(src) finally: delete_file(src) delete_file(target)