Beispiel #1
0
def test_simple():
    input_sgf = "(;GM[1]FF[4]SZ[19]DT[2020-04-12]AB[dd][dj];B[dp];W[pp];B[pj])"
    root = SGF.parse(input_sgf)
    assert "4" == root.get_property("FF")
    assert root.get_property("XYZ") is None
    assert "dp" == root.children[0].get_property("B")
    assert input_sgf == root.sgf()
Beispiel #2
0
def test_weird_escape():
    input_sgf = """(;GM[1]FF[4]CA[UTF-8]AP[Sabaki:0.43.3]KM[6.5]SZ[19]DT[2020-04-12]C[how does it escape
[
or \\]
])"""
    root = SGF.parse(input_sgf)
    assert input_sgf == root.sgf()
Beispiel #3
0
def test_backslash_escape():
    nasty_string = "[]]\\"
    nasty_strings = [
        "[\\]\\]\\\\", "[", "]", "\\", "\\[", "\\]", "\\\\[", "\\\\]",
        "]]]\\]]\\]]["
    ]
    assert "[\\]\\]\\\\" == SGFNode._escape_value(nasty_string)
    for x in nasty_strings:
        assert x == SGFNode._unescape_value(SGFNode._escape_value(x))

    c2 = ["]", "\\"]
    node = SGFNode(properties={"C1": nasty_string})
    node.set_property("C2", c2)
    assert "(;C1[[\\]\\]\\\\]C2[\\]][\\\\])" == node.sgf()
    assert {"C1": [nasty_string], "C2": c2} == SGF.parse(node.sgf()).properties
Beispiel #4
0
def test_dragon_weirdness():  # dragon go server has weird line breaks
    input_sgf = "\n(\n\n;\nGM[1]\nFF[4]\nCA[UTF-8]AP[Sabaki:0.43.3]KM[6.5]SZ[19]DT[2020-04-12]AB[dd]\n[dj]\n(\n;\nB[dp]\n;\nW[pp]\n(\n;\nB[pj]\n)\n(\n;\nPL[B]\nAW[jp]\nC[sdfdsfdsf]\n)\n)\n(\n;\nB[pd]\n)\n)\n"
    root = SGF.parse(input_sgf)
    assert input_sgf.replace("\n", "") == root.sgf()
Beispiel #5
0
def test_branch():
    input_sgf = "(;GM[1]FF[4]CA[UTF-8]AP[Sabaki:0.43.3]KM[6.5]SZ[19]DT[2020-04-12]AB[dd][dj](;B[dp];W[pp](;B[pj])(;PL[B]AW[jp]C[sdfdsfdsf]))(;B[pd]))"
    root = SGF.parse(input_sgf)
    assert input_sgf == root.sgf()