-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce can_contain in tree mutation methods
Fix #9.
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using MarkdownAST: MarkdownAST, @ast, Node, | ||
Document, Paragraph, Strong, Link, CodeBlock, HTMLBlock, Code, | ||
InvalidChildException, insert_after!, insert_before! | ||
using Test | ||
|
||
@testset "Invalid AST" begin | ||
# Document can only contain blocks, not inlines | ||
@test_throws InvalidChildException (@ast Document() do | ||
Link("", "") | ||
end) | ||
valid_document = @ast Document() do | ||
Paragraph() | ||
end | ||
node_strong = Node(Strong()) | ||
@test_throws InvalidChildException push!(valid_document.children, node_strong) | ||
@test_throws InvalidChildException pushfirst!(valid_document.children, node_strong) | ||
@test_throws InvalidChildException insert_after!(first(valid_document.children), node_strong) | ||
@test_throws InvalidChildException insert_before!(first(valid_document.children), node_strong) | ||
|
||
# Paragraph can only contain inlines, but not blocks: | ||
@test_throws InvalidChildException (@ast Paragraph() do | ||
HTMLBlock("") | ||
end) | ||
valid_p = @ast Paragraph() do | ||
"..." | ||
end | ||
node_codeblock = Node(CodeBlock("", "")) | ||
@test_throws InvalidChildException push!(valid_p.children, node_codeblock) | ||
@test_throws InvalidChildException pushfirst!(valid_p.children, node_codeblock) | ||
@test_throws InvalidChildException insert_after!(first(valid_p.children), node_codeblock) | ||
@test_throws InvalidChildException insert_before!(first(valid_p.children), node_codeblock) | ||
|
||
# Some nodes can not have child nodes | ||
@test_throws InvalidChildException (@ast CodeBlock("", "") do | ||
"..." | ||
end) | ||
@test_throws InvalidChildException (@ast Code("...") do | ||
"..." | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ using Test | |
@testset "MarkdownAST" begin | ||
include("markdown.jl") | ||
include("node.jl") | ||
include("invalidast.jl") | ||
end |