fixing block comment indentation

This commit is contained in:
Jeremy Ashkenas
2012-09-25 19:35:02 -05:00
parent 82fadea1ed
commit 4fb3a312b0
4 changed files with 34 additions and 4 deletions

View File

@@ -225,11 +225,12 @@ runTests = (CoffeeScript) ->
# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
for file in files when file.match /\.coffee$/i
for file in files when file.match /\.(lit)?coffee$/i
literate = path.extname(file) is '.litcoffee'
currentFile = filename = path.join 'test', file
code = fs.readFileSync filename
try
CoffeeScript.run code.toString(), {filename}
CoffeeScript.run code.toString(), {filename, literate}
catch error
failures.push {filename, error}
return !failures.length

View File

@@ -487,7 +487,7 @@
if (HEREDOC_ILLEGAL.test(doc)) {
this.error("block comment cannot contain \"*/\", starting");
}
if (doc.indexOf('\n') <= 0) {
if (doc.indexOf('\n') < 0) {
return doc;
}
} else {

View File

@@ -389,7 +389,7 @@ exports.Lexer = class Lexer
if herecomment
if HEREDOC_ILLEGAL.test doc
@error "block comment cannot contain \"*/\", starting"
return doc if doc.indexOf('\n') <= 0
return doc if doc.indexOf('\n') < 0
else
while match = HEREDOC_INDENT.exec doc
attempt = match[1]

29
test/literate.litcoffee Normal file
View File

@@ -0,0 +1,29 @@
comment comment
test "basic literate CoffeeScript parsing", ->
ok yes
now with a...
test "broken up indentation", ->
... broken up ...
do ->
... nested block.
ok yes
Code in `backticks is not parsed` and...
test "comments in indented blocks work", ->
do ->
do ->
# Regular comment.
###
Block comment.
###
ok yes