From 3a004b5d581bf921cfa4c4d30bc5bf01b2713191 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 15 May 2019 13:33:11 +0300 Subject: [PATCH] diff: add editor painting tests GitOrigin-RevId: 9b6f6fdce791666c4ce5b11ab391a087cb81ff5d --- .../intellij.platform.diff.tests.iml | 2 + .../diff/painting/borderLineMarker.png | Bin 0 -> 357 bytes .../testData/diff/painting/emptyRange.png | Bin 0 -> 295 bytes .../diff/painting/emptyRangeLastEmptyLine.png | Bin 0 -> 183 bytes .../painting/emptyRangeLastLineSoftWraps.png | Bin 0 -> 342 bytes .../diff/painting/lastEmptyLineChanged.png | Bin 0 -> 235 bytes .../diff/painting/lastLineChanged.png | Bin 0 -> 259 bytes .../diff/painting/lastLineSoftWraps.png | Bin 0 -> 309 bytes .../testData/diff/painting/lineMarker.png | Bin 0 -> 351 bytes .../testData/diff/painting/newlineChanged.png | Bin 0 -> 249 bytes .../diff/painting/oneLetterChanged.png | Bin 0 -> 175 bytes .../diff/painting/wholeLineChanged.png | Bin 0 -> 165 bytes .../diff/painting/DiffEditorPaintingTest.kt | 100 ++++++++++++++++++ .../softWrapWithWithLineSeparator.png | Bin 0 -> 286 bytes .../openapi/editor/EditorPaintingTest.java | 20 +++- .../editor/EditorPaintingTestCase.java | 59 ++++++++--- 16 files changed, 163 insertions(+), 18 deletions(-) create mode 100644 platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/emptyRange.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/lineMarker.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/newlineChanged.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png create mode 100644 platform/diff-impl/tests/testData/diff/painting/wholeLineChanged.png create mode 100644 platform/diff-impl/tests/testSrc/com/intellij/diff/painting/DiffEditorPaintingTest.kt create mode 100644 platform/platform-tests/testData/editor/painting/softWrapWithWithLineSeparator.png diff --git a/platform/diff-impl/intellij.platform.diff.tests.iml b/platform/diff-impl/intellij.platform.diff.tests.iml index 60a966d6d9e7..de9d7ca33a89 100644 --- a/platform/diff-impl/intellij.platform.diff.tests.iml +++ b/platform/diff-impl/intellij.platform.diff.tests.iml @@ -3,6 +3,7 @@ + @@ -17,5 +18,6 @@ + \ No newline at end of file diff --git a/platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png b/platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png new file mode 100644 index 0000000000000000000000000000000000000000..b3fbf769502ac55814199083937ef5b0703c9478 GIT binary patch literal 357 zcmV-r0h<1aP)UE_=p<+etGG#)_M*9<68z0 zK<nrb0VEA_1%(b7;VzTA z_=dkBsS@1*xd!5#^U}3|C^-NDq;rtvmIw$SfJlMt66(kx;kf_-Bn`6rj1K9rLk_p= z1r}A3D$)HxAoDzn6dl6I08$oYec&wt(t2YT1qmT)qI3ar1SAF05=K497UeWumQ1qJ z7*|H--wUk@qG?f$U1*aIX@OA!B)5~YKqPaBDv<3W~)!J6SNq5D-OG!bgex_<2Ip^wO9+Duy0nQg( zO356Kh`kcKn+&sVmP7b#h@gNN{t>8b^b3Fb_!p?kHR-rCLXW3-$m`3vT&BVgc8V4AJ0vFipHi!EHfW z!D#@VeW!c4HQwH0`%gujyt8;@jV9Tu+=Y(dUe_G{Em~4>>Tq|UT>&S_yA96r92XL9 t{g+F-@Jv|wp-z|8?yF2KD8?h6y02n$1XEz|%2002ovPDHLkV1i&>dVT-^ literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png new file mode 100644 index 0000000000000000000000000000000000000000..32178299d554d01c889d340e7da520b077ef2972 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^en8C6!3HF~*8RK!r0P6f978H@y}j_0>QJ98 zvz=*c%wrC7#_2m3UA(z}-CwcZ>T@-7JI@LB6;$rnUVPEgtgkm)anBp&L-U#U$7mn? idP?kh6Y~w_$-)z^mcMpfcIFz;B@CXfelF{r5}E)mJV@gJ literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png new file mode 100644 index 0000000000000000000000000000000000000000..d68230c5285a40fa4d38dc707226f1ba23762c86 GIT binary patch literal 342 zcmV-c0jd6pP)sW!EJ^;@SydHUKA0f!O z6t$QSzyQmEM}c+;Tq5s{+3dIgKE6aq;Q&?urh*lLTPq!4fX@NfHYe$Cud&J1=0_(- zs|+x}00Rs#z+6{0ol^n6;dP~3;1Qvxx~`PG@7?iDd0lw~?Cf6wu=3gtu=2(UaN|1d o3b@yGr8IY{O^!|uV1O;37a)MQ7Ze{zA^-pY07*qoM6N<$f&uA{mjD0& literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png b/platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png new file mode 100644 index 0000000000000000000000000000000000000000..3a2f27a8a8a46814dc09077fcc89f84f7cc6263f GIT binary patch literal 235 zcmVaOB|djMx?QEl#9Z9hcCopbKiX!C#r&JK6APMb%?QE^3uXT3z2 z92mKP`vKh2>&~&l1=xorfCDZV-2R0GI33&>>`T0%TNOCq+QD(gaXGYsYk@W_9PhY? l&ymC5F5s9PfCH{CxEU=1M$L+1NdW)=002ovPDHLkV1gU~W32!H literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png b/platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png new file mode 100644 index 0000000000000000000000000000000000000000..ec7c54b5d6964972fcd7080d713edb2a3fa242d9 GIT binary patch literal 259 zcmV+e0sQ`nP){|3EP@8B)=Qt80bi5tn#C2{{l9)uLiM`Bu)_E?&C)LL7FeON+(11=U^ zDa9R5L|!5^TnF326D|r=x{3qt3ph)QYIDzO`&(4pKIh#UZ60vI+2M}XY4fN!DsEBX zS%(NW2d-Se{Q+F>b?11(1=xorfCDZV-1tHQoDOaeb|v1eTNSuOaN~qOJ*R^6e8)*Z zv^2v(vbE|j(6n%p4bJ-0nI@#cH{Z;?~002ov JPDHLkV1gVdZ4>|i literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png b/platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png new file mode 100644 index 0000000000000000000000000000000000000000..e2d2e07998c1fb0a8a1d46ee5add8c59a8175543 GIT binary patch literal 309 zcmV-50m}Y~P)mzh>H&Vkeku}JPwd(!buhpaf&Uo|-m@#lO}Y-2^EF!Z?Eo0y`@p(!4q!TX{ZmBG zWjG2`7ndiS9IGmm0b8 z9T`_@;k*WT@@xlq^2G^o=bTOjJSwjAo;~W4W0M0I;K+Ibky~fi*!sv{00000NkvXX Hu0mjf%!++Y literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/lineMarker.png b/platform/diff-impl/tests/testData/diff/painting/lineMarker.png new file mode 100644 index 0000000000000000000000000000000000000000..d9253b610934532d991c1d1f9bb5623d418049a8 GIT binary patch literal 351 zcmV-l0igbgP)XTvo42plhymn2~$)Imh#tBNB8=aegmtu#Su0Azt!=@39Nm&%i6^>-Z-e+Lji(ja$G=#UZaGP%Py z{tZc$=-vy+(zXUl=6UwowSpKq00E?PkoA@b2q1uHf$S3M$RP2#00ATovipn<>99i% zAJ+>ERgx;v9S}eO0mK-{w&AS-()z*f5+sJGiP8ng5s(&0OBnMYAtm;002ovPDHLkV1i5`jWYlM literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/newlineChanged.png b/platform/diff-impl/tests/testData/diff/painting/newlineChanged.png new file mode 100644 index 0000000000000000000000000000000000000000..999df9beb40d164cdbbdc9682f96cce356ad8ce5 GIT binary patch literal 249 zcmVkXvQA$A%t5iXDxCvxz(uJ8whAP69O}z;00000NkvXXu0mjfaf@jc literal 0 HcmV?d00001 diff --git a/platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png b/platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png new file mode 100644 index 0000000000000000000000000000000000000000..9b24cf2a9abd1d6847de2d7a47a22fcdd5a46910 GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^en8C6!3HF~*8RK!q{=*9978H@y}f>rx50p;_2Ksa zY&l2WOy%|@T)1U2?M3|qH_y+kP63l|y(;+r@cG`(%lmm{3bsBtvxZ@glStd`gMAU) z>Q;O^u0QxB*jr#|-oAVN&)I#KIW?OvFTQnv@jCzVJPStmpUm=PbN-ds7yAk5>UY4^D{7xF*x{>yvp?dw}>y}dPkBcgYBS?DF49x-LAYb-UnCR)e;X(f#HoAVLeKG|$i7;yu(U#K2;aEXuHfb~pieH;RN zBZk7>3%(2PNv_evnzUq+x}v(1V8OWRHS`8TgXehXD)F?brX`mOh+x63rDu^SJYrAb zfWw~MqHA*y)fS- ((DocumentEx)myEditor.getDocument()).moveText(5, 10, 0)); checkResult(); } + + public void testSoftWrapWithWithLineSeparator() throws Exception { + initText("x\nabcef\ny"); + configureSoftWraps(2); + verifySoftWrapPositions(4, 5); + + RangeHighlighter topHighlighter = addRangeHighlighter(4, 4, 0, null); + topHighlighter.setLineSeparatorColor(Color.red); + topHighlighter.setLineSeparatorPlacement(SeparatorPlacement.TOP); + + RangeHighlighter bottomHighlighter = addRangeHighlighter(4, 4, 0, null); + bottomHighlighter.setLineSeparatorColor(Color.blue); + bottomHighlighter.setLineSeparatorPlacement(SeparatorPlacement.BOTTOM); + + checkResult(); + } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java index 40e4759cc579..ff1ac87e8bea 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java @@ -21,12 +21,14 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterClient; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.editor.impl.AbstractEditorTest; +import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter; import com.intellij.openapi.editor.impl.view.FontLayoutService; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.HighlighterTargetArea; +import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.tree.IElementType; @@ -69,7 +71,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { } protected void checkResult() throws IOException { - checkResult(getFileName()); + checkResult(getFileName(), false); + } + + protected void checkResultWithGutter() throws IOException { + checkResult(getFileName(), true); } @NotNull @@ -81,24 +87,24 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { ((EditorEx)myEditor).setHighlighter(new UniformHighlighter(attributes)); } - protected static void addRangeHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { - addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); + protected static RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { + return addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); } - protected static void addLineHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { - addLineHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); + protected static RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { + return addLineHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); } - protected static void addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { - myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.EXACT_RANGE); + protected static RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { + return myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.EXACT_RANGE); } - protected static void addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { - myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); + protected static RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { + return myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); } - protected static void addBorderHighlighter(int startOffset, int endOffset, int layer, Color borderColor) { - addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(null, null, borderColor, EffectType.BOXED, Font.PLAIN)); + protected static RangeHighlighter addBorderHighlighter(int startOffset, int endOffset, int layer, Color borderColor) { + return addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(null, null, borderColor, EffectType.BOXED, Font.PLAIN)); } @Override @@ -165,18 +171,29 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { return TEST_DATA_PATH; } - private void checkResult(@TestDataFile String expectedResultFileName) throws IOException { + private void checkResult(@TestDataFile String expectedResultFileName, boolean withGutter) throws IOException { myEditor.getSettings().setAdditionalLinesCount(0); myEditor.getSettings().setAdditionalColumnsCount(1); + JComponent editorComponent = myEditor.getContentComponent(); - Dimension size = editorComponent.getPreferredSize(); - editorComponent.setSize(size); + JComponent gutterComponent = withGutter ? ((EditorImpl)myEditor).getGutterComponentEx() : new MyEmptyPanel(); + + Dimension editorSize = editorComponent.getPreferredSize(); + Dimension gutterSize = gutterComponent.getPreferredSize(); + Dimension imageSize = new Dimension(editorSize.width + gutterSize.width, Math.max(editorSize.height, gutterSize.height)); + + editorComponent.setSize(editorSize.width, imageSize.height); + gutterComponent.setSize(gutterSize.width, imageSize.height); + //noinspection UndesirableClassUsage - BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); + BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB); BitmapFont plainFont = BitmapFont.loadFromFile(getFontFile(false)); BitmapFont boldFont = BitmapFont.loadFromFile(getFontFile(true)); MyGraphics graphics = new MyGraphics(image.createGraphics(), plainFont, boldFont); try { + gutterComponent.paint(graphics); + graphics.translate(gutterComponent.getWidth(), 0); + editorComponent.paint(graphics); } finally { @@ -258,6 +275,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { } } + @Override + public void drawString(String str, int x, int y) { + drawString(str, (float)x, (float)y); + } + private void drawChar(char c, int x, int y) { (((getFont().getStyle() & Font.BOLD) == 0) ? myPlainFont : myBoldFont).draw(myDelegate, c, x, y); } @@ -409,4 +431,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { BitmapFont boldBont = BitmapFont.createFromFont(font.deriveFont(Font.BOLD)); boldBont.saveToFile(getFontFile(true)); } + + private static class MyEmptyPanel extends JComponent { + @Override + public Dimension getPreferredSize() { + return new Dimension(0, 0); + } + } }