From bacbb600c6143dd92f967370b21f6fa90a9baca1 Mon Sep 17 00:00:00 2001 From: brouwers <122355335+brouwers-tiobe@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:31:17 +0200 Subject: [PATCH 1/2] 35202: Bring Matlab form-feed fix to CPD 7 --- pmd-matlab/etc/grammar/Matlab.jj | 2 ++ .../lang/matlab/cpd/MatlabCpdLexerTest.java | 13 ++++++- .../pmd/lang/matlab/cpd/testdata/formFeed.m | 7 ++++ .../pmd/lang/matlab/cpd/testdata/formFeed.txt | 35 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m create mode 100644 pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.txt diff --git a/pmd-matlab/etc/grammar/Matlab.jj b/pmd-matlab/etc/grammar/Matlab.jj index d83368fc73b..793efd400cf 100644 --- a/pmd-matlab/etc/grammar/Matlab.jj +++ b/pmd-matlab/etc/grammar/Matlab.jj @@ -36,6 +36,8 @@ PARSER_END(MatlabParserImpl) "\r\n" : DEFAULT | "\n" : DEFAULT +| + "\f" : DEFAULT } MORE: diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java index 39b56ccfd29..0b1c5244754 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java @@ -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; @@ -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"); @@ -22,7 +29,6 @@ void testLongSample() { @Test void testIgnoreBetweenSpecialComments() { doTest("specialComments"); - } @Test @@ -49,4 +55,9 @@ void testDoubleQuotedStrings() { void testTabWidth() { doTest("tabWidth"); } + + @Test + void testFormFeed() { + doTest("formFeed"); + } } diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m new file mode 100644 index 00000000000..b2a31bfce23 --- /dev/null +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m @@ -0,0 +1,7 @@ +classdef LC + methods + function [obj, c,t, s ] = Classification( obj,m,t, cm )%#codegen + end + end +end + diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.txt b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.txt new file mode 100644 index 00000000000..5e48259a909 --- /dev/null +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.txt @@ -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 From bc541c4a1fc505d166b7362f65e578fa3d389bd9 Mon Sep 17 00:00:00 2001 From: brouwers <122355335+brouwers-tiobe@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:17:04 +0200 Subject: [PATCH 2/2] 35202: Indicate form-feed presence in test file --- .../net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m index b2a31bfce23..f72e3bd34a8 100644 --- a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/formFeed.m @@ -1,7 +1,7 @@ classdef LC methods function [obj, c,t, s ] = Classification( obj,m,t, cm )%#codegen - end + end % This line contains a form-feed character (U+000C) end end