Skip to content

Commit

Permalink
Merge pull request crystal-lang#2 from icyleaf/refactor-lexer-middlewave
Browse files Browse the repository at this point in the history
Refactor lexer middlewave
  • Loading branch information
icyleaf authored Jun 26, 2017
2 parents 2dfba35 + 1efc305 commit 5d5a9f1
Show file tree
Hide file tree
Showing 24 changed files with 991 additions and 583 deletions.
56 changes: 0 additions & 56 deletions spec/markd/lexer/blockquote_spec.cr

This file was deleted.

42 changes: 0 additions & 42 deletions spec/markd/lexer/code_spec.cr

This file was deleted.

56 changes: 56 additions & 0 deletions spec/markd/lexer/common_lexer/blockquote_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require "../../../spec_helper"

describe Markd::Lexer do
assert_common_lexer_render "> # Foo\n> bar\n> baz", [{
"type" => "blockquote_start"
},
{
"type" => "heading",
"level" => 1,
"text" => "Foo"
},
{
"type" => "paragraph",
"text" => "bar\nbaz"
},
{
"type" => "blockquote_end"
}]

assert_common_lexer_render "> # Foo\n>bar\n> baz", [{
"type" => "blockquote_start"
},
{
"type" => "heading",
"level" => 1,
"text" => "Foo"
},
{
"type" => "paragraph",
"text" => "bar\nbaz"
},
{
"type" => "blockquote_end"
}]

assert_common_lexer_render "> # Foo\n> bar\n > baz", [{
"type" => "blockquote_start"
},
{
"type" => "heading",
"level" => 1,
"text" => "Foo"
},
{
"type" => "paragraph",
"text" => "bar\nbaz"
},
{
"type" => "blockquote_end"
}]

assert_common_lexer_render " > # Foo\n > bar\n > baz", [{
"type" => "code",
"text" => "> # Foo\n> bar\n> baz"
}]
end
42 changes: 42 additions & 0 deletions spec/markd/lexer/common_lexer/code_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "../../../spec_helper"

describe Markd::Lexer do
assert_common_lexer_render " echo hello world", [{
"type" => "code",
"text" => "echo hello world"
}]

assert_common_lexer_render " echo hello world\n pwd", [{
"type" => "code",
"text" => "echo hello world\npwd"
}]

assert_common_lexer_render "Hello World\n\n echo hello world", [{
"type" => "paragraph",
"text" => "Hello World"
},
{
"type" => "code",
"text" => "echo hello world"
}]

assert_common_lexer_render " echo hello world", [
{
"type" => "code",
"text" => "echo hello world"
}]

assert_common_lexer_render " echo hello world\n\nHello Earch\n\n echo hello crystal", [
{
"type" => "code",
"text" => "echo hello world"
},
{
"type" => "paragraph",
"text" => "Hello Earch"
},
{
"type" => "code",
"text" => "echo hello crystal"
}]
end
50 changes: 50 additions & 0 deletions spec/markd/lexer/common_lexer/fences_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require "../../../spec_helper"

describe Markd::Lexer do
assert_common_lexer_render "```\necho hello world\n```", [{
"type" => "code",
"text" => "echo hello world"
}]

assert_common_lexer_render "```bash\necho hello world\npwd```", [{
"type" => "code",
"lang" => "bash",
"text" => "echo hello world\npwd",
}]

assert_common_lexer_render "`````\nhi ther `` ok ```\n`````", [{
"type" => "code",
"text" => "hi ther `` ok ```"
}]

assert_common_lexer_render "```\n<\n >\n```", [{
"type" => "code",
"text" => "&lt;\n &gt;"
}]

assert_common_lexer_render "~~~\n<\n >\n~~~", [{
"type" => "code",
"text" => "&lt;\n &gt;"
}]

assert_common_lexer_render "```\naaa\n~~~\n```", [{
"type" => "code",
"text" => "aaa\n~~~"
}]

assert_common_lexer_render "~~~\naaa\n```\n~~~", [{
"type" => "code",
"text" => "aaa\n```"
}]

# TODO: fix it
# assert_common_lexer_render "````\naaa\n```\n``````", [{
# "type" => "code",
# "text" => "aaa\n```"
# }]

# assert_common_lexer_render "~~~~\naaa\n~~~\n~~~~~", [{
# "type" => "code",
# "text" => "aaa\n~~~"
# }]
end
57 changes: 57 additions & 0 deletions spec/markd/lexer/common_lexer/heading_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "../../../spec_helper"

describe Markd::Lexer do
assert_common_lexer_render "# Heading 1", [{
"type" => "heading",
"level" => 1,
"text" => "Heading 1",
}]

assert_common_lexer_render "## Heading 2", [{
"type" => "heading",
"level" => 2,
"text" => "Heading 2",
}]

assert_common_lexer_render "###### Heading 6", [{
"type" => "heading",
"level" => 6,
"text" => "Heading 6",
}]

assert_common_lexer_render "## Heading 2\n### Heading 3", [{
"type" => "heading",
"level" => 2,
"text" => "Heading 2",
},
{
"type" => "heading",
"level" => 3,
"text" => "Heading 3",
}]

assert_common_lexer_render "####### Heading 7", [{
"type" => "paragraph",
"text" => "####### Heading 7",
}]

assert_common_lexer_render "#Heading 1", [{
"type" => "paragraph",
"text" => "#Heading 1",
}]

assert_common_lexer_render "#Heading 1", [{
"type" => "paragraph",
"text" => "#Heading 1",
}]

assert_common_lexer_render "#Heading 1", [{
"type" => "paragraph",
"text" => "#Heading 1",
}]

assert_common_lexer_render "#Heading 1\n#Heading 2", [{
"type" => "paragraph",
"text" => "#Heading 1\n#Heading 2",
}]
end
75 changes: 75 additions & 0 deletions spec/markd/lexer/common_lexer/hr_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require "../../../spec_helper"

describe Markd::Lexer do
assert_common_lexer_render "---\n___", [{
"type" => "hr"
},
{
"type" => "hr"
}]

assert_common_lexer_render "+++", [{
"type" => "paragraph",
"text" => "+++"
}]

assert_common_lexer_render "===", [{
"type" => "paragraph",
"text" => "==="
}]

assert_common_lexer_render "--\n**\n__", [{
"type" => "paragraph",
"text" => "--\n**\n__"
}]

assert_common_lexer_render " ***\n ***\n ***", [{
"type" => "hr"
},
{
"type" => "hr"
},
{
"type" => "hr"
}]

assert_common_lexer_render " ***", [{
"type" => "code",
"text" => "***"
}]

assert_common_lexer_render "Foo\n ***", [{
"type" => "paragraph",
"text" => "Foo\n ***"
}]

assert_common_lexer_render "_____________________________________\n - - -\n ** * ** * ** * **\n- - - -\n- - - - ", [{
"type" => "hr"
},
{
"type" => "hr"
},
{
"type" => "hr"
},
{
"type" => "hr"
},
{
"type" => "hr"
}]

assert_common_lexer_render "_ _ _ _ a\n\na------\n\n---a---", [{
"type" => "paragraph",
"text" => "_ _ _ _ a"
},
{
"type" => "paragraph",
"text" => "a------"
},
{
"type" => "paragraph",
"text" => "---a---"
}]

end
Loading

0 comments on commit 5d5a9f1

Please sign in to comment.