Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TestPicker"
uuid = "a64165b9-4409-4de6-85cd-a4e0953bae44"
authors = ["theogf <[email protected]> and contributors"]
version = "2.1.0"
version = "2.2.0"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
68 changes: 35 additions & 33 deletions src/testblock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ struct SyntaxBlock
interface::TestBlockInterface
end

"""
TestBlockInfo

Metadata container for a test block, including its location and identification information.

Stores essential information about a test block's location within a file and provides
a label for identification and display purposes.
"""
struct TestBlockInfo
label::String
file_name::String
line_start::Int
line_end::Int
end

label(info::TestBlockInfo) = info.label
file_name(info::TestBlockInfo) = info.file_name

function TestBlockInfo(block::SyntaxBlock, file::AbstractString)
(; testblock, interface) = block
label = blocklabel(interface, testblock)
line_start, _ = JuliaSyntax.source_location(testblock.source, testblock.position)
block_length = countlines(IOBuffer(JuliaSyntax.sourcetext(testblock)))
line_end = line_start + block_length - 1
return TestBlockInfo(label, file, line_start, line_end)
end

"""
get_testblocks(interfaces::Vector{<:TestBlockInterface}, file::AbstractString) -> Vector{SyntaxBlock}

Expand All @@ -48,25 +75,25 @@ to determine what constitutes a test block.
function get_testblocks(interfaces::Vector{<:TestBlockInterface}, file::AbstractString)
root = parseall(SyntaxNode, read(file, String); filename=file)
return mapreduce(vcat, interfaces) do interface
testblocks = Vector{SyntaxBlock}()
get_testblocks!(interface, testblocks, root)
testblocks
syntax_blocks = Vector{SyntaxBlock}()
get_testblocks!(interface, syntax_blocks, root)
syntax_blocks
end
end
function get_testblocks!(
interface::TestBlockInterface,
testblocks::Vector{SyntaxBlock},
syntax_blocks::Vector{SyntaxBlock},
node::SyntaxNode,
preamble::Vector{SyntaxNode}=SyntaxNode[],
)
nodes = JuliaSyntax.children(node)
isnothing(nodes) && return nothing
for node in nodes
if istestblock(interface, node)
push!(testblocks, SyntaxBlock(copy(preamble), node, interface))
get_testblocks!(interface, testblocks, node, copy(preamble))
push!(syntax_blocks, SyntaxBlock(copy(preamble), node, interface))
get_testblocks!(interface, syntax_blocks, node, copy(preamble))
else
get_testblocks!(interface, testblocks, node, copy(preamble))
get_testblocks!(interface, syntax_blocks, node, copy(preamble))
if ispreamble(node)
push!(preamble, node)
end
Expand All @@ -93,24 +120,6 @@ function get_matching_files(
)
end

"""
TestBlockInfo

Metadata container for a test block, including its location and identification information.

Stores essential information about a test block's location within a file and provides
a label for identification and display purposes.
"""
struct TestBlockInfo
label::String
file_name::String
line_start::Int
line_end::Int
end

label(info::TestBlockInfo) = info.label
file_name(info::TestBlockInfo) = info.file_name

"""
build_info_to_syntax(interfaces, root, matched_files) -> (Dict{TestBlockInfo,SyntaxBlock}, Dict{String,TestBlockInfo})

Expand All @@ -130,14 +139,7 @@ function build_info_to_syntax(
syntax_blocks = get_testblocks(interfaces, joinpath(root, file))
Dict(
map(syntax_blocks) do syntax_block
(; testblock, interface) = syntax_block
label = blocklabel(interface, testblock)
line_start, _ = JuliaSyntax.source_location(
testblock.source, testblock.position
)
block_length = countlines(IOBuffer(JuliaSyntax.sourcetext(testblock)))
line_end = line_start + block_length - 1
TestBlockInfo(label, file, line_start, line_end) => syntax_block
TestBlockInfo(syntax_block, file) => syntax_block
end,
)
end
Expand Down
Loading