Permalink
Browse files

#2 tests completed for CLI

  • Loading branch information...
1 parent bc657d2 commit aa7faba0c24c0b2d748e39f2e7e37ff03aa650a0 @neocotic neocotic committed Dec 11, 2012
Showing with 68 additions and 20 deletions.
  1. +1 −1 bin/md
  2. +67 −19 test/cli
View
2 bin/md
@@ -106,7 +106,7 @@ parsePath = (source, topLevel, base) ->
# Parse `input` and write it to a Markdown file, where appropriate.
parseHtml = (file, input, base) ->
try
- output = md input, debug: opts.debug
+ output = md input, opts
if opts.print
console.log output
else
View
@@ -40,17 +40,12 @@ VERSION = """
existsSync = fs.existsSync or path.existsSync
-# TODO: Complete test fixtures execution
-
cleanOutput = ->
if existsSync OUTPUT_DIR
for file in fs.readdirSync OUTPUT_DIR
do (file) -> fs.unlinkSync path.join OUTPUT_DIR, file
fs.rmdirSync OUTPUT_DIR
-createOutput = ->
- fs.mkdirSync OUTPUT_DIR unless existsSync OUTPUT_DIR
-
testFixture = (t, name) ->
t.test name, (t) ->
htmlPath = path.join FIXTURES_DIR, "#{name}#{HTML_EXT}"
@@ -68,41 +63,94 @@ testFixture = (t, name) ->
t.equal markdown, md html
exec "#{COMMAND} -p #{htmlPath}", (err, stdout) ->
t.notOk err
- t.equal stdout, md html
+ t.equal stdout, """
+ #{md html}
+
+ """
testFixtures = ->
test 'fixtures', (t) ->
- createOutput()
files = fs.readdirSync FIXTURES_DIR
fixtures = (
for file in files when HTML_EXT is path.extname file
path.basename file, HTML_EXT
)
for fixture in fixtures
do (fixture) -> testFixture t, fixture
- cleanOutput()
+ t.tearDown cleanOutput
t.end()
+testStdio = (t, expected) ->
+ (err, stdout) ->
+ t.notOk err
+ t.equal stdout, expected
+
+toFileUrl = (relativePath) ->
+ "file://#{toPathName relativePath}"
+
+toPathName = (relativePath) ->
+ pathName = path.resolve __dirname, '../lib', relativePath
+ pathName = pathName.replace ///\\///g, '/'
+ pathName = "/#{pathName}" if pathName[0] isnt '/'
+ pathName
+
# Tests
# -----
testFixtures()
+test 'absolute', (t) ->
+ t.plan 6 * 2
+ exec "#{COMMAND} -ep \"<a href='mock'>anchor</a>\"", testStdio t, """
+ [anchor][0]
+
+ [0]: mock
+
+ """
+ exec "#{COMMAND} -ep \"<a href='/mock'>anchor</a>\"", testStdio t, """
+ [anchor][0]
+
+ [0]: /mock
+
+ """
+ exec "#{COMMAND} -epa \"<a href='mock'>anchor</a>\"", testStdio t, """
+ [anchor][0]
+
+ [0]: #{toFileUrl 'mock'}
+
+ """
+ exec "#{COMMAND} -epa \"<a href='/mock'>anchor</a>\"", testStdio t, """
+ [anchor][0]
+
+ [0]: #{toFileUrl '/mock'}
+
+ """
+ exec "#{COMMAND} -ep \"<img src='mock'>\"", testStdio t, """
+ ![](mock)
+
+ """
+ exec "#{COMMAND} -epa \"<img src='mock'>\"", testStdio t, """
+ ![](mock)
+
+ """
+
+test 'stdio', (t) ->
+ t.plan 2
+ exec "#{COMMAND} -ep \"<strong>strong</strong>\"", testStdio t, """
+ **strong**
+
+ """
+
test 'usage', (t) ->
testUsage = (err, stdout) ->
t.notOk err
t.equal stdout, USAGE
- t.plan 3 * 2
- exec COMMAND, testUsage
- exec "#{COMMAND} -h", testUsage
- exec "#{COMMAND} --help", testUsage
+ t.plan 2 * 2
+ exec COMMAND, testUsage
+ exec "#{COMMAND} -h", testUsage
test 'version', (t) ->
- testVersion = (err, stdout) ->
+ t.plan 2
+ exec "#{COMMAND} -v", (err, stdout) ->
t.notOk err
- t.equal stdout, VERSION
- t.plan 2 * 2
- exec "#{COMMAND} -v", testVersion
- exec "#{COMMAND} --version", testVersion
-
-# TODO: Complete tests
+ t.equal stdout, VERSION

0 comments on commit aa7faba

Please sign in to comment.