Skip to content

Commit

Permalink
fix issue sebastianbenz#171 Full qualified names in "should be"
Browse files Browse the repository at this point in the history
the JnarioCompiler no longer considers packageFragments as fully-fledged
sub-expressions
  • Loading branch information
riederm committed Apr 17, 2017
1 parent 48f1eeb commit 30adbbd
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 2 deletions.
13 changes: 12 additions & 1 deletion plugins/org.jnario/src/org/jnario/compiler/JnarioCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.jnario.xbase.richstring.XbaseWithRichstringCompiler;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;

Expand Down Expand Up @@ -383,10 +384,20 @@ public boolean apply(XExpression expr) {
return !expressionHelper.isLiteral(expr);
}
};
Predicate<XExpression> noPackageFragments = new Predicate<XExpression>(){
public boolean apply(XExpression expr) {
if (expr instanceof XAbstractFeatureCall){
//we don't want package fragments as fully-fledged sub-expressions
return !((XAbstractFeatureCall)expr).isPackageFragment();
}
return true;
}
};
Iterable<XExpression> subExpressions = filter(expression.eContents(), XExpression.class);

subExpressions = filter(subExpressions, noLiteralExpressions);
subExpressions = filter(subExpressions, noSwitchCases);
subExpressions = filter(subExpressions, noPackageFragments);
return subExpressions.iterator();
}

Expand Down
1 change: 1 addition & 0 deletions tests/org.jnario.tests/doc-gen/org/jnario/JnarioSuite.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ <h1>Jnario</h1>
<li><a class="specref pending" href="../../org/jnario/spec/tests/integration/MockingSpec.html">Mocking</a> <strong class="icon pending">~</strong></li>
<li><a class="specref notrun" href="../../org/jnario/spec/tests/unit/naming/OperationNameProviderSpec.html">OperationNameProvider</a></li>
<li><a class="specref notrun" href="../../org/jnario/spec/tests/integration/PendingSpec.html">Pending</a></li>
<li><a class="specref pending" href="../../org/jnario/spec/tests/unit/compiler/QualfiedReferencesInShouldBeSpec.html">Qualfied References in should be</a> <strong class="icon pending">~</strong></li>
<li><a class="specref notrun" href="../../org/jnario/spec/tests/integration/SetupTeardownSpec.html">Setup & Teardown</a></li>
<li><a class="specref notrun" href="../../org/jnario/spec/tests/integration/SpecExtensionsSpec.html">Spec Extensions</a></li>
<li><a class="specref notrun" href="../../org/jnario/spec/tests/unit/doc/SpecDocGeneratorSpec.html">SpecDocGenerator</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Qualfied References in should be</title>
<meta name="description" content="">
<meta name="author" content="Jnario">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<link rel="stylesheet" href="../../../../../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../../../../../css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="../../../../../../css/custom.css">
<link rel="stylesheet" href="../../../../../../css/prettify.css">
<script type="text/javascript" src="../../../../../../js/prettify.js"></script>
<script type="text/javascript" src="../../../../../../js/lang-jnario.js"></script>
<script type="text/javascript" src="../../../../../../js/jquery.js"></script>
<script type="text/javascript" src="../../../../../../js/bootstrap-tab.js"></script>
</head>

<body onload="prettyPrint()">
<div class="container">
<div class="tabbable">
<div class="content">
<div class="page-header pending">
<h1>Qualfied References in should be</h1>
<ul class="nav nav-tabs pull-right">
<li class="active"><a href="#spec" data-toggle="tab">Spec</a></li>
<li><a href="#source" data-toggle="tab">Source</a></li>
</ul>
</div>
<div class="row">
<div class="span12">
<div class="tab-content">
<div class="tab-pane active" id="spec">
<ul><li><p id="it_should_successfully_generate_asserts_on_QualifiedRefernces" class="example notrun"><strong>it should successfully generate asserts on QualifiedRefernces</strong></p>
<pre class="prettyprint lang-spec linenums">
java.lang.System =&gt; java.lang.System
java.lang.System should be java.lang.System

java.lang.System should not be java.lang.String</pre>
</li><li><p id="it_should_successfully_generate_asserts_on_members_of_QualifiedRefernces" class="example notrun"><strong>it should successfully generate asserts on members of QualifiedRefernces</strong></p>
<pre class="prettyprint lang-spec linenums">
java.lang.System.classLoader =&gt; java.lang.System.classLoader
java.lang.System.classLoader should be java.lang.System.classLoader

java.lang.String.canonicalName should not be java.lang.Integer.canonicalName</pre>
</li></ul>
</div>
<div class="tab-pane" id="source">
<h3>QualifiedReferencesInsideShouldBe.spec</h3>
<p>
<pre class="prettyprint lang-spec linenums">
package org.jnario.spec.tests.unit.compiler

describe &quot;Qualfied References in should be&quot;{

fact &quot;it should successfully generate asserts on QualifiedRefernces&quot;{
java.lang.System =&gt; java.lang.System
java.lang.System should be java.lang.System

java.lang.System should not be java.lang.String
}

fact &quot;it should successfully generate asserts on members of QualifiedRefernces&quot;{
java.lang.System.classLoader =&gt; java.lang.System.classLoader
java.lang.System.classLoader should be java.lang.System.classLoader

java.lang.String.canonicalName should not be java.lang.Integer.canonicalName
}

}
</pre>
</p></div>
</div>
</div>
</div> <!-- /row -->
</div> <!-- /content -->
</div> <!-- /tabbable -->
<footer>
<p><small>Generated by <a href="http://www.jnario.org">Jnario</a>.</small></p>
</footer>
</div> <!-- /container -->

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jnario.spec.tests.unit.compiler

describe "Qualfied References in should be"{

fact "it should successfully generate asserts on QualifiedRefernces"{
java.lang.System => java.lang.System
java.lang.System should be java.lang.System

java.lang.System should not be java.lang.String
}

fact "it should successfully generate asserts on members of QualifiedRefernces"{
java.lang.System.classLoader => java.lang.System.classLoader
java.lang.System.classLoader should be java.lang.System.classLoader

java.lang.String.canonicalName should not be java.lang.Integer.canonicalName
}

}
3 changes: 2 additions & 1 deletion tests/org.jnario.tests/xtend-gen/org/jnario/SpecSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jnario.spec.tests.integration.UsingTablesSpec;
import org.jnario.spec.tests.integration.UsingXtendSWithOperatorSpec;
import org.jnario.spec.tests.unit.compiler.CompilerSpec;
import org.jnario.spec.tests.unit.compiler.QualfiedReferencesInShouldBeSpec;
import org.jnario.spec.tests.unit.doc.SpecDocGeneratorSpec;
import org.jnario.spec.tests.unit.naming.ExampleNameProviderSpec;
import org.jnario.spec.tests.unit.naming.ExampleSpec;
Expand All @@ -33,7 +34,7 @@
import org.junit.runner.RunWith;

@Named("Spec")
@Contains({ AnnotationsSpec.class, AssertionSpec.class, CompilerSpec.class, CustomizingTheSpecCreationSpec.class, DefiningSpecBaseClassesSpec.class, ExampleSpec.class, ExampleGroupSpec.class, ExampleNameProviderSpec.class, ImplicitSubjectSpec.class, IntroducingJnarioSpecsSpec.class, LinkerValidationSpec.class, MockingSpec.class, OperationNameProviderSpec.class, PendingSpec.class, SetupTeardownSpec.class, SpecExtensionsSpec.class, SpecDocGeneratorSpec.class, SpecExecutableProviderSpec.class, SpecJavaValidatorSpec.class, SpecQualifiedNameProviderSpec.class, SpecScopeProviderSpec.class, StaticImportsSpec.class, ThrowsSpec.class, UsingJUnitRulesInSpecsSpec.class, UsingShouldSpec.class, UsingTablesSpec.class, UsingXtendSWithOperatorSpec.class })
@Contains({ AnnotationsSpec.class, AssertionSpec.class, CompilerSpec.class, CustomizingTheSpecCreationSpec.class, DefiningSpecBaseClassesSpec.class, ExampleSpec.class, ExampleGroupSpec.class, ExampleNameProviderSpec.class, ImplicitSubjectSpec.class, IntroducingJnarioSpecsSpec.class, LinkerValidationSpec.class, MockingSpec.class, OperationNameProviderSpec.class, PendingSpec.class, QualfiedReferencesInShouldBeSpec.class, SetupTeardownSpec.class, SpecExtensionsSpec.class, SpecDocGeneratorSpec.class, SpecExecutableProviderSpec.class, SpecJavaValidatorSpec.class, SpecQualifiedNameProviderSpec.class, SpecScopeProviderSpec.class, StaticImportsSpec.class, ThrowsSpec.class, UsingJUnitRulesInSpecsSpec.class, UsingShouldSpec.class, UsingTablesSpec.class, UsingXtendSWithOperatorSpec.class })
@RunWith(ExampleGroupRunner.class)
@SuppressWarnings("all")
public class SpecSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.jnario.spec.tests.unit.compiler;

import org.jnario.lib.Assert;
import org.jnario.lib.Should;
import org.jnario.runner.ExampleGroupRunner;
import org.jnario.runner.Named;
import org.jnario.runner.Order;
import org.junit.Test;
import org.junit.runner.RunWith;

@Named("Qualfied References in should be")
@RunWith(ExampleGroupRunner.class)
@SuppressWarnings("all")
public class QualfiedReferencesInShouldBeSpec {
@Test
@Named("it should successfully generate asserts on QualifiedRefernces")
@Order(1)
public void _itShouldSuccessfullyGenerateAssertsOnQualifiedRefernces() throws Exception {
boolean _doubleArrow = Should.operator_doubleArrow(
System.class, System.class);
Assert.assertTrue("\nExpected java.lang.System => java.lang.System but"
+ "\n java.lang.System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", _doubleArrow);

boolean _should_be = Should.should_be(
System.class, System.class);
Assert.assertTrue("\nExpected java.lang.System should be java.lang.System but"
+ "\n java.lang.System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", _should_be);

Assert.assertFalse("\nExpected java.lang.System should not be java.lang.String but"
+ "\n java.lang.System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString()
+ "\n java.lang.String is " + new org.hamcrest.StringDescription().appendValue(String.class).toString() + "\n", Should.should_be(
System.class, String.class));

}

@Test
@Named("it should successfully generate asserts on members of QualifiedRefernces")
@Order(2)
public void _itShouldSuccessfullyGenerateAssertsOnMembersOfQualifiedRefernces() throws Exception {
ClassLoader _classLoader = System.class.getClassLoader();
ClassLoader _classLoader_1 = System.class.getClassLoader();
boolean _doubleArrow = Should.<ClassLoader>operator_doubleArrow(_classLoader, _classLoader_1);
Assert.assertTrue("\nExpected java.lang.System.classLoader => java.lang.System.classLoader but"
+ "\n java.lang.System.classLoader is " + new org.hamcrest.StringDescription().appendValue(_classLoader).toString()
+ "\n java.lang.System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", _doubleArrow);

ClassLoader _classLoader_2 = System.class.getClassLoader();
ClassLoader _classLoader_3 = System.class.getClassLoader();
boolean _should_be = Should.<ClassLoader>should_be(_classLoader_2, _classLoader_3);
Assert.assertTrue("\nExpected java.lang.System.classLoader should be java.lang.System.classLoader but"
+ "\n java.lang.System.classLoader is " + new org.hamcrest.StringDescription().appendValue(_classLoader_2).toString()
+ "\n java.lang.System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", _should_be);

String _canonicalName = String.class.getCanonicalName();
String _canonicalName_1 = Integer.class.getCanonicalName();
Assert.assertFalse("\nExpected java.lang.String.canonicalName should not be java.lang.Integer.canonicalName but"
+ "\n java.lang.String.canonicalName is " + new org.hamcrest.StringDescription().appendValue(_canonicalName).toString()
+ "\n java.lang.String is " + new org.hamcrest.StringDescription().appendValue(String.class).toString()
+ "\n java.lang.Integer.canonicalName is " + new org.hamcrest.StringDescription().appendValue(_canonicalName_1).toString()
+ "\n java.lang.Integer is " + new org.hamcrest.StringDescription().appendValue(Integer.class).toString() + "\n", Should.<String>should_be(_canonicalName, _canonicalName_1));

}
}

0 comments on commit 30adbbd

Please sign in to comment.