Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to test a formatting with xtend?
How to test a formatting with xtend? [message #909134] Thu, 06 September 2012 15:40 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

could someone point me to any example on how to test a formatting?

I'm using xtend in my parser tests, so I would like to stay with it.

	@Test
	def void testParsingLibraryAttributes() {
		val library = '''
			libraryID core.base
				description "My description"
				creationDate "10/01/2012"
				creator cvgaviao
				ownership org.lunifera
			}
		'''.parse
		
		assertEquals("core.base", library.getName())
		assertNotNull("creationData is null", library.creationDate)



Btw, I could note that xtend editor doesn't have a formatter and I have used tab to ident the text in library val.
Would that tabs influence the formatting tests ?

thanks,

Cristiano
Re: How to test a formatting with xtend? [message #909139 is a reply to message #909134] Thu, 06 September 2012 15:47 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
Hi,

simply injecting the serializer and call it doesnt work?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to test a formatting with xtend? [message #909240 is a reply to message #909139] Thu, 06 September 2012 19:46 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

Well, one more time was not possible to find good practical information in docs... but it is ok.

I did this:
@Inject extension ISerializer

@Test
	def void testFormating() {
		val library = '''
			libraryID core.base
				description "My description"
				creationDate "10/01/2012"
				creator cvgaviao
				ownership org.lunifera
			}
		'''.parse.serialize(SaveOptions::newBuilder.format().getOptions())


Unfortunately, I'm get a red test. I almost sure that is related to indentation. At my eyes junit result in console are identical, so it is a hidden character.
How could I know what is being considered in the multline string val ?

thanks,

Cristiano
Re: How to test a formatting with xtend? [message #909253 is a reply to message #909240] Thu, 06 September 2012 20:19 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
Hi,

the following works for me.

package test

import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.InjectWith
import org.xtext.example.mydsl1.MyDslInjectorProvider
import org.eclipse.xtext.junit4.util.ParseHelper
import org.xtext.example.mydsl1.myDsl.Model
import com.google.inject.Inject
import org.eclipse.xtext.serializer.ISerializer
import static org.junit.Assert.*
import org.junit.Test
import org.eclipse.xtext.resource.SaveOptions

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(MyDslInjectorProvider))
class FormatterTest {
	
	@Inject extension ParseHelper<Model>
	@Inject extension ISerializer
	
	@Test
	def void test() {
		assertEquals(
	'''Hello A !
Hello B !'''.toString,
	'''Hello A! Hello B!'''.parse.serialize(SaveOptions::newBuilder.format().getOptions()))
	}
	
}


public class MyDslFormatter extends AbstractDeclarativeFormatter {
	
	@Override
	protected void configureFormatting(FormattingConfig c) {
		MyDslGrammarAccess ga = (MyDslGrammarAccess) getGrammarAccess();
		c.setLinewrap().after(ga.getGreetingAccess().getExclamationMarkKeyword_2());
		}
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to test a formatting with xtend? [message #909320 is a reply to message #909253] Fri, 07 September 2012 00:03 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Ok, now I got how to deal with tab and a NL at the begging of the multiline text. very good Smile

The tests are passing, but something really weird are happening when I run and call ctrl+shift+F.

I'm getting a newline and one indent for every write line in editor. And to get worst, each time that I call ctrl+shift+F I got another format Sad

Investigating, I could note in the BaseFormatter class this method:

protected TerminalRule getWSRule()


I'm using WS in my grammar but I've split it in two:

terminal WS:
	(' ' | '\t');

terminal NEWLINE:
	'\r'? '\n'?;


would this be related to the problem that I'm facing ?


regards,

Cristiano

Re: How to test a formatting with xtend? [message #909425 is a reply to message #909320] Fri, 07 September 2012 05:56 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
Sorry i have no idea what is going on. please file a ticket.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to test a formatting with xtend? [message #1714432 is a reply to message #909425] Thu, 12 November 2015 16:16 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
This method does not work if one uses the IFormatter2 API. It calls a default implementation of IFormatter instead of IFormatter2.
Re: How to test a formatting with xtend? [message #1714436 is a reply to message #1714432] Thu, 12 November 2015 16:29 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
which xtext version do you use?
https://bugs.eclipse.org/bugs/show_bug.cgi?id=474300


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to test a formatting with xtend? [message #1714443 is a reply to message #1714436] Thu, 12 November 2015 17:09 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
2.8.4.v201508050135
It's the latest version in http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/. I suppose I need to wait for the release of 2.9
Re: How to test a formatting with xtend? [message #1714445 is a reply to message #1714443] Thu, 12 November 2015 17:14 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
Right

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtend-Metamodel
Next Topic:Problem by using ExecutableExtensionFactory in non-XText Plugin
Goto Forum:
  


Current Time: Fri Apr 26 16:57:49 GMT 2024

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

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

Back to the top