From 1e475f071928abe2e66bd030f29200b539186fd4 Mon Sep 17 00:00:00 2001 From: Chris Ledet Date: Tue, 24 Apr 2012 19:43:37 -0400 Subject: [PATCH] Added tests. WIP. --- Gemfile | 2 +- Rakefile | 7 ++ bin/markdown2confluence | 13 ++-- .../convertor/confluence.rb | 1 - markdown2confluence.gemspec | 5 ++ test/markdown2confluence_test.rb | 66 +++++++++++++++++++ test/test_helper.rb | 4 ++ 7 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 test/markdown2confluence_test.rb create mode 100644 test/test_helper.rb diff --git a/Gemfile b/Gemfile index dce58c5..c80ee36 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source "http://rubygems.org" -gem "markdown2confluence", :path => "." +gemspec diff --git a/Rakefile b/Rakefile index 0d24448..60c7750 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/bin/markdown2confluence b/bin/markdown2confluence index fca3469..78431e8 100755 --- a/bin/markdown2confluence +++ b/bin/markdown2confluence @@ -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 diff --git a/lib/markdown2confluence/convertor/confluence.rb b/lib/markdown2confluence/convertor/confluence.rb index 595bf1f..45bc841 100644 --- a/lib/markdown2confluence/convertor/confluence.rb +++ b/lib/markdown2confluence/convertor/confluence.rb @@ -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 diff --git a/markdown2confluence.gemspec b/markdown2confluence.gemspec index 7a46a97..5f393b3 100644 --- a/markdown2confluence.gemspec +++ b/markdown2confluence.gemspec @@ -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 diff --git a/test/markdown2confluence_test.rb b/test/markdown2confluence_test.rb new file mode 100644 index 0000000..13ff286 --- /dev/null +++ b/test/markdown2confluence_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..b57a14e --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,4 @@ +require 'test/unit' +require 'active_support/test_case' +require 'turn' +require 'markdown2confluence'