我在 ANTLR 中有一个带有参数的解析器规则。
tincture [Tinctures tinctures] returns [Tincture tincture]
: { String tinctureName = ""; }
( COLOUR { tinctureName = $COLOUR.text; }
| METAL { tinctureName = $METAL.text; }
| FUR { tinctureName = $FUR.text; }
)
{
try {
$tincture = tinctures.getTincture(tinctureName);
} catch (UnknownTinctureException e) {
throw new MyRecognitionException("Unknown tincture found.", e);
}
}
;
如何在 GUnit 中为此编写测试?
我已经成功地为我的 Lexer 规则编写了测试,因为它们没有任何参数。如果我写以下内容,我会得到“java.lang.NoSuchMethodException:mypackage.BlazonParser.tincture()”
tincture
: "gules" OK
"sable" OK
"blah" FAIL
除了这个页面,我几乎找不到关于 GUnit 的文档,但它没有涵盖这一点。