package org.erlide.erlang; import com.google.inject.Inject; import org.eclipse.emf.common.util.EList; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.junit4.InjectWith; import org.eclipse.xtext.junit4.XtextRunner; import org.eclipse.xtext.junit4.util.ParseHelper; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Extension; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.erlide.ErlangInjectorProvider; import org.erlide.erlang.Expression; import org.erlide.erlang.Expressions; import org.erlide.erlang.Function; import org.erlide.erlang.FunctionClause; import org.erlide.erlang.ModelExtensions; import org.erlide.erlang.Module; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(XtextRunner.class) @InjectWith(ErlangInjectorProvider.class) @SuppressWarnings("all") public class ElementExtensionsTest { @Inject private ParseHelper<Module> parser; @Inject @Extension private ModelExtensions _modelExtensions; @Test public void getModule() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("-module(x)."); _builder.newLine(); _builder.append("-export([ff/0])."); _builder.newLine(); _builder.append("ff() -> ok."); _builder.newLine(); _builder.append("gg() -> ok."); _builder.newLine(); final Module module = this.parser.parse(_builder); final Function ff = this._modelExtensions.getFunction(module, "ff", 0); Module _owningModule = this._modelExtensions.getOwningModule(ff); Matcher<? super Module> _is = Matchers.<Module>is(module); MatcherAssert.<Module>assertThat(_owningModule, _is); EList<FunctionClause> _clauses = ff.getClauses(); FunctionClause _head = IterableExtensions.<FunctionClause>head(_clauses); Expressions _body = _head.getBody(); EList<Expression> _exprs = _body.getExprs(); final Expression fexpr = IterableExtensions.<Expression>head(_exprs); Module _owningModule_1 = this._modelExtensions.getOwningModule(fexpr); Matcher<? super Module> _is_1 = Matchers.<Module>is(module); MatcherAssert.<Module>assertThat(_owningModule_1, _is_1); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } }