Skip to content

Commit

Permalink
Merge pull request #52 from davidchambers/ramda
Browse files Browse the repository at this point in the history
ramda@0.11.x
  • Loading branch information
davidchambers committed Mar 8, 2015
2 parents c083ede + 5975d35 commit 40d37bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"coffee-script": "1.8.x",
"jquery": "2.1.x",
"ramda": "0.10.x"
"ramda": "0.11.x"
},
"devDependencies": {
"qunit": "1.15.x"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"coffee-script": "1.8.x",
"commander": "2.5.x",
"esprima-fb": "13001.1001.0-dev-harmony-fb",
"ramda": "0.10.x"
"ramda": "0.11.x"
},
"devDependencies": {
"bower": "1.3.x",
Expand Down
22 changes: 14 additions & 8 deletions src/doctest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ doctest.version = '0.8.0'

if typeof window isnt 'undefined'
{CoffeeScript, esprima, R} = window
_ = R.__
window.doctest = doctest
else
fs = require 'fs'
pathlib = require 'path'
CoffeeScript = require 'coffee-script'
esprima = require 'esprima-fb'
R = require 'ramda'
_ = R.__
module.exports = doctest


# appendTo :: [a] -> a -> [a]
appendTo = R.flip R.append


# indentN :: Number -> String -> String
indentN = R.pipe(
R.times R.always ' '
Expand Down Expand Up @@ -178,29 +184,29 @@ transformComments = R.pipe(

[prefix, value] = R.tail R.match /^(>|[.]*)[ ]?(.*)$/, normalizedLine
if prefix is '>'
['input', R.appendTo accum, {
['input', appendTo accum, {
commentIndex
input: {loc: {start, end}, value}
}]
else if state is 'default'
['default', accum]
else if state is 'input'
if prefix
['input', R.appendTo R.init(accum), {
['input', appendTo R.init(accum), {
commentIndex
input:
loc: {start: R.last(accum).input.loc.start, end}
value: "#{R.last(accum).input.value}\n#{value}"
}]
else
['output', R.appendTo R.init(accum), {
['output', appendTo R.init(accum), {
commentIndex
input: R.last(accum).input
output: {loc: {start, end}, value}
}]
else if state is 'output'
if prefix
['output', R.appendTo R.init(accum), {
['output', appendTo R.init(accum), {
commentIndex
input: R.last(accum).input
output:
Expand Down Expand Up @@ -252,7 +258,7 @@ substring = (input, start, end) ->


wrap = R.curry (type, test) -> R.pipe(
R.filter R.partialRight R.has, test
R.filter R.has _, test
R.map (dir) -> wrap[type][dir] test
R.join '\n'
) ['input', 'output']
Expand Down Expand Up @@ -322,11 +328,11 @@ rewrite.js = (input) ->
source = R.pipe(
R.append input: bookend
reduce [[], {line: 1, column: 0}], ([chunks, start], test) -> [
R.appendTo chunks, substring input, start, test.input.loc.start
appendTo chunks, substring input, start, test.input.loc.start
(test.output ? test.input).loc.end
]
R.head
R.partialRight R.zip, R.append '', R.map wrap.js, lineTests
R.zip _, R.append '', R.map wrap.js, lineTests
R.flatten
R.join ''
) lineTests
Expand All @@ -341,7 +347,7 @@ rewrite.js = (input) ->
R.filter R.propEq 'commentIndex', idx
R.map wrap.js
R.join '\n'
R.appendTo R.append substring(source, start, comment.loc.start), chunks
appendTo R.append substring(source, start, comment.loc.start), chunks
R.of
R.append comment.loc.end
) blockTests
Expand Down

0 comments on commit 40d37bf

Please sign in to comment.