Created
December 19, 2018 14:17
-
-
Save miyohide/5695a901b6618399c25380495fb73c8d to your computer and use it in GitHub Desktop.
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
class Pukiwiki2md | |
STRONG_REG = /''(.+?)''/ | |
LINK_REG = /\[\[(.+?):(.+?)\]\]/ | |
def convert_strong!(line) | |
line.gsub!(STRONG_REG, "**\\1**") | |
line | |
end | |
def convert_link!(line) | |
line.gsub!(LINK_REG, "[\\1](\\2)") | |
line | |
end | |
def convert_decorator(line) | |
[:convert_strong!, :convert_link!].each do |converter| | |
send(converter, line) | |
end | |
line | |
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
require 'minitest/autorun' | |
require './pukiwiki2md' | |
class Pukiwiki2mdTest < Minitest::Test | |
def setup | |
@p2m = Pukiwiki2md.new | |
end | |
def test_convert_strong | |
actual = @p2m.convert_decorator("aaaa''bbbb''cccc") | |
assert_equal "aaaa**bbbb**cccc", actual | |
end | |
def test_convert_strong_double | |
actual = @p2m.convert_decorator("aaaa''bbbb''cccc''ddddd''eeeee") | |
assert_equal "aaaa**bbbb**cccc**ddddd**eeeee", actual | |
end | |
def test_convert_strong_and_link | |
actual = @p2m.convert_decorator("aaa''bbbb''cccc[[hoge:https://hoge]]ddd") | |
assert_equal "aaa**bbbb**cccc[hoge](https://hoge)ddd", actual | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment