mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial implementation of tag filtering
This commit is contained in:
parent
38ea2e7f96
commit
b79dd4361e
3 changed files with 30 additions and 0 deletions
|
@ -5,6 +5,7 @@ require "../line_node_filter"
|
|||
require "../location"
|
||||
require "../location_node_filter"
|
||||
require "../name_node_filter"
|
||||
require "../tag_node_filter"
|
||||
|
||||
module Spectator
|
||||
class Config
|
||||
|
@ -105,6 +106,7 @@ module Spectator
|
|||
example_option(parser, builder)
|
||||
line_option(parser, builder)
|
||||
location_option(parser, builder)
|
||||
tag_option(parser, builder)
|
||||
end
|
||||
|
||||
# Adds the example filter option to the parser.
|
||||
|
@ -135,6 +137,17 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
# Adds the tag filter option to the parser.
|
||||
private def tag_option(parser, builder)
|
||||
parser.on("--tag TAG", "run examples with the specified TAG, or exclude examples by adding ~ before the TAG.") do |tag|
|
||||
negated = tag.starts_with?('~')
|
||||
tag = tag.lchop('~')
|
||||
Log.debug { "Filtering for example with tag #{tag}" }
|
||||
filter = TagNodeFilter.new(tag)
|
||||
builder.add_node_filter(filter)
|
||||
end
|
||||
end
|
||||
|
||||
# Adds options to the parser for changing output.
|
||||
private def output_parser_options(parser, builder)
|
||||
verbose_option(parser, builder)
|
||||
|
|
|
@ -51,6 +51,7 @@ require "./runner_events"
|
|||
require "./runner"
|
||||
require "./spec_builder"
|
||||
require "./spec"
|
||||
require "./tag_node_filter"
|
||||
require "./test_context"
|
||||
require "./value"
|
||||
require "./wrapper"
|
||||
|
|
16
src/spectator/tag_node_filter.cr
Normal file
16
src/spectator/tag_node_filter.cr
Normal file
|
@ -0,0 +1,16 @@
|
|||
require "./node_filter"
|
||||
|
||||
module Spectator
|
||||
# Filter that matches nodes with a given tag.
|
||||
class TagNodeFilter < NodeFilter
|
||||
# Creates the filter.
|
||||
# The *tag* indicates which tag the node must have in its metadata.
|
||||
def initialize(@tag : String)
|
||||
end
|
||||
|
||||
# Checks whether the node satisfies the filter.
|
||||
def includes?(node) : Bool
|
||||
node.metadata.each_key.any? { |key| key.to_s == @tag }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue