package com.sap.furcas.parser.tcs.scenario;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.util.Collection;
import org.junit.BeforeClass;
import org.junit.Test;
import com.sap.furcas.parsergenerator.TCSSyntaxContainerBean;
import com.sap.furcas.runtime.parser.ParserFacade;
import com.sap.furcas.runtime.parser.testbase.GeneratedParserBasedTest;
import com.sap.furcas.runtime.parser.testbase.GeneratedParserTestConfiguration;
import com.sap.furcas.runtime.parser.testbase.stubs.StubModelAdapter;
import com.sap.furcas.runtime.parser.testbase.stubs.StubModelElement;
import com.sap.furcas.runtime.parser.testbase.stubs.StubParsingHelper;
import com.sap.furcas.test.fixture.ScenarioFixtureData;
/**
* Simple Test for the custom BibText language
*/
public class TestBibTextModes extends GeneratedParserBasedTest {
private static final String LANGUAGE = "BibtextModes";
private static final File TCS = ScenarioFixtureData.BIBTEXT_MODES_TCS;
private static final File[] METAMODELS = { ScenarioFixtureData.BIBTEXT_METAMODEL, ScenarioFixtureData.BIBTEXT1_METAMODEL };
private static StubParsingHelper parsingHelper;
@BeforeClass
public static void setupParser() throws Exception {
GeneratedParserTestConfiguration testConfig = new GeneratedParserTestConfiguration(LANGUAGE, TCS, METAMODELS);
TCSSyntaxContainerBean syntaxBean = parseSyntax(testConfig);
ParserFacade facade = generateParserForLanguage(syntaxBean, testConfig, new ClassLookupImpl());
parsingHelper = new StubParsingHelper(facade);
}
/**
* Tests references are set, this protects against bugs relating to naming of classes.
*
* @throws Exception
*/
@Test
public void testReference() throws Exception {
String sample = "article{" + " Testing, \"John Doe\" " + "} ;" + "author = \"John Doe\";";
StubModelAdapter stubModelHandler = parsingHelper.parseString(sample, 0);
Collection<StubModelElement> authors = stubModelHandler.getElementsOfType("BibText::Author");
assertEquals(1, authors.size());
StubModelElement johnDoe = authors.iterator().next();
Collection<StubModelElement> articles = stubModelHandler.getElementsOfType("BibText::Article");
assertEquals(1, articles.size());
StubModelElement article = articles.iterator().next();
// now check the reference was set using the right property name
// assertNotNull(johnDoe.get("articles")); StubModelHandler not powerful enough
assertNotNull(article.get("author"));
assertEquals(johnDoe, article.get("author"));
}
/**
* */
@Test
public void testSingleAuthor() throws Exception {
// in this special syntax, a single author must not have a ';' in the end
String sample = "author = \"John Doe\"";
StubModelAdapter stubModelHandler = parsingHelper.parseString(sample, 0);
Collection<StubModelElement> authors = stubModelHandler.getElementsOfType("BibText::Author");
assertEquals(1, authors.size());
}
/**
* */
@Test
public void testSingleArticle() throws Exception {
// in this special syntax, a single author must not have a ';' in the end
String sample = "article {" + " Testing }";
StubModelAdapter stubModelHandler = parsingHelper.parseString(sample, 0);
Collection<StubModelElement> articles = stubModelHandler.getElementsOfType("BibText::Article");
assertEquals(1, articles.size());
}
}