我写了以下验证规则:
@Check
def checkDeclarationIsNotReferenceToItself(Declaration dec) {
if(dec.decCon.singleContent.reference == null && !dec.decCon.nextCon.isEmpty) {
//only proceed if it is a reference
return
}
var name = dec.name
if(dec.decCon.singleContent.reference.name == name) {
//only if the declaration is a self-reference without further actions
var warningMsg = "The declaration '" + name + "' is a reference to itself"
warning(warningMsg,
SQFPackage.eINSTANCE.declaration_DecCon,
SELFREFERENCE)
}
}
然后我写了一个测试用例,看起来如下:
@Test
def void checkDeclarationIsNotReferenceToItselfTest() {
'''
test = 3;
test = test;
'''.parse.assertWarning(SQFPackage.eINSTANCE.decContent,
SQFValidator.SELFREFERENCE,
"The declaration 'test' is a reference to itself")
}
但是当我运行JUnit时,它报告错误:
Expected WARNING 'raven.sqf.SelfReference' on DecContent at [-1:-1] but got
WARNING (raven.sqf.SelfReference) 'The declaration 'test' is a reference to itself' on Declaration, offset 18, length 4
我不明白这一点,因为它实际上预计会出现错误信息(据我所知)
任何人都知道它为什么不起作用?
问候Krzmbrzl
答案 0 :(得分:1)
看起来像您创建警告的方式并且测试验证不匹配
warning(warningMsg,
SQFPackage.eINSTANCE.declaration_DecCon,
SELFREFERENCE)
在声明
上创建警告.assertWarning(SQFPackage.eINSTANCE.decContent,
SQFValidator.SELFREFERENCE,
"The declaration 'test' is a reference to itself")
测试DecContent