/*******************************************************************************
* Copyright (c) 2011 Sebastian Benz.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sebastian Benz - initial API and implementation
******************************************************************************/
/*
* generated by Xtext
*/
package de.sebastianbenz.task.parsing;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.junit.Assert;
import org.junit.Test;
import com.google.common.base.Joiner;
import de.sebastianbenz.task.Code;
import de.sebastianbenz.task.EmptyLine;
import de.sebastianbenz.task.Note;
import de.sebastianbenz.task.Project;
import de.sebastianbenz.task.Task;
import de.sebastianbenz.task.util.AbstractTest;
import de.sebastianbenz.task.util.ContentTypesMatcher;
public class ParserTest extends AbstractTest {
@Test
public void parseRootProject() throws Exception {
assertThat(parse("Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse(" Project:\n"), ContentTypesMatcher.are(Project.class));
}
@Test
public void parseRootProjectWithLineBreak() throws Exception {
assertThat(parse("Project:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse("Project-:\n"), ContentTypesMatcher.are(Project.class));
assertThat(parse("Project:\n "), ContentTypesMatcher.are(Project.class));
assertThat(parse("Project:\n "), ContentTypesMatcher.are(Project.class));
}
@Test
public void parseMixedContent() throws Exception {
assertThat(parse("note\nProject:\n"), ContentTypesMatcher.are(Note.class, Project.class));
}
@Test
public void parseOpenTask() throws Exception {
assertThat(parse("- a task\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse(" - a task\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse(" - a task\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task :\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task\n "), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task\n "), ContentTypesMatcher.are(Task.class));
}
@Test
public void parseClosedTask() throws Exception {
assertThat(parse("- a task@done\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse(" - a task @done\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse(" - a task@done\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task :@done\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task @done\n"), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task@done\n "), ContentTypesMatcher.are(Task.class));
assertThat(parse("- a task @done\n "), ContentTypesMatcher.are(Task.class));
}
@Test
public void parseDoneTag() throws Exception {
assertThat(tagsOf(firstTask(parse("- a task @done\n"))), is("@done"));
}
@Test
public void tagShouldBeginWithSpace() throws Exception {
assertThat(tagsOf(firstTask(parse("- a task@done\n"))), is(""));
}
@Test
public void parseOtherTag() throws Exception {
assertThat(tagsOf(firstTask(parse("- a task @today\n"))), is("@today"));
}
@Test
public void parseEmptyLines() throws Exception {
assertThat(parse("\nProject:\n"), ContentTypesMatcher.are(EmptyLine.class, Project.class));
assertThat(parse(" \nProject:\n"), ContentTypesMatcher.are(EmptyLine.class, Project.class));
assertThat(parse("Project:\n \n"), ContentTypesMatcher.are(Project.class, EmptyLine.class));
assertThat(parse("Project:\n\n\nProject:\n"),
ContentTypesMatcher.are(Project.class, EmptyLine.class, EmptyLine.class, Project.class));
}
@Test
public void noSyntaxErrorsOnTextWithSingleCharacter() throws Exception {
assertThat(parse("n\nProject:\n"), ContentTypesMatcher.are(Note.class, Project.class));
assertThat(parse(" n\nProject:\n"), ContentTypesMatcher.are(Note.class, Project.class));
assertThat(parse(" n \nProject:\n"), ContentTypesMatcher.are(Note.class, Project.class));
}
@Test
public void noSyntaxErrorWhenLastLineHasNoLineBreak() throws Exception {
assertThat(parse("a project:"), ContentTypesMatcher.are(Project.class));
assertThat(parse("- a task"), ContentTypesMatcher.are(Task.class));
assertThat(parse("text"), ContentTypesMatcher.are(Note.class));
}
@Test
public void parsesCode() throws Exception {
assertThat(parse("'''Here is some code'''"), ContentTypesMatcher.are(Code.class));
assertThat(parse("'''\n" +
" multiline code" +
"'''\n"), ContentTypesMatcher.are(Code.class));
}
@Test
public void codeBlockParsing() throws Exception {
URI uri = URI.createPlatformPluginURI("de.sebastianbenz.task.test/examples/SyntaxHighlightingExamples.todo", true);
Resource resource = new XtextResourceSet().getResource(uri, true);
assertTrue(Joiner.on("\n").join(resource.getErrors()), resource.getErrors().isEmpty());
}
}