mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move example filters from === to their own types
This commit is contained in:
parent
b2ab579d8a
commit
a3c1892465
11 changed files with 113 additions and 160 deletions
|
@ -59,21 +59,5 @@ module Spectator
|
|||
def to_json(json : ::JSON::Builder)
|
||||
json.string(to_s)
|
||||
end
|
||||
|
||||
# Checks if this example matches some criteria.
|
||||
# This is used to filter examples.
|
||||
def ===(other)
|
||||
other === to_s
|
||||
end
|
||||
|
||||
# Checks if this example is at the specified source.
|
||||
def ===(other : Source)
|
||||
source == other
|
||||
end
|
||||
|
||||
# Checks if this example is at the specified line number.
|
||||
def ===(other : Int32)
|
||||
source.line === other
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,24 +1,9 @@
|
|||
module Spectator
|
||||
# Checks examples to determine which should be run.
|
||||
class ExampleFilter
|
||||
# The criteria for filtering examples can be multiple types.
|
||||
# A `String` will exact-match an example's name.
|
||||
# A `Regex` will perform a regular expression match on the example's name.
|
||||
# A `Source` will check if the example is in the specified file on a given line.
|
||||
# An `Int32` will check if an example is on a given line.
|
||||
alias Type = String | Regex | Source | Int32
|
||||
|
||||
# Creates the example filter.
|
||||
# The *criteria* should be a list of what to filter on.
|
||||
def initialize(@criteria = [] of Type)
|
||||
end
|
||||
|
||||
# Base class for all example filters.
|
||||
# Checks whether an example should be run.
|
||||
# Sub-classes must implement the `#includes?` method.
|
||||
abstract class ExampleFilter
|
||||
# Checks if an example is in the filter, and should be run.
|
||||
def includes?(example)
|
||||
return true if @criteria.empty?
|
||||
@criteria.any? do |criterion|
|
||||
example === criterion
|
||||
end
|
||||
end
|
||||
abstract def includes?(example : Example) : Bool
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,11 @@ require "./config"
|
|||
require "./config_builder"
|
||||
require "./config_source"
|
||||
require "./command_line_arguments_config_source"
|
||||
|
||||
require "./example_filter"
|
||||
require "./source_example_filter"
|
||||
require "./line_example_filter"
|
||||
require "./name_example_filter"
|
||||
|
||||
require "./example_failed"
|
||||
require "./expectation_failed"
|
||||
|
|
13
src/spectator/line_example_filter.cr
Normal file
13
src/spectator/line_example_filter.cr
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Spectator
|
||||
# Filter that matches examples on a given line.
|
||||
class LineExampleFilter < ExampleFilter
|
||||
# Creates the example filter.
|
||||
def initialize(@line : Int32)
|
||||
end
|
||||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example)
|
||||
@line == example.source.line
|
||||
end
|
||||
end
|
||||
end
|
13
src/spectator/name_example_filter.cr
Normal file
13
src/spectator/name_example_filter.cr
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Spectator
|
||||
# Filter that matches examples based on their name.
|
||||
class NameExampleFilter < ExampleFilter
|
||||
# Creates the example filter.
|
||||
def initialize(@name : String)
|
||||
end
|
||||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example)
|
||||
@name == example.to_s
|
||||
end
|
||||
end
|
||||
end
|
14
src/spectator/source_example_filter.cr
Normal file
14
src/spectator/source_example_filter.cr
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Spectator
|
||||
# Filter that matches examples in a given file and line.
|
||||
class SourceExampleFilter < ExampleFilter
|
||||
# Creates the filter.
|
||||
# The *source* indicates which file and line the example must be on.
|
||||
def initialize(@source : Source)
|
||||
end
|
||||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example)
|
||||
@source === example.source
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue