equal

The word .equal tests for equality. It takes one parameter and terminates the phrase. Its parameter is the expected value for the left-hand side of the should phrase.

  1. void equal(Should should, T expected, Fence _, string file, size_t line)
    void
    equal
    (
    Should
    T
    )
    (
    Should should
    ,,
    Fence _ = Fence()
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )
    if (
    isInstanceOf!(ShouldType, Should) &&
    !should.hasWord!"approximately"
    )
  2. auto equal(Should should)
  3. void equal(Should should, T expected, ErrorValue error, Fence _, string file, size_t line)

Examples

5.should.equal(5);
5.should.not.equal(6);
(new Object).should.not.equal(new Object);
auto obj = new Object;

obj.should.equal(obj);
obj.should.be(obj);
class SameyClass
{
    override bool opEquals(Object o) { return true; }
}

(new SameyClass).should.not.be(new SameyClass);
(new SameyClass).should.equal(new SameyClass);
const string[int] hashmap1 = [1: "2", 5: "4"];
string[int] hashmap2 = null;

hashmap2[5] = "4";
hashmap2[1] = "2";

// TODO reliable way to produce a hash collision
// assert(hashmap1.keys != hashmap2.keys, "hash collision not found"); // make sure that ordering doesn't matter

hashmap1.should.equal(hashmap2);
hashmap2.should.equal(hashmap1);
import std.range : only;

5.only.should.equal([5]);
[5].should.equal(5.only);
5.only.should.not.equal(6.only);
5.only.should.not.equal([6]);

Meta