Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zardoz89 committed Jun 6, 2020
2 parents a87c03d + cffd747 commit 8f2a434
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.3.3

* .throw must be @trusted, to allow to catch Errors
* Added .biggerOrEqualThan and .smallerOrEqualThan

# v0.3.2

* .equals and others, must be @trusted to allow to call @system opEquals
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Asserts if a value is bigger than another value. Returns the result.
10.should.be.biggerThan(1);
```

#### `bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__);`

Asserts if a value is bigger or euqal than another value. Returns the result.
```d
10.should.be.biggerOrEqualThan(1);
10.should.be.biggerOrEqualThan(10);
```

#### `bool smallerThan(U)(U other, string file = __FILE__, size_t line = __LINE__)`

Asserts if a value is smaller than another value. Returns the result.
Expand All @@ -95,6 +103,14 @@ Asserts if a value is smaller than another value. Returns the result.
false.should.be.smallerThan(true);
```

#### `bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__)`

Asserts if a value is smaller or equal than another value. Returns the result.
```d
10.should.be.smallerOrEqualThan(100);
10.should.be.smallerOrEqualThan(10);
```

#### `U include(U)(U other, string file = __FILE__, size_t line = __LINE__);`

Asserts for an input range wrapped around an `Assertion` to contain/include a
Expand Down
10 changes: 10 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
layout: default
title: Changelog
---
# v0.3.3

* .throw must be @trusted, to allow to catch Errors
* Added .biggerOrEqualThan and .smallerOrEqualThan

# v0.3.2

* .equals and others, must be @trusted to allow to call @system opEquals
* .approxEquals to do approximated equality of float types

# v0.3.1

* Make Pijamas @safe
Expand Down
25 changes: 25 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ assertion.
255.should.equal(10); // Throws an Exception "expected 255 to equal 10"
```

#### `T approxEqual(U)(U other, U maxRelDiff = 1e-2, U maxAbsDiff = 1e-05, string file = __FILE__, size_t line = __LINE__);`

Asserts for aproximated equality of float types. Returns the value wrapped around the
assertion.
```d
(1.0f).should.be.approxEqual(1.00000001);
(1.0f).should.not.be.approxEqual(1.001);
```

#### `T exist(string file = __FILE__, size_t line = __LINE__);`

Asserts whether a value exists - currently simply compares it with `null`, if it
Expand All @@ -82,6 +91,14 @@ Asserts if a value is bigger than another value. Returns the result.
10.should.be.biggerThan(1);
```

#### `bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__);`

Asserts if a value is bigger or euqal than another value. Returns the result.
```d
10.should.be.biggerOrEqualThan(1);
10.should.be.biggerOrEqualThan(10);
```

#### `bool smallerThan(U)(U other, string file = __FILE__, size_t line = __LINE__)`

Asserts if a value is smaller than another value. Returns the result.
Expand All @@ -90,6 +107,14 @@ Asserts if a value is smaller than another value. Returns the result.
false.should.be.smallerThan(true);
```

#### `bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__)`

Asserts if a value is smaller or equal than another value. Returns the result.
```d
10.should.be.smallerOrEqualThan(100);
10.should.be.smallerOrEqualThan(10);
```

#### `U include(U)(U other, string file = __FILE__, size_t line = __LINE__);`

Asserts for an input range wrapped around an `Assertion` to contain/include a
Expand Down
104 changes: 103 additions & 1 deletion docs/pijamas.html
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,57 @@ <h4>Examples</h4>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
<a href="#Assertion.biggerOrEqualThan" id="Assertion.biggerOrEqualThan"><code class="code">biggerOrEqualThan</code></a>
</div>
</div><div class="ddoc_decl">
<section class="section">
<div class="declaration">
<h4>Declaration</h4>
<div class="dlang">
<p class="para">
<code class="code">
<span class="ddoc_anchor" id="Assertion.biggerOrEqualThan"></span>@trusted bool <code class="code">biggerOrEqualThan</code>(U)(U <code class="code">other</code>, string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__);

</code>
</p>
</div>
</div>
</section>
</div>
<div class="ddoc_decl">
<section class="section ddoc_sections">
<div class="ddoc_summary">
<p class="para">
Asserts if a value is bigger or equal than another value. Returns the result.

</p>
</div>
<div class="ddoc_examples">
<h4>Examples</h4>
<p class="para">

<section class="code_listing">
<div class="code_sample">
<div class="dlang">
<ol class="code_lines">
<li><code class="code"><span class="string_literal">"z"</span>.should.be.<span class="psymbol">biggerOrEqualThan</span>(<span class="string_literal">"a"</span>);
10.should.be.<span class="psymbol">biggerOrEqualThan</span>(10);
20.should.be.<span class="psymbol">biggerOrEqualThan</span>(10);
</code></li>
</ol>
</div>
</div>
</section>

</p>
</div>
</section>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
Expand Down Expand Up @@ -950,6 +1001,57 @@ <h4>Examples</h4>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
<a href="#Assertion.smallerOrEqualThan" id="Assertion.smallerOrEqualThan"><code class="code">smallerOrEqualThan</code></a>
</div>
</div><div class="ddoc_decl">
<section class="section">
<div class="declaration">
<h4>Declaration</h4>
<div class="dlang">
<p class="para">
<code class="code">
<span class="ddoc_anchor" id="Assertion.smallerOrEqualThan"></span>@trusted bool <code class="code">smallerOrEqualThan</code>(U)(U <code class="code">other</code>, string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__);

</code>
</p>
</div>
</div>
</section>
</div>
<div class="ddoc_decl">
<section class="section ddoc_sections">
<div class="ddoc_summary">
<p class="para">
Asserts if a value is smaller or euqal than another value. Returns the result.

</p>
</div>
<div class="ddoc_examples">
<h4>Examples</h4>
<p class="para">

<section class="code_listing">
<div class="code_sample">
<div class="dlang">
<ol class="code_lines">
<li><code class="code">10.should.be.<span class="psymbol">smallerOrEqualThan</span>(100);
10.should.be.<span class="psymbol">smallerOrEqualThan</span>(10);
<span class="keyword">false</span>.should.be.<span class="psymbol">smallerOrEqualThan</span>(<span class="keyword">true</span>);
</code></li>
</ol>
</div>
</div>
</section>

</p>
</div>
</section>

</div>

</li><li class="ddoc_member">
<div class="ddoc_member_header">
<div class="ddoc_header_anchor">
Expand Down Expand Up @@ -1372,7 +1474,7 @@ <h4>Declaration</h4>
<div class="dlang">
<p class="para">
<code class="code">
<span class="ddoc_anchor" id="Assertion.Throw"></span>@safe void <code class="code">Throw</code>(T : Throwable = Exception)(string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__);
<span class="ddoc_anchor" id="Assertion.Throw"></span>@trusted void <code class="code">Throw</code>(T : Throwable = Exception)(string <code class="code">file</code> = __FILE__, size_t <code class="code">line</code> = __LINE__);

</code>
</p>
Expand Down
34 changes: 33 additions & 1 deletion source/pijamas.d
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ class Assertion(T)
return this.ok(context > other, this.message(other), file, line);
}

/**
* Asserts if a value is bigger or equal than another value. Returns the result.
*
* Examples:
* ```
* "z".should.be.biggerOrEqualThan("a");
* 10.should.be.biggerOrEqualThan(10);
* 20.should.be.biggerOrEqualThan(10);
* ```
*/
bool biggerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__) @trusted
{
operator = "be bigger or equal than";
return this.ok(context >= other, this.message(other), file, line);
}

/**
* Asserts if a value is smaller than another value. Returns the result.
*
Expand All @@ -199,6 +215,22 @@ class Assertion(T)
return this.ok(context < other, this.message(other), file, line);
}

/**
* Asserts if a value is smaller or euqal than another value. Returns the result.
*
* Examples:
* ```
* 10.should.be.smallerOrEqualThan(100);
* 10.should.be.smallerOrEqualThan(10);
* false.should.be.smallerOrEqualThan(true);
* ```
*/
bool smallerOrEqualThan(U)(U other, string file = __FILE__, size_t line = __LINE__) @trusted
{
operator = "be smaller or equal than";
return this.ok(context <= other, this.message(other), file, line);
}

static if (isForwardRange!T && __traits(compiles, context.isSorted))
{
/**
Expand Down Expand Up @@ -395,7 +427,7 @@ class Assertion(T)
* should(&notThrowing).not.Throw;
* ```
*/
void Throw(T : Throwable = Exception)(string file = __FILE__, size_t line = __LINE__) @safe
void Throw(T : Throwable = Exception)(string file = __FILE__, size_t line = __LINE__) @trusted
{
operator = "throw";
bool thrown = false;
Expand Down
6 changes: 6 additions & 0 deletions tests/pijamas_spec.d
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ import pijamas;
a2.should.be.biggerThan("aaa");
a2.should.not.be.biggerThan("zz");
assertThrown!Exception(a2.should.be.biggerThan("zz"));

10.should.be.biggerOrEqualThan(10);
50.should.be.biggerOrEqualThan(10);
}
}

Expand All @@ -431,5 +434,8 @@ import pijamas;
a2.should.be.smallerThan(2000);
a2.should.be.not.smallerThan(99);
assertThrown!Exception(a2.should.be.smallerThan(99));

10.should.be.smallerOrEqualThan(10);
10.should.be.smallerOrEqualThan(50);
}
}

0 comments on commit 8f2a434

Please sign in to comment.