Browse Source

Add a pretty-printer for Runic.Node.

pull/19/head
Fredrik Ekre 2 years ago
parent
commit
5a9f8ad523
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 7
      src/Runic.jl
  2. 13
      test/runtests.jl

7
src/Runic.jl

@ -39,6 +39,13 @@ function Node(node::JuliaSyntax.GreenNode)
) )
end end
function Base.show(io::IO, node::Node)
print(io, "Node({head: {kind: ")
show(io, kind(node))
print(io, ", flags: \"$(flags(node))\"}, span: $(span(node))})")
return nothing
end
# Defining these allow using many duck-typed methods in JuliaSyntax directly without having # Defining these allow using many duck-typed methods in JuliaSyntax directly without having
# to re-package a Node as a GreenNode. # to re-package a Node as a GreenNode.
JuliaSyntax.head(node::Node) = head(node) JuliaSyntax.head(node::Node) = head(node)

13
test/runtests.jl

@ -7,10 +7,11 @@ using Test:
using JuliaSyntax: using JuliaSyntax:
JuliaSyntax JuliaSyntax
@testset "Chisels" begin @testset "Node" begin
# Type stability of verified_kids
node = Runic.Node(JuliaSyntax.parseall(JuliaSyntax.GreenNode, "a = 1 + b\n")) node = Runic.Node(JuliaSyntax.parseall(JuliaSyntax.GreenNode, "a = 1 + b\n"))
@test typeof(@inferred Runic.verified_kids(node)) === Vector{Runic.Node}
# Pretty-printing
@test sprint(show, node) == "Node({head: {kind: K\"toplevel\", flags: \"0\"}, span: 10})"
# JuliaSyntax duck-typing # JuliaSyntax duck-typing
for n in (node, Runic.verified_kids(node)...,) for n in (node, Runic.verified_kids(node)...,)
@ -19,6 +20,12 @@ using JuliaSyntax:
@test Runic.flags(n) === JuliaSyntax.flags(n) === n.head.flags @test Runic.flags(n) === JuliaSyntax.flags(n) === n.head.flags
@test Runic.span(n) === JuliaSyntax.span(n) === n.span @test Runic.span(n) === JuliaSyntax.span(n) === n.span
end end
end
@testset "Chisels" begin
# Type stability of verified_kids
node = Runic.Node(JuliaSyntax.parseall(JuliaSyntax.GreenNode, "a = 1 + b\n"))
@test typeof(@inferred Runic.verified_kids(node)) === Vector{Runic.Node}
# replace_bytes!: insert larger # replace_bytes!: insert larger
io = IOBuffer(); write(io, "abc"); seek(io, 1) io = IOBuffer(); write(io, "abc"); seek(io, 1)

Loading…
Cancel
Save