Skip to content

Commit

Permalink
Added tests. WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisledet committed Apr 24, 2012
1 parent 5519cac commit 1e475f0
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "http:https://rubygems.org"

gem "markdown2confluence", :path => "."
gemspec
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
require 'bundler/setup'
Bundler::GemHelper.install_tasks

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = false
end
13 changes: 4 additions & 9 deletions bin/markdown2confluence
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

require 'markdown2confluence'

filename=ARGV[0]
if ARGV.size < 1
puts "We need at least on file argument"
exit -1
end
filename = ARGV[0]
abort "We need at least on file argument" if ARGV.size < 1

begin
text=File.read(filename)

s=Kramdown::Document.new(text).to_confluence
puts s
text = File.read(filename)
puts Kramdown::Document.new(text).to_confluence
rescue Exception => ex
warn "There was an error running the convertor: \n#{ex}"
end
1 change: 0 additions & 1 deletion lib/markdown2confluence/convertor/confluence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def convert_p(el, indent)
"#{' '*indent}#{inner(el, indent)}\n\n"
end


def convert_blockquote(el, indent)
"#{' '*indent}bq. #{inner(el, indent)}\n"
end
Expand Down
5 changes: 5 additions & 0 deletions markdown2confluence.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ Gem::Specification.new do |s|

s.add_dependency "kramdown"
s.add_dependency "nokogiri"

s.add_development_dependency('rake', "~> 0.9.2")
s.add_development_dependency('activesupport', '>= 3.0.0')
s.add_development_dependency('turn')

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
s.require_path = 'lib'
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
end

66 changes: 66 additions & 0 deletions test/markdown2confluence_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'test_helper'

class Markdown2ConfluenceTest < ActiveSupport::TestCase
test "header 1" do
assert_equal "h1. Hello\n", confluence("# Hello")
end

test "heading 2" do
assert_equal "h2. Hello\n", confluence("## Hello")
end

test "heading 3" do
assert_equal "h3. Hello\n", confluence("### Hello")
end

test "heading 4" do
assert_equal "h4. Hello\n", confluence("#### Hello")
end

# TODO - remove these extra spaces after - symbol
test "lists" do
list = "* this\n"
list << "* is\n"
list << "* a\n"
list << "* list\n"
confluence_list = list.gsub("*", "- ").gsub("\n", "\n\n")
assert_equal confluence_list, confluence(list)
end

# TODO - two trailing newlines
test "strong text" do
assert_equal "*strong*\n\n", confluence("**strong**")
end

# TODO - two trailing newlines
test "italics text" do
assert_equal "_some text here_\n\n", confluence("*some text here*")
end

# TODO - two trailing newlines
test "inline code" do
assert_equal "{{hello world}}\n\n", confluence("`hello world`")
end

test "block of code" do
code = " this is code\n"
assert_equal "{code}this is code\n{code}\n", confluence(code)
end

# TODO - two trailing newlines
# FIX - failing test
test "strikethrough" do
assert_equal "-strikethrough text-\n\n", confluence("~~strikethrough text~~")
end

# FIX - failing test
test "quote" do
assert_equal "bq. this is a quote", confluence("> this is a quote")
end

private

def confluence(text)
Kramdown::Document.new(text).to_confluence
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test/unit'
require 'active_support/test_case'
require 'turn'
require 'markdown2confluence'

0 comments on commit 1e475f0

Please sign in to comment.