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

Handle form-feed character in Matlab files #2

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions pmd-matlab/etc/grammar/Matlab.jj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ PARSER_END(MatlabParserImpl)
"\r\n" : DEFAULT
|
"\n" : DEFAULT
|
"\f" : DEFAULT
}

<DEFAULT, TRANSPOSE> MORE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package net.sourceforge.pmd.lang.matlab.cpd;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Test;

import net.sourceforge.pmd.lang.test.cpd.CpdTextComparisonTest;
Expand All @@ -14,6 +15,12 @@ class MatlabCpdLexerTest extends CpdTextComparisonTest {
super("matlab", ".m");
}

@Override
protected @NonNull String normalize(@NonNull String str) {
// Only normalize LF/CR/CRLF so we can test handling of e.g. \u000C (form-feed)
return str.replaceAll("\\u000D\\u000A|[\\u000A\\u000D]", "\n");
}

@Test
void testLongSample() {
doTest("sample-matlab");
Expand All @@ -22,7 +29,6 @@ void testLongSample() {
@Test
void testIgnoreBetweenSpecialComments() {
doTest("specialComments");

}

@Test
Expand All @@ -49,4 +55,9 @@ void testDoubleQuotedStrings() {
void testTabWidth() {
doTest("tabWidth");
}

@Test
void testFormFeed() {
doTest("formFeed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
classdef LC
methods
function [obj, c,t, s ] = Classification( obj,m,t, cm )%#codegen
end % This line contains a form-feed character (U+000C)
end
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[classdef] 1 9
[LC] 10 12
L2
[methods] 5 12
L3
[function] 9 17
[\[] 18 19
[obj] 19 22
[,] 22 23
[c] 24 25
[,] 25 26
[t] 26 27
[,] 27 28
[s] 29 30
[\]] 31 32
[=] 33 34
[Classification] 35 49
[(] 49 50
[obj] 51 54
[,] 54 55
[m] 55 56
[,] 56 57
[t] 57 58
[,] 58 59
[cm] 60 62
[)] 63 64
L4
[end] 9 12
L5
[end] 5 8
L6
[end] 1 4
EOF