# Path: betago/gosgf/sgf_grammar.py
# def is_valid_property_identifier(s):
# def is_valid_property_value(s):
# def tokenise(s, start_position=0):
#     def __init__(self):
# def _parse_sgf_game(s, start_position):
# def parse_sgf_game(s):
# def parse_sgf_collection(s):
# def block_format(pieces, width=79):
# def serialise_game_tree(game_tree, wrap=79):
# def make_tree(game_tree, root, node_builder, node_adder):
# def make_coarse_game_tree(root, get_children, get_properties):
# def main_sequence_iter(game_tree):
# def parse_compose(s):
# def compose(s1, s2):
# def simpletext_value(s):
# def text_value(s):
# def escape_text(s):
# class Coarse_game_tree(object):


import unittest
from betago.gosgf import sgf_grammar
        tc.assertEqual(simpletext_value(b"ab \tc"), b"ab  c")
        tc.assertEqual(simpletext_value(b"ab\nc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\\\nc"), b"abc")
        tc.assertEqual(simpletext_value(b"ab\\\\\nc"), b"ab\\ c")
        tc.assertEqual(simpletext_value(b"ab\xa0c"), b"ab\xa0c")

        tc.assertEqual(simpletext_value(b"ab\rc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\r\nc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\n\rc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\r\n\r\nc"), b"ab  c")
        tc.assertEqual(simpletext_value(b"ab\r\n\r\n\rc"), b"ab   c")
        tc.assertEqual(simpletext_value(b"ab\\\r\nc"), b"abc")
        tc.assertEqual(simpletext_value(b"ab\\\n\nc"), b"ab c")

        tc.assertEqual(simpletext_value(b"ab\\\tc"), b"ab c")

        # These can't actually appear as SGF PropValues; anything sane will do
        tc.assertEqual(simpletext_value(b"abc\\"), b"abc")
        tc.assertEqual(simpletext_value(b"abc]"), b"abc]")

    def test_escape_text(tc):
        tc.assertEqual(sgf_grammar.escape_text(b"abc"), b"abc")
        tc.assertEqual(sgf_grammar.escape_text(r"a\bc".encode('ascii')), r"a\\bc".encode('ascii'))
        tc.assertEqual(sgf_grammar.escape_text(r"ab[c]".encode('ascii')),
                       r"ab[c\]".encode('ascii'))
        tc.assertEqual(sgf_grammar.escape_text(r"a\]bc".encode('ascii')),
                       r"a\\\]bc".encode('ascii'))

    def test_text_roundtrip(tc):
        def roundtrip(s):

# Path: betago/gosgf/sgf_grammar.py
# def is_valid_property_identifier(s):
# def is_valid_property_value(s):
# def tokenise(s, start_position=0):
#     def __init__(self):
# def _parse_sgf_game(s, start_position):
# def parse_sgf_game(s):
# def parse_sgf_collection(s):
# def block_format(pieces, width=79):
# def serialise_game_tree(game_tree, wrap=79):
# def make_tree(game_tree, root, node_builder, node_adder):
# def make_coarse_game_tree(root, get_children, get_properties):
# def main_sequence_iter(game_tree):
# def parse_compose(s):
# def compose(s1, s2):
# def simpletext_value(s):
# def text_value(s):
# def escape_text(s):
# class Coarse_game_tree(object):


# Path: tests/gosgf/sgf_grammar_test.py
import unittest
from betago.gosgf import sgf_grammar

        tc.assertEqual(simpletext_value(b"ab \tc"), b"ab  c")
        tc.assertEqual(simpletext_value(b"ab\nc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\\\nc"), b"abc")
        tc.assertEqual(simpletext_value(b"ab\\\\\nc"), b"ab\\ c")
        tc.assertEqual(simpletext_value(b"ab\xa0c"), b"ab\xa0c")

        tc.assertEqual(simpletext_value(b"ab\rc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\r\nc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\n\rc"), b"ab c")
        tc.assertEqual(simpletext_value(b"ab\r\n\r\nc"), b"ab  c")
        tc.assertEqual(simpletext_value(b"ab\r\n\r\n\rc"), b"ab   c")
        tc.assertEqual(simpletext_value(b"ab\\\r\nc"), b"abc")
        tc.assertEqual(simpletext_value(b"ab\\\n\nc"), b"ab c")

        tc.assertEqual(simpletext_value(b"ab\\\tc"), b"ab c")

        # These can't actually appear as SGF PropValues; anything sane will do
        tc.assertEqual(simpletext_value(b"abc\\"), b"abc")
        tc.assertEqual(simpletext_value(b"abc]"), b"abc]")

    def test_escape_text(tc):
        tc.assertEqual(sgf_grammar.escape_text(b"abc"), b"abc")
        tc.assertEqual(sgf_grammar.escape_text(r"a\bc".encode('ascii')), r"a\\bc".encode('ascii'))
        tc.assertEqual(sgf_grammar.escape_text(r"ab[c]".encode('ascii')),
                       r"ab[c\]".encode('ascii'))
        tc.assertEqual(sgf_grammar.escape_text(r"a\]bc".encode('ascii')),
                       r"a\\\]bc".encode('ascii'))

    def test_text_roundtrip(tc):
        def roundtrip(s):

            return sgf_grammar.text_value(sgf_grammar.escape_text(s))