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 11:40 Go to next message
Cristiano Gaviao is currently offline Cristiano Gaviao
Messages: 245
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 11:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 4387
Registered: July 2009
Senior Member
Hi,

simply injecting the serializer and call it doesnt work?

~Christian
Re: How to test a formatting with xtend? [message #909240 is a reply to message #909139] Thu, 06 September 2012 15:46 Go to previous messageGo to next message
Cristiano Gaviao is currently offline Cristiano Gaviao
Messages: 245
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 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 4387
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
Re: How to test a formatting with xtend? [message #909320 is a reply to message #909253] Thu, 06 September 2012 20:03 Go to previous messageGo to next message
Cristiano Gaviao is currently offline Cristiano Gaviao
Messages: 245
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 01:56 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 4387
Registered: July 2009
Senior Member
Sorry i have no idea what is going on. please file a ticket.
Previous Topic:Using Xtext's index/linking machinery in a graphical editor
Next Topic:Howto load multiple concrete syntax instances
Goto Forum:
  


Current Time: Sat May 18 16:05:30 EDT 2013

Powered by FUDForum. Page generated in 0.01790 seconds