SusSourceSusFilter

class Filter

Provides a way to filter the registry according to the suffix on loaded paths.

A test has an identity, e.g. the file and line number on which it's defined.

A filter takes an identity, decomposes it into a file and suffix, loads the file, and registers the filter suffix.

When the filter is used to enumerate the registry, it will only return the tests that match the suffix.

Nested

Definitions

def initialize(registry = Registry.new)

Initialize a new Filter.

Signature

parameter registry Registry

The registry to filter.

Implementation

def initialize(registry = Registry.new)
	@registry = registry
	@index = nil
	@keys = Array.new
end

def load(target)

Load a target path, optionally with a filter suffix.

Signature

parameter target String

The target path, optionally with a ":suffix" filter.

Implementation

def load(target)
	path, filter = target.split(":", 2)
	
	@registry.load(path)
	
	if filter
		@keys << target
	end
end

def each(&block)

Iterate over filtered test cases.

Signature

yields {|test| ...}

Each test case that matches the filter.

Implementation

def each(&block)
	if @keys.any?
		@index = Index.new
		@index.add(@registry)
		
		@keys.each do |key|
			if target = @index[key]
				yield target
			end
		end
	else
		@registry.each(&block)
	end
end

def call(assertions = Assertions.default)

Execute filtered tests.

Signature

parameter assertions Assertions

Optional assertions instance to use.

returns Assertions

The assertions instance with results.

Implementation

def call(assertions = Assertions.default)
	if @keys.any?
		@index = Index.new
		@index.add(@registry)
		
		@keys.each do |key|
			@index[key]&.call(assertions)
		end
	else
		@registry.call(assertions)
	end
	
	return assertions
end