/*
 * $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.bugs.to00999;

import static io.sarl.tests.api.tools.TestAssertions.assertEqualsExceptNewLines;
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.TestUtils.multilineString2;
import static io.sarl.tests.api.tools.TestValidator.validate;

import org.eclipse.xtext.xbase.testing.CompilationTestHelper;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import com.google.inject.Inject;

import io.sarl.lang.core.SARLVersion;
import io.sarl.lang.sarl.SarlPackage;
import io.sarl.lang.sarl.SarlScript;
import io.sarl.lang.tests.api.AbstractSarlTest;
import io.sarl.tests.api.tools.TestValidator.Validator;

/** Testing class for issue: Guards are not evaluated when the event is fired across multiple kernels.
 *
 * <p>https://github.com/sarl/sarl/issues/885
 *
 * @author $Author: sgalland$
 * @author $Author: alombard$
 * @version $Name$ $Revision$ $Date$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 * @see "https://github.com/sarl/sarl/issues/885"
 */
@DisplayName("Bug #885")
@SuppressWarnings("all")
@Tag("core")
@Tag("compileToJava")
public class Bug885Test extends AbstractSarlTest {

	@Inject
	private CompilationTestHelper compiler;

	private static final String SNIPSET_LOCAL_PARAMETER = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent Boot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>, p : Address) {",
			"    f [ it.UUID == p.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_LOCAL_PARAMETER = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s, final Address p) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = p.getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, p.getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingLocalParameter() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_LOCAL_PARAMETER, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_LOCAL_PARAMETER, actual);
		});
	}

	private static final String SNIPSET_LOCAL_VARIABLE = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent Boot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    var p : Address = null",
			"    f [ it.UUID == p.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_LOCAL_VARIABLE = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    Address p = null;",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = p.getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, p.getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingLocalVariable() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET02);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_LOCAL_VARIABLE, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_LOCAL_VARIABLE, actual);
		});
	}

	private static final String SNIPSET_FIELD = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent Boot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  var p : Address = null",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == p.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_FIELD = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  private Address p = null;",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = Boot.this.p.getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @Override",
			"  @Pure",
			"  @SyntheticMember",
			"  public boolean equals(final Object obj) {",
			"    return super.equals(obj);",
			"  }",
			"",
			"  @Override",
			"  @Pure",
			"  @SyntheticMember",
			"  public int hashCode() {",
			"    int result = super.hashCode();",
			"    return result;",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingField() throws Exception {
		SarlScript mas = file(getParseHelper(), SNIPSET_FIELD);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();
		this.compiler.compile(SNIPSET_FIELD, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_FIELD, actual);
		});
	}

	private static final String SNIPSET_SUPER_FIELD = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent SuperBoot {",
			"  protected var p : Address = null",
			"}",
			"agent Boot extends SuperBoot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == p.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_SUPER_FIELD = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends SuperBoot {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = Boot.this.p.getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingSuperField() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET04);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_SUPER_FIELD, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_SUPER_FIELD, actual);
		});
	}

	private static final String SNIPSET_LOCAL_FUNCTION_01 = multilineString2(false,
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent Boot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == callF.UUID ]",
			"  }",
			"  def callF : Address { null }",
			"}");

	private static final String EXPECTED_LOCAL_FUNCTION_01 = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = Boot.this.callF().getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF().getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @Pure",
			"  protected Address callF() {",
			"    return null;",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingLocalFunction_01() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_LOCAL_FUNCTION_01, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_LOCAL_FUNCTION_01, actual);
		});
	}

	private static final String SNIPSET_LOCAL_FUNCTION_02 = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"import java.util.UUID",
			"",
			"agent Boot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == callF ]",
			"  }",
			"  def callF : UUID { null }",
			"}");

	private static final String EXPECTED_LOCAL_FUNCTION_02 = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_callF;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_callF) {",
			"        this.$_callF = $_callF;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_callF);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _callF = Boot.this.callF();",
			"        return Objects.equals(_uUID, _callF);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @Pure",
			"  protected UUID callF() {",
			"    return null;",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingLocalFunction_02() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_LOCAL_FUNCTION_02, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_LOCAL_FUNCTION_02, actual);
		});
	}

	private static final String SNIPSET_SUPER_FUNCTION_01 = multilineString2(false,
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"agent SuperBoot {",
			"  def callF : Address { null }",
			"}",
			"agent Boot extends SuperBoot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == callF.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_SUPER_FUNCTION_01 = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends SuperBoot {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = Boot.this.callF().getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF().getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingSuperFunction_01() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_SUPER_FUNCTION_01, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_SUPER_FUNCTION_01, actual);
		});
	}

	private static final String SNIPSET_SUPER_FUNCTION_02 = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"import java.util.UUID",
			"",
			"agent SuperBoot {",
			"  def callF : UUID { null }",
			"}",
			"agent Boot extends SuperBoot {",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == callF ]",
			"  }",
			"}");

	private static final String EXPECTED_SUPER_FUNCTION_02 = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends SuperBoot {",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_callF;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_callF) {",
			"        this.$_callF = $_callF;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_callF);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _callF = Boot.this.callF();",
			"        return Objects.equals(_uUID, _callF);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingSuperFunction_02() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_SUPER_FUNCTION_02, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_SUPER_FUNCTION_02, actual);
		});
	}

	private static final String SNIPSET_EXTENSION_FIELD = multilineString(
			"package io.sarl.lang.tests.bug885",
			"import io.sarl.lang.core.Scope",
			"import io.sarl.lang.core.Address",
			"",
			"class Provider {",
			"  def callF : Address { null }",
			"}",
			"agent Boot {",
			"  extension var p : Provider",
			"  def f(s : Scope<Address>) {",
			"  }",
			"  def f2(s : Scope<Address>) {",
			"    f [ it.UUID == callF.UUID ]",
			"  }",
			"}");

	private static final String EXPECTED_EXTENSION_FIELD = multilineString2(false,
			"package io.sarl.lang.tests.bug885;",
			"",
			"import io.sarl.lang.core.Address;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.DynamicSkillProvider;",
			"import io.sarl.lang.core.Scope;",
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.util.SerializableProxy;",
			"import jakarta.inject.Inject;",
			"import java.io.ObjectStreamException;",
			"import java.util.Objects;",
			"import java.util.UUID;",
			"import org.eclipse.xtext.xbase.lib.Extension;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class Boot extends Agent {",
			"  @Extension",
			"  private Provider p;",
			"",
			"  protected void f(final Scope<Address> s) {",
			"  }",
			"",
			"  protected void f2(final Scope<Address> s) {",
			"    class $SerializableClosureProxy implements Scope<Address> {",
			"      ",
			"      private final UUID $_uUID;",
			"      ",
			"      public $SerializableClosureProxy(final UUID $_uUID) {",
			"        this.$_uUID = $_uUID;",
			"      }",
			"      ",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        return Objects.equals(_uUID, $_uUID);",
			"      }",
			"    }",
			"    final Scope<Address> _function = new Scope<Address>() {",
			"      @Override",
			"      public boolean matches(final Address it) {",
			"        UUID _uUID = it.getID();",
			"        UUID _uUID_1 = Boot.this.p.callF().getID();",
			"        return Objects.equals(_uUID, _uUID_1);",
			"      }",
			"      private Object writeReplace() throws ObjectStreamException {",
			"        return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.callF().getID());",
			"      }",
			"    };",
			"    this.f(_function);",
			"  }",
			"",
			"  @Override",
			"  @Pure",
			"  @SyntheticMember",
			"  public boolean equals(final Object obj) {",
			"    return super.equals(obj);",
			"  }",
			"",
			"  @Override",
			"  @Pure",
			"  @SyntheticMember",
			"  public int hashCode() {",
			"    int result = super.hashCode();",
			"    return result;",
			"  }",
			"",
			"  @SyntheticMember",
			"  public Boot(final UUID arg0, final UUID arg1) {",
			"    super(arg0, arg1);",
			"  }",
			"",
			"  @SyntheticMember",
			"  @Inject",
			"  public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
			"    super(arg0, arg1, arg2);",
			"  }",
			"}",
			"");

	@Test
	public void compilingExtensionField() throws Exception {
		/*SarlScript mas = file(getParseHelper(), SNIPSET01);
		final Validator validator = validate(getValidationHelper(), getInjector(), mas);
		validator.assertNoErrors();*/
		this.compiler.compile(SNIPSET_EXTENSION_FIELD, (it) -> {
			String actual;
			actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
			assertEqualsExceptNewLines(EXPECTED_EXTENSION_FIELD, actual);
		});
	}

