|
16 | 16 | import static org.junit.jupiter.api.Assertions.assertThrows; |
17 | 17 |
|
18 | 18 | import org.junit.jupiter.api.Test; |
| 19 | +import org.junit.jupiter.params.ParameterizedTest; |
| 20 | +import org.junit.jupiter.params.provider.CsvSource; |
19 | 21 |
|
20 | 22 | import org.eclipse.swt.SWT; |
21 | 23 | import org.eclipse.swt.dnd.Clipboard; |
@@ -516,4 +518,69 @@ private ProjectionAnnotation addVisibleRegionAndProjection(TestProjectionViewer |
516 | 518 | viewer.getProjectionAnnotationModel().addAnnotation(annotation, new Position(projectionStart, projectionEnd - projectionStart)); |
517 | 519 | return annotation; |
518 | 520 | } |
| 521 | + |
| 522 | + @ParameterizedTest |
| 523 | + @CsvSource({ "true", "false" }) |
| 524 | + void testDifferentLineEndings(boolean crlf) { |
| 525 | + Shell shell= new Shell(Display.getCurrent()); |
| 526 | + shell.setLayout(new FillLayout()); |
| 527 | + TestProjectionViewer viewer= new TestProjectionViewer(shell, null, null, true, SWT.ALL); |
| 528 | + String documentContent= """ |
| 529 | + // before |
| 530 | + { |
| 531 | + // within |
| 532 | + } |
| 533 | + // after |
| 534 | + """; |
| 535 | + if (crlf) { |
| 536 | + documentContent= documentContent.replace("\n", "\r\n"); |
| 537 | + } |
| 538 | + Document document= new Document(documentContent); |
| 539 | + viewer.setDocument(document, new AnnotationModel()); |
| 540 | + int start= documentContent.indexOf('{'); |
| 541 | + int end= documentContent.indexOf('}') + 1; |
| 542 | + viewer.enableProjection(); |
| 543 | + viewer.setVisibleRegion(start, end - start); |
| 544 | + assertEquals(documentContent.substring(start, documentContent.indexOf("// after")), viewer.getVisibleDocument().get()); |
| 545 | + } |
| 546 | + |
| 547 | + @Test |
| 548 | + void testIncludesLastLineIfAdditionalTextPresent() { |
| 549 | + Shell shell= new Shell(Display.getCurrent()); |
| 550 | + shell.setLayout(new FillLayout()); |
| 551 | + TestProjectionViewer viewer= new TestProjectionViewer(shell, null, null, true, SWT.ALL); |
| 552 | + String documentContent= """ |
| 553 | + // before |
| 554 | + { |
| 555 | + // within |
| 556 | + }// ... |
| 557 | + // should be hidden |
| 558 | + """; |
| 559 | + Document document= new Document(documentContent); |
| 560 | + viewer.setDocument(document, new AnnotationModel()); |
| 561 | + int start= documentContent.indexOf('{'); |
| 562 | + int end= documentContent.indexOf('}') + 1; |
| 563 | + viewer.enableProjection(); |
| 564 | + viewer.setVisibleRegion(start, end - start); |
| 565 | + assertEquals(documentContent.substring(start, documentContent.indexOf("// should be hidden")), viewer.getVisibleDocument().get()); |
| 566 | + } |
| 567 | + |
| 568 | + @Test |
| 569 | + void testSetVisibleRegionUntilEOF() { |
| 570 | + Shell shell= new Shell(Display.getCurrent()); |
| 571 | + shell.setLayout(new FillLayout()); |
| 572 | + TestProjectionViewer viewer= new TestProjectionViewer(shell, null, null, true, SWT.ALL); |
| 573 | + String documentContent= """ |
| 574 | + // before |
| 575 | + { |
| 576 | + // within |
| 577 | + }"""; |
| 578 | + Document document= new Document(documentContent); |
| 579 | + viewer.setDocument(document, new AnnotationModel()); |
| 580 | + int start= documentContent.indexOf('{'); |
| 581 | + int end= documentContent.indexOf('}') + 1; |
| 582 | + viewer.enableProjection(); |
| 583 | + viewer.setVisibleRegion(start, end - start); |
| 584 | + assertEquals(documentContent.substring(start), viewer.getVisibleDocument().get()); |
| 585 | + } |
519 | 586 | } |
0 commit comments