Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple multi line support #99

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c4cf23b
Move some more logic to the nextline provider allowing to split a sin…
Uight Aug 28, 2024
f3e9dc5
NextLineProvider now allows PeakLine
Uight Aug 29, 2024
3790268
Multiline support via NextLineProvider
Uight Aug 31, 2024
ed5340d
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Aug 31, 2024
ae60b3b
Resolve merge conflicts
Uight Aug 31, 2024
5755890
intermediate updateing tests
Uight Aug 31, 2024
638b649
Fix changed tests (still not running as \r\n is still removed)
Uight Aug 31, 2024
a29e799
All current Test running
Uight Aug 31, 2024
99cbf46
dummy add the three cases from the tikcet at strings
Uight Aug 31, 2024
0e7eb84
Basic test + bugfix multidefinition in one line
Uight Aug 31, 2024
17ace3f
Complete the tests
Uight Aug 31, 2024
a271ffa
All line parsers use line trim and replace newline by space. Test adj…
Uight Aug 31, 2024
0c5ee35
allow other newline chars
Uight Aug 31, 2024
1eed82f
small rename
Uight Aug 31, 2024
a5fddc1
some changes from the we
Uight Sep 2, 2024
c34eaa7
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Sep 2, 2024
abd1d07
Upstream merge cleanup
Uight Sep 2, 2024
2e68cae
Logic for multiline read changed
Uight Sep 2, 2024
c687070
Move virtualLine memory to textreader component
Uight Sep 2, 2024
a6c1946
Could autocorrect missing ";" at line end
Uight Sep 2, 2024
f46995f
fox wrong observer lines and support multidefinition right after mult…
Uight Sep 2, 2024
d2e91dd
Add test for last case
Uight Sep 2, 2024
26b3119
ass multidefinitionsupport even after ";"
Uight Sep 2, 2024
42ab1b9
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Sep 3, 2024
d4440e7
Merge conflixts resolved
Uight Sep 3, 2024
bfcce6a
small cleanup
Uight Sep 3, 2024
02a2641
simplyfy multiline handling
Uight Sep 3, 2024
e153eef
missed a unused using
Uight Sep 3, 2024
9adafcf
More cleanup
Uight Sep 3, 2024
869f259
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Sep 5, 2024
62cf4de
merge conflicts resolved
Uight Sep 5, 2024
803f07d
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Sep 7, 2024
2be2c48
Merge remote-tracking branch 'upstream/main' into TestBranchMultiLine…
Uight Dec 19, 2024
72fded5
Resolve merge conflicts
Uight Dec 19, 2024
7a5a8ea
Add testcase for issue 97
Uight Dec 19, 2024
297e340
use Env new line in test
Uight Dec 19, 2024
840ae99
Add a test to parse a full file including namespaces and so on which …
Uight Dec 19, 2024
95a26d9
Remove dumb missing termiantion correction; Vector Candb++ doesnt do …
Uight Dec 19, 2024
b3d08c3
Bugfix for multiple terminations in one line
Uight Dec 19, 2024
5c63517
Remove abilities to have comments without termination if termination …
Uight Dec 19, 2024
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
90 changes: 54 additions & 36 deletions DbcParserLib.Tests/CommentLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Moq;
using System.Collections.Generic;
using DbcParserLib.Observers;
using System.IO;

namespace DbcParserLib.Tests
{
Expand Down Expand Up @@ -92,20 +93,22 @@ public void FullLineIsParsed()
[Test]
public void FullMultilineIsParsed()
{
var multiLineComment = new[]
{
"CM_ SG_ 75 channelName \"This is the first line",
"this is the second line",
"this is the third line\";"
};
var expectedText = Helpers.ConcatenateTextComment(multiLineComment, 23);
var dbcString = @"CM_ SG_ 75 channelName ""This is the first line
this is the second line
this is the third line"";";

var expectedText = "This is the first line\r\nthis is the second line\r\nthis is the third line";

var dbcBuilderMock = m_repository.Create<IDbcBuilder>();
dbcBuilderMock.Setup(mock => mock.AddSignalComment(75, "channelName", expectedText));
var commentLineParser = CreateParser();

var reader = new ArrayBasedLineProvider(multiLineComment);
Assert.That(commentLineParser.TryParse(multiLineComment[0], dbcBuilderMock.Object, reader), Is.True);
using (var reader = new StringReader(dbcString))
{
var nextLineProvider = new NextLineProvider(reader, new SilentFailureObserver());
nextLineProvider.TryGetLine(out var line);
Assert.That(commentLineParser.TryParse(line, dbcBuilderMock.Object, nextLineProvider), Is.True);
}
}

[Test]
Expand All @@ -122,20 +125,23 @@ public void FullLineIsParsedAndRobustToWhiteSpace()
[Test]
public void FullMultilineIsParsedAndRobustToWhiteSpace()
{
var multiLineComment = new[]
{
"CM_ SG_ 75 channelName \"This is the first line",
" this is the second line",
" this is the third line\";"
};
var expectedText = Helpers.ConcatenateTextComment(multiLineComment, 23);
var dbcString = @"CM_ SG_ 75 channelName ""This is the first line
this is the second line
this is the third line"";";

// Spaces at linestart are always removed
var expectedText = "This is the first line\r\nthis is the second line\r\nthis is the third line";

var dbcBuilderMock = m_repository.Create<IDbcBuilder>();
dbcBuilderMock.Setup(mock => mock.AddSignalComment(75, "channelName", expectedText));
var commentLineParser = CreateParser();

var reader = new ArrayBasedLineProvider(multiLineComment);
Assert.That(commentLineParser.TryParse(multiLineComment[0], dbcBuilderMock.Object, reader), Is.True);
using (var reader = new StringReader(dbcString))
{
var nextLineProvider = new NextLineProvider(reader, new SilentFailureObserver());
nextLineProvider.TryGetLine(out var line);
Assert.That(commentLineParser.TryParse(line, dbcBuilderMock.Object, nextLineProvider), Is.True);
}
}

[Test]
Expand All @@ -152,20 +158,23 @@ public void FullLineIsParsedForMessageAndRobustToWhiteSpace()
[Test]
public void FullMultilineIsParsedForMessageAndRobustToWhiteSpace()
{
var multiLineComment = new[]
{
"CM_ BO_ 75 \"This is the first line",
" this is the second line",
" this is the third line\";"
};
var expectedText = Helpers.ConcatenateTextComment(multiLineComment, 11);
var dbcString = @"CM_ BO_ 75 ""This is the first line
this is the second line
this is the third line"";";

// Spaces at linestart are always removed
var expectedText = "This is the first line\r\nthis is the second line\r\nthis is the third line";

var dbcBuilderMock = m_repository.Create<IDbcBuilder>();
dbcBuilderMock.Setup(mock => mock.AddMessageComment(75, expectedText));
var commentLineParser = CreateParser();

var reader = new ArrayBasedLineProvider(multiLineComment);
Assert.That(commentLineParser.TryParse(multiLineComment[0], dbcBuilderMock.Object, reader), Is.True);
using (var reader = new StringReader(dbcString))
{
var nextLineProvider = new NextLineProvider(reader, new SilentFailureObserver());
nextLineProvider.TryGetLine(out var line);
Assert.That(commentLineParser.TryParse(line, dbcBuilderMock.Object, nextLineProvider), Is.True);
}
}

[Test]
Expand Down Expand Up @@ -202,20 +211,23 @@ public void FullLineIsParsedForNodeAndRobustToWhiteSpace()
[Test]
public void FullMultilineIsParsedForNodeAndRobustToWhiteSpace()
{
var multiLineComment = new[]
{
"CM_ BU_ node_name \"This is the first line",
" this is the second line",
" this is the third line\";"
};
var expectedText = Helpers.ConcatenateTextComment(multiLineComment, 18);
var dbcString = @"CM_ BU_ node_name ""This is the first line
this is the second line
this is the third line"";";

// Spaces at linestart are always removed
var expectedText = "This is the first line\r\nthis is the second line\r\nthis is the third line";

var dbcBuilderMock = m_repository.Create<IDbcBuilder>();
dbcBuilderMock.Setup(mock => mock.AddNodeComment("node_name", expectedText));
var commentLineParser = CreateParser();

var reader = new ArrayBasedLineProvider(multiLineComment);
Assert.That(commentLineParser.TryParse(multiLineComment[0], dbcBuilderMock.Object, reader), Is.True);
using (var reader = new StringReader(dbcString))
{
var nextLineProvider = new NextLineProvider(reader, new SilentFailureObserver());
nextLineProvider.TryGetLine(out var line);
Assert.That(commentLineParser.TryParse(line, dbcBuilderMock.Object, nextLineProvider), Is.True);
}
}

[Test]
Expand Down Expand Up @@ -255,6 +267,12 @@ public void AnotherMalformedLineIsAcceptedWithoutInteraction()
[TestCase("CM_ BO_ 865 \"Test with incorrect \"syntax\"\";")]
[TestCase("CM_ EV_ VarName \"Test with incorrect \"syntax\"\";")]
[TestCase("CM_ \"Test with incorrect \"syntax\"\";")]
[TestCase("CM_ BO_ 1160 \"This is a very fine comment;\"")]
[TestCase("CM_ BO_ 1160 \"This is a very fine comment\"")]
[TestCase("CM_ BO_ 1160 \"This is a very fine comment; Right?\"")]
[TestCase("CM_ SG_ SignalName \"This is a very fine comment; Right?\"")]
[TestCase("CM_ BU_ NodeName \"This is a very fine comment; Right?\"")]
[TestCase("CM_ EV_ VarName \"This is a very fine comment; Right?\"")]
public void CommentSyntaxErrorIsObserved(string commentLine)
{
var observerMock = m_repository.Create<IParseFailureObserver>();
Expand Down
Loading