Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Why does my test is not working
Why does my test is not working [message #1796168] Sun, 07 October 2018 21:54 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Hi all, I have following grammar, validator, and the test. Unfortunately, my test is not passed with the following error message

Quote:

Expected ERROR 'org.blockchain.rell.entities.HierarchyCycle' on TheClass at [-1:-1] but got
ERROR (null) 'cycle in hierarchy of entity 'Test'' on TheClass, offset 19, length 4



But why and how to fix it?

Regards,
Vladimir
grammar org.blockchain.rell.Rell with org.eclipse.xtext.common.Terminals

generate rell "http://www.blockchain.org/rell/Rell"

Model:
	entities+=TheClass*
	operations+=Operation*;

TheClass:
	'class' name=ID ('extends' superType=[TheClass])? '{'
	attributes+=Attribute*
	'}';

Operation:
	"operation" name=ID "(" parameters=RelAttrubutesList? ")" "{" statements+=Statement* "}";

Statement:
	(Relational | Variable) ';';

Variable:
	declaration=VariableDeclaration '=' expression=Expression;

Relational:
	Update | Delete | Create;

Update:
	'update' entity=ID '(' expressions=ExpressionsModel? ')' '{' variableList+=VariableInit
	(',' variableList+=VariableInit*)? '}';

Delete:
	'delete' entity=ID '(' expressions=ExpressionsModel? ')';

Create:
	'create' entity=ID '(' expressions=ExpressionsModel? ')';

ExpressionsModel:
	elements+=ConditionElements (',' elements+=ConditionElements*)?;

ConditionElements:
	compareName=ID ('==' | '!=' | '>' | '<' | '>=' | '<=') expr=Expression;

	//AbstractElement:
//	Variable | Expression;
//
VariableInit:
	name=ID '=' expression=Expression;

Expression:
	Or;

Or returns Expression:
	And ({Or.left=current} "or" right=And)*;

And returns Expression:
	Equality ({And.left=current} "and" right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} op=("==" | "!=")
	right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} op=(">=" | "<=" | ">" | "<")
	right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MulOrDiv (({Plus.left=current} '+' | {Minus.left=current} '-')
	right=MulOrDiv)*;

Atomic returns Expression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BoolConstant} value=('true' | 'false') |
	{VariableRef} variable=[Variable];

MulOrDiv returns Expression:
	Primary ({MulOrDiv.left=current} op=('*' | '/')
	right=Primary)*;

Primary returns Expression:
	'(' Expression ')' |
	{Not} "not" expression=Primary |
	Atomic;

RelAttrubutesList:
	value+=RelAttribute (',' value+=RelAttribute)*;

RelAttribute:
	name=ID ':' reference=TypeReference;

Attribute:
	modificator=Prefix? variable=VariableDeclaration ';';

VariableDeclaration:
	name=ID ':' type=TypeReference;

TypeReference:
	primitive=PrimitiveType | entity=EntityType;

PrimitiveType:
	Text | Integer | Json | ByteArray;

EntityType:
	entity=[TheClass];

Json:
	'json';

Integer:
	'integer' | 'timestamp';

Text:
	'text' | 'tuid' | 'name';

ByteArray:
	'byte_array' | 'signer' | 'guid' | 'pubkey';

Prefix:
	'key' | 'index';


/*
 * generated by Xtext 2.14.0
 */
package org.blockchain.rell.validation

import org.blockchain.rell.rell.RellPackage
import org.blockchain.rell.rell.TheClass
import org.eclipse.xtext.validation.Check

/**
 * Custom validation rules. 
 * 
 * see http://www.eclipse.org/Xtext/documentation.html#validation
 */
class RellValidator extends AbstractRellValidator {

	public static val FORWARD_REFERENCE = "org.example.expressions.ForwardReference";

	public static val WRONG_TYPE = "org.example.expressions.WrongType";

	public static val HIERARCHY_CYCLE = "org.blockchain.rell.entities.HierarchyCycle";

	

	@Check
	def checkNoCycleClassHierarhy(TheClass theClass) {
		if (theClass.superType === null) {
			return;
		}
		val visitedClasses = <TheClass>newHashSet();
		visitedClasses.add(theClass);
		var current = theClass.superType
		while (current !== null) {
			if (visitedClasses.contains(current)) {
				error("cycle in hierarchy of entity '" + current.name + "'", RellPackage::eINSTANCE.theClass_SuperType)
				return
			}
			visitedClasses.add(current)
			current = current.superType
		}

	}
}



package org.blockchain.rell.tests

import com.google.inject.Inject
import org.blockchain.rell.rell.Model
import org.blockchain.rell.rell.RellPackage
import org.blockchain.rell.validation.RellValidator
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(RellInjectorProvider))
class RellValidatorTest {
	@Inject extension ParseHelper<Model>
	@Inject extension ValidationTestHelper

	@Test
	def void testEntityExtendsItself() {
		'''class Test extends Test{
			
		}'''.parse.assertError(RellPackage.eINSTANCE.theClass, RellValidator::HIERARCHY_CYCLE,
			"cycle in hierarchy of entity 'Test'")
	}
}


Re: Why does my test is not working [message #1796182 is a reply to message #1796168] Mon, 08 October 2018 04:39 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, you test for a error code you dont use during creation

error("cycle in hierarchy of entity '" + current.name + "'", theClass, MyDslPackage::eINSTANCE.theClass_SuperType, HIERARCHY_CYCLE)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText Generator making random mistakes while generating java classes
Next Topic:Class missing while executing xtext-maven:generate
Goto Forum:
  


Current Time: Fri Apr 26 03:03:10 GMT 2024

Powered by FUDForum. Page generated in 0.02940 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top