Files
msproj/test/net/woodyfolsom/msproj/sgf/CollectionTest.java

56 lines
1.8 KiB
Java

package net.woodyfolsom.msproj.sgf;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.junit.Test;
public class CollectionTest {
public static final String TEST_SGF =
"(;FF[4]SZ[9]KM[5.5]RE[W+6.5]"+
";W[ee];B[];W[])";
public static final String TEST_LATEX =
"\\white{e5}\n" +
"\\begin{center}\n" +
"\\gobansize{9}\n" +
"\\shortstack{\\showfullgoban\\\\White wins by 6.5}\n" +
"\\end{center}";
@Test
public void testToSGF() throws RecognitionException, IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(
("(;FF[4]SZ[9]KM[5.5]RE[W+6.5]" +
";W[ee];B[];W[])"
).getBytes());
ANTLRStringStream in = new ANTLRInputStream(bis);
SGFLexer lexer = new SGFLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SGFParser parser = new SGFParser(tokens);
SGFNodeCollection nodeCollection = parser.collection();
assertEquals(TEST_SGF, nodeCollection.toSGF());
}
@Test
public void testToLaTeX() throws RecognitionException, IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(
("(;FF[4]SZ[9]RE[W+6.5]" +
";W[ee];B[];W[])"
).getBytes());
ANTLRStringStream in = new ANTLRInputStream(bis);
SGFLexer lexer = new SGFLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SGFParser parser = new SGFParser(tokens);
SGFNodeCollection nodeCollection = parser.collection();
String actualLaTeX = nodeCollection.toLateX();
assertEquals(TEST_LATEX, actualLaTeX);
}
}