public class SGFWriterTest extends TestCase {
public void testWrite() {
try {
String data = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]RU[Japanese]SZ[9]HA[3]KM[5.50]PW[White]PB[Black]AB[gc][cg][gg];W[ed]CR[ee]TR[cc][gc](;B[ec]CR[ec]LB[dd:A])(;B[eg]CR[eg];W[];B[ge]))";
SGFParser reader = new SGFParser(data);
SGFNode tree = reader.parse();
assertNotNull("Emty tree received.", tree);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter w = new OutputStreamWriter(baos);
SGFWriter.write(w, tree);
w.close();
//System.out.println(baos.toString());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
reader = new SGFParser(new InputStreamReader(bais));
SGFNode tree2 = reader.parse();
assertEquals(tree, tree2);
assertEquals(SGFWriter.toString(tree), SGFWriter.toString(tree2));
} catch (Exception e) {
e.printStackTrace();