Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Sprache/CommentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Parser<string> SingleLineComment
throw new ParseException("Field 'Single' is null; single-line comments not allowed.");

return from first in Parse.String(Single)
from rest in Parse.CharExcept(NewLine).Many().Text()
from rest in Parse.CharExcept(new[] {'\r', '\n' }).Many().Text()
select rest;
}
private set { }
Expand Down
35 changes: 35 additions & 0 deletions test/Sprache.Tests/CommentParserTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Sprache.Tests
{
public class CommentParserTest
{
[Fact]
public void Check_single_line_comment_for_both_eol_windows_linux()
{
var parser = new CommentParser();
var expected = "this is a line comment";
var result = parser.SingleLineComment.Parse("//this is a line comment\r\nint i=5;");
Assert.Equal(result, expected);
result = parser.SingleLineComment.Parse("//this is a line comment\nint i=5;");
Assert.Equal(result, expected);

}
[Fact]
public void Check_any_comment_for_both_eol_windows_linux()
{
var parser = new CommentParser();
var expected = "this is a line comment";
var result = parser.AnyComment.Parse("//this is a line comment\r\nint i=5;");
Assert.Equal(result, expected);
result = parser.AnyComment.Parse("//this is a line comment\nint i=5;");
Assert.Equal(result, expected);

}
}
}