/*
 * $Id$
 *
 * SARL is an general-purpose agent programming language.
 * More details on http://www.sarl.io
 *
 * Copyright (C) 2014-2026 SARL.io, the original authors and main 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.parsing.general;

import static io.sarl.lang.tests.api.tools.TestAssertions.assertParameterDefaultValues;
import static io.sarl.tests.api.tools.TestAssertions.assertNoParameterVarArg;
import static io.sarl.tests.api.tools.TestAssertions.assertParameterNames;
import static io.sarl.tests.api.tools.TestAssertions.assertParameterTypes;
import static io.sarl.tests.api.tools.TestAssertions.assertParameterVarArg;
import static io.sarl.tests.api.tools.TestAssertions.assertTypeReferenceIdentifier;
import static io.sarl.tests.api.tools.TestAssertions.assertTypeReferenceIdentifiers;
import static io.sarl.tests.api.tools.TestEObjects.file;
import static io.sarl.tests.api.tools.TestUtils.multilineString;
import static io.sarl.tests.api.tools.TestValidator.validate;
import static org.eclipse.xtext.xbase.validation.IssueCodes.CLASS_MUST_BE_ABSTRACT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.base.Strings;
import org.eclipse.xtext.diagnostics.Diagnostic;
import org.eclipse.xtext.xbase.XNumberLiteral;
import org.eclipse.xtext.xbase.XStringLiteral;
import org.eclipse.xtext.xbase.XbasePackage;
import org.eclipse.xtext.xbase.validation.IssueCodes;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.sarl.lang.sarl.SarlAction;
import io.sarl.lang.sarl.SarlAgent;
import io.sarl.lang.sarl.SarlBehavior;
import io.sarl.lang.sarl.SarlCapacity;
import io.sarl.lang.sarl.SarlConstructor;
import io.sarl.lang.sarl.SarlPackage;
import io.sarl.lang.sarl.SarlScript;
import io.sarl.lang.sarl.SarlSkill;
import io.sarl.lang.tests.api.AbstractSarlTest;

/**
 * @author $Author: sgalland$
 * @version $Name$ $Revision$ $Date$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 */
@SuppressWarnings("all")
@DisplayName("Syntax: parameter default values")
@Tag("core")
public class ArgDefaultValueParsingTest extends AbstractSarlTest {

	@Nested
	public class AgentAction extends AbstractSarlTest {

		@Test
		@Tag("sarlParsing")
		public void action_1p() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg : int=4) {",
					"System.^out.println(arg)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg");
			assertParameterTypes(action.getParameters(), "int");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4");
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlValidation")
		public void action_1p_invalid1() throws Exception {
			SarlScript mas = file(getParseHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg : int=4*) {",
					"System.out.println(arg)",
					"}",
					"}"
					));
			validate(getValidationHelper(), getInjector(), mas).assertError(
					SarlPackage.eINSTANCE.getSarlAction(),
					Diagnostic.SYNTAX_DIAGNOSTIC,
					"no viable alternative at input");
		}

		@Test
		@Tag("sarlValidation")
		public void action_1p_invalid2() throws Exception {
			SarlScript mas = file(getParseHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg : int*=4) {",
					"System.out.println(arg)",
					"}",
					"}"
					));
			validate(getValidationHelper(), getInjector(), mas).assertError(
					SarlPackage.eINSTANCE.getSarlAction(),
					Diagnostic.SYNTAX_DIAGNOSTIC,
					"mismatched input '*=' expecting ')'");
		}

		@Test
		@Tag("sarlParsing")
		public void action_1p_returnValue() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg : int=4) : boolean {",
					"System.^out.println(arg)",
					"return true",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg");
			assertParameterTypes(action.getParameters(), "int");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4");
			assertTypeReferenceIdentifier(action.getReturnType(), "boolean");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int, arg4 : String) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, null, null, null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_1() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int, arg1 : String=\"abc\", arg2 : int, arg3 : int, arg4 : String) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), null, XStringLiteral.class, "abc", null, null, null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_2() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"	def myaction(arg0 : int, arg1 : String, arg2 : int=18, arg3 : int, arg4 : String) {",
					"		System.^out.println(arg0)",
					"	}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), null, null, XNumberLiteral.class, "18", null, null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_3() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int, arg1 : String, arg2 : int, arg3 : int = 34, arg4 : String) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), null, null, null, XNumberLiteral.class, "34", null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_4() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int, arg1 : String, arg2 : int, arg3 : int, arg4 : String=\"xyz\") {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), null, null, null, null, XStringLiteral.class, "xyz");
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0_3() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int=56, arg4 : String) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, null, XNumberLiteral.class, "56", null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0_3_4() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int=56, arg4 : String=\"def\") {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, null, XNumberLiteral.class, "56", XStringLiteral.class, "def");
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0_2_4() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String, arg2 : int=18, arg3 : int, arg4 : String=\"def\") {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", null, XNumberLiteral.class, "18", null, XStringLiteral.class, "def");
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0_1_2_3() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String=\"ghj\", arg2 : int=18, arg3 : int=98, arg4 : String) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", XStringLiteral.class, "ghj", XNumberLiteral.class, "18", XNumberLiteral.class, "98", null);
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_5p_0_1_2_3_4() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=4, arg1 : String=\"ghj\", arg2 : int=18, arg3 : int=98, arg4 : String=\"klm\") {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(action.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(action.getParameters(), XNumberLiteral.class, "4", XStringLiteral.class, "ghj", XNumberLiteral.class, "18", XNumberLiteral.class, "98", XStringLiteral.class, "klm");
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlValidation")
		public void action_3p_vararg_2() throws Exception {
			SarlScript mas = file(getParseHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int, arg1 : int, arg2 : int=45*) {",
					"System.out.println(arg0)",
					"}",
					"}"
					));
			validate(getValidationHelper(), getInjector(), mas).assertError(
					SarlPackage.eINSTANCE.getSarlAction(),
					Diagnostic.SYNTAX_DIAGNOSTIC,
					"no viable alternative at input");
		}

		@Test
		@Tag("sarlParsing")
		public void action_3p_vararg_1() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"	def myaction(arg0 : int, arg1 : int=45, arg2 : int*) {",
					"		System.^out.println(arg0)",
					"	}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2");
			assertParameterTypes(action.getParameters(), "int", "int", "int");
			assertParameterDefaultValues(action.getParameters(),
					null,
					XNumberLiteral.class, "45",
					null);
			assertParameterVarArg(action.getParameters());
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_3p_vararg_0() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"	def myaction(arg0 : int=45, arg1 : int, arg2 : int*) {",
					"		System.^out.println(arg0)",
					"	}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2");
			assertParameterTypes(action.getParameters(), "int", "int", "int");
			assertParameterDefaultValues(action.getParameters(),
					XNumberLiteral.class, "45",
					null,
					null);
			assertParameterVarArg(action.getParameters());
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void action_3p_vararg_0_1() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"def myaction(arg0 : int=45, arg1 : int=56, arg2 : int*) {",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(1, agent.getMembers().size());
			//
			SarlAction action = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action.getName());
			assertTypeReferenceIdentifiers(action.getFiredEvents());
			assertParameterNames(action.getParameters(), "arg0", "arg1", "arg2");
			assertParameterTypes(action.getParameters(), "int", "int", "int");
			assertParameterDefaultValues(action.getParameters(),
					XNumberLiteral.class, "45",
					XNumberLiteral.class, "56",
					null);
			assertParameterVarArg(action.getParameters());
			assertTypeReferenceIdentifier(action.getReturnType(), "void");
		}

		@Test
		@Tag("sarlParsing")
		public void multipleActionDefinitionsInAgent() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"agent A1 {",
					"	def myaction(arg0 : int, arg1 : int=42, arg2 : int*) {",
					"		System.^out.println(\"valid\")",
					"	}",
					"	def myaction(arg0 : int, arg1 : int*) {",
					"		System.^out.println(\"invalid\")",
					"	}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlAgent agent = (SarlAgent) mas.getXtendTypes().get(0);
			assertEquals("A1", agent.getName());
			assertNull(agent.getExtends());
			assertEquals(2, agent.getMembers().size());
			//
			SarlAction action1 = (SarlAction) agent.getMembers().get(0);
			assertEquals("myaction", action1.getName());
			assertTypeReferenceIdentifiers(action1.getFiredEvents());
			assertParameterNames(action1.getParameters(), "arg0", "arg1", "arg2");
			assertParameterTypes(action1.getParameters(), "int", "int", "int");
			assertParameterDefaultValues(action1.getParameters(),
					null,
					XNumberLiteral.class, "42",
					null);
			assertParameterVarArg(action1.getParameters());
			assertTypeReferenceIdentifier(action1.getReturnType(), "void");
			//
			SarlAction action2 = (SarlAction) agent.getMembers().get(1);
			assertEquals("myaction", action2.getName());
			assertTypeReferenceIdentifiers(action2.getFiredEvents());
			assertParameterNames(action2.getParameters(), "arg0", "arg1");
			assertParameterTypes(action2.getParameters(), "int", "int");
			assertParameterDefaultValues(action2.getParameters(),
					null,
					null);
			assertParameterVarArg(action2.getParameters());
			assertTypeReferenceIdentifier(action2.getReturnType(), "void");
		}

	}

	@Nested
	public class BehaviorConstructor extends AbstractSarlTest {

		@Test
		@Tag("sarlParsing")
		public void constructor_1p() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg : int=4) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg");
			assertParameterTypes(constructor.getParameters(), "int");
			assertParameterDefaultValues(constructor.getParameters(), XNumberLiteral.class, "4");
		}

		@Test
		@Tag("sarlValidation")
		public void constructor_1p_invalid1() throws Exception {
			SarlScript mas = file(getParseHelper(), multilineString(
					"behavior B1 {",
					"new(arg : int=4*) {",
					"System.out.println(arg)",
					"}",
					"}"
					));
			validate(getValidationHelper(), getInjector(), mas).assertError(
					SarlPackage.eINSTANCE.getSarlConstructor(),
					Diagnostic.SYNTAX_DIAGNOSTIC,
					"no viable alternative at input");
		}

		@Test
		@Tag("sarlValidation")
		public void constructor_1p_invalid2() throws Exception {
			SarlScript mas = file(getParseHelper(), multilineString(
					"behavior B1 {",
					"new(arg : int*=4) {",
					"System.out.println(arg)",
					"}",
					"}"
					));
			validate(getValidationHelper(), getInjector(), mas).assertError(
					SarlPackage.eINSTANCE.getSarlConstructor(),
					Diagnostic.SYNTAX_DIAGNOSTIC,
					"mismatched input '*=' expecting ')'");
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_0() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int, arg4 : String) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), XNumberLiteral.class, "4", null, null, null, null);
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_1() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int, arg1 : String=\"abc\", arg2 : int, arg3 : int, arg4 : String) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), null, XStringLiteral.class, "abc", null, null, null);
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_2() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int, arg1 : String, arg2 : int=18, arg3 : int, arg4 : String) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), null, null, XNumberLiteral.class, "18", null, null);
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_3() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int, arg1 : String, arg2 : int, arg3 : int = 34, arg4 : String) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), null, null, null, XNumberLiteral.class, "34", null);
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_4() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int, arg1 : String, arg2 : int, arg3 : int, arg4 : String=\"xyz\") {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), null, null, null, null, XStringLiteral.class, "xyz");
		}

		@Test
		@Tag("sarlParsing")
		public void constructor_5p_0_3() throws Exception {
			SarlScript mas = file(getParseHelper(), getValidationHelper(), multilineString(
					"behavior B1 {",
					"new(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int=56, arg4 : String) {",
					"super(null) // must be never null during runtime",
					"System.^out.println(arg0)",
					"}",
					"}"
					));
			assertEquals(1, mas.getXtendTypes().size());
			//
			assertTrue(Strings.isNullOrEmpty(mas.getPackage()));
			//
			SarlBehavior behavior = (SarlBehavior) mas.getXtendTypes().get(0);
			assertEquals("B1", behavior.getName());
			assertNull(behavior.getExtends());
			assertEquals(1, behavior.getMembers().size());
			//
			SarlConstructor constructor = (SarlConstructor) behavior.getMembers().get(0);
			assertParameterNames(constructor.getParameters(), "arg0", "arg1", "arg2", "arg3", "arg4");
			assertParameterTypes(constructor.getParameters(), "int", "java.lang.String", "int", "int", "java.lang.String");
			assertParameterDefaultValues(constructor.getParameters(), XNumberLiteral.class, "4", null, null, XNumberLiteral.class, "56", null);
		}

		@Test
		@Tag("sarlParsing")
