This commit is contained in:
Michael Miller 2021-04-26 17:11:53 -06:00
parent 5dfc60d4cd
commit 6c98d7107c
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 16 additions and 4 deletions

View file

@ -1,14 +1,19 @@
module Spectator
# Equals and matches everything.
# All comparison methods will always return true.
struct Anything
def ==(other)
# Returns true for equality.
def ==(_other)
true
end
def ===(other)
# Returns true for case equality.
def ===(_other)
true
end
def =~(other)
# Returns true for matching.
def =~(_other)
true
end
end

View file

@ -4,10 +4,17 @@
# This type is intentionally outside the `Spectator` module.
# The reason for this is to prevent name collision when using the DSL to define a spec.
abstract class SpectatorContext
# Produces a dummy string to represent the context as a string.
# This prevents the default behavior, which normally stringifies instance variables.
# Due to the sheer amount of types Spectator can create
# and that the Crystal compiler instantiates a `#to_s` and/or `#inspect` for each of those types,
# an explosion in method instances can be created.
# The compile time is drastically reduced by using a dummy string instead.
def to_s(io)
io << "Context"
end
# :ditto:
def inspect(io)
io << "Context<"
io << self.class

View file

@ -1,7 +1,7 @@
require "json"
module Spectator
# Define the file and line number something originated from.
# Defines the file and line numbers something originated from.
struct Source
# Absolute file path.
getter file : String