mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add ExampleFilter class
This commit is contained in:
parent
2f8b4761de
commit
8c66f8df34
3 changed files with 110 additions and 0 deletions
24
src/spectator/example_filter.cr
Normal file
24
src/spectator/example_filter.cr
Normal file
|
@ -0,0 +1,24 @@
|
|||
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
|
||||
|
||||
# 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
|
||||
end
|
||||
end
|
|
@ -28,6 +28,7 @@ require "./config"
|
|||
require "./config_builder"
|
||||
require "./config_source"
|
||||
require "./command_line_arguments_config_source"
|
||||
require "./example_filter"
|
||||
|
||||
require "./example_failed"
|
||||
require "./expectation_failed"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue