Skip to content

Matcher operator overloads for nil(-like) literals #214

@jmper1

Description

@jmper1

How about if we define a constant (global only to Nimble):

let Nil: NilLiteralType = NilLiteral()

where NilLiteralType and NilLiteral are defined as:

protocol NilLiteralType {}
struct NilLiteral: NilLiteralType {}

and override the equality operators:

func ==<T>(lhs: Expectation<T>, nilLiteral: NilLiteralType)
{
  lhs.to(beNil())
}

func !=<T>(lhs: Expectation<T>, nilLiteral: NilLiteralType)
{
  lhs.toNot(beNil())
}

so that expressions like the following are possible:

expect(foo) == Nil
expect(bar) != Nil

I can create a PR if you don't think this is a stupid idea.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions