/* * Copyright (C) 2014-2017 the original authors or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package io.sarl.lang.tests.general.compilation.oop; import com.google.inject.Inject; import org.eclipse.xtext.xbase.testing.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; import io.sarl.lang.SARLVersion; import io.sarl.lang.sarl.SarlPackage; import io.sarl.tests.api.AbstractSarlTest; /** * @author $Author: sgalland$ * @version $Name$ $Revision$ $Date$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ @RunWith(Suite.class) @SuiteClasses({ EnumCompilerTest.TopLevelTest.class, EnumCompilerTest.InClassTest.class, EnumCompilerTest.InAgentTest.class, }) @SuppressWarnings("all") public class EnumCompilerTest { public static class TopLevelTest extends AbstractSarlTest { @Inject private CompilationTestHelper compiler; @Test public void basic() throws Exception { String source = "enum E1 { CST1, CST2 }"; String expected = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_ENUMERATION + ")", "@SuppressWarnings(\"all\")", "public enum E1 {", " CST1,", " ", " CST2;", "}", "" ); this.compiler.assertCompilesTo(source, expected); } } public static class InClassTest extends AbstractSarlTest { @Inject private CompilationTestHelper compiler; @Test public void basic() throws Exception { String source = "class Container { enum E1 { CST1, CST2 } }"; String expected = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_CLASS + ")", "@SuppressWarnings(\"all\")", "public class Container {", " @SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", " @SarlElementType(" + SarlPackage.SARL_ENUMERATION + ")", " public enum E1 {", " CST1,", " ", " CST2;", " }", " ", " @SyntheticMember", " public Container() {", " super();", " }", "}", "" ); this.compiler.assertCompilesTo(source, expected); } } public static class InAgentTest extends AbstractSarlTest { @Inject private CompilationTestHelper compiler; @Test public void basic() throws Exception { String source = "agent Container { enum E1 { CST1, CST2 } }"; String expected = multilineString( "import io.sarl.lang.annotation.SarlElementType;", "import io.sarl.lang.annotation.SarlSpecification;", "import io.sarl.lang.annotation.SyntheticMember;", "import io.sarl.lang.core.Agent;", "import io.sarl.lang.core.BuiltinCapacitiesProvider;", "import java.util.UUID;", "import javax.inject.Inject;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SarlElementType(" + SarlPackage.SARL_AGENT + ")", "@SuppressWarnings(\"all\")", "public class Container extends Agent {", " @SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", " @SarlElementType(" + SarlPackage.SARL_ENUMERATION + ")", " protected enum E1 {", " CST1,", " ", " CST2;", " }", " ", " @SyntheticMember", " public Container(final UUID arg0, final UUID arg1) {", " super(arg0, arg1);", " }", " ", " @SyntheticMember", " @Inject", " public Container(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {", " super(arg0, arg1, arg2);", " }", "}", "" ); this.compiler.assertCompilesTo(source, expected); } } }