File tree Expand file tree Collapse file tree
integrationTest/java/org/fxmisc/richtext
main/java/org/fxmisc/richtext Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .fxmisc .richtext ;
2+
3+ import java .util .function .Function ;
4+
5+ public class TextBuildingUtils {
6+
7+ private TextBuildingUtils () {
8+ throw new IllegalStateException ("Cannot construct an instance of TextBuildingUtils" );
9+ }
10+
11+ /** Builds {@code totalNumber} of lines that each have the index of the line as their text */
12+ public static String buildLines (int totalNumber ) { return buildLines (totalNumber , String ::valueOf ); }
13+
14+ public static String buildLines (int totalNumber , Function <Integer , String > textOnEachLine ) {
15+ StringBuilder sb = new StringBuilder ();
16+ for (int i = 0 ; i < totalNumber - 1 ; i ++) {
17+ sb .append (textOnEachLine .apply (i )).append ("\n " );
18+ }
19+ sb .append (textOnEachLine .apply (totalNumber ));
20+ return sb .toString ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package org .fxmisc .richtext .api ;
2+
3+ import javafx .stage .Stage ;
4+ import org .fxmisc .richtext .InlineCssTextAreaAppTest ;
5+ import org .fxmisc .richtext .TextBuildingUtils ;
6+ import org .junit .Test ;
7+
8+ import java .util .Optional ;
9+
10+ import static org .junit .Assert .assertEquals ;
11+
12+ public class ParagraphIndexMappingTests extends InlineCssTextAreaAppTest {
13+
14+ private static final int TOTAL_NUMBER_OF_LINES = 80 ;
15+ private static final int LAST_PAR_INDEX = TOTAL_NUMBER_OF_LINES - 1 ;
16+ private static final String CONTENT = TextBuildingUtils .buildLines (TOTAL_NUMBER_OF_LINES );
17+
18+ @ Override
19+ public void start (Stage stage ) throws Exception {
20+ super .start (stage );
21+ area .replaceText (CONTENT );
22+ }
23+
24+ @ Test
25+ public void all_par_to_visible_par_index_is_correct () {
26+ interact (() -> area .showParagraphAtTop (0 ));
27+ assertEquals (Optional .of (0 ), area .allParToVisibleParIndex (0 ));
28+
29+ interact (() -> area .showParagraphAtBottom (LAST_PAR_INDEX ));
30+ assertEquals (Optional .of (area .getVisibleParagraphs ().size () - 1 ), area .allParToVisibleParIndex (LAST_PAR_INDEX ));
31+ }
32+
33+ @ Test
34+ public void visible_par_to_all_par_index_is_correct () {
35+ interact (() -> area .showParagraphAtTop (0 ));
36+ assertEquals (0 , area .visibleParToAllParIndex (0 ));
37+
38+ interact (() -> area .showParagraphAtBottom (LAST_PAR_INDEX ));
39+ assertEquals (LAST_PAR_INDEX , area .visibleParToAllParIndex (area .getVisibleParagraphs ().size () - 1 ));
40+
41+ }
42+ }
Original file line number Diff line number Diff line change 33import javafx .geometry .Bounds ;
44import javafx .stage .Stage ;
55import org .fxmisc .richtext .InlineCssTextAreaAppTest ;
6+ import org .fxmisc .richtext .TextBuildingUtils ;
67import org .junit .Test ;
78
89import static javafx .scene .input .KeyCode .PAGE_DOWN ;
1314
1415public class PageUpDownTests extends InlineCssTextAreaAppTest {
1516
16- private static final String EIGHT_LINES ;
17-
18- static {
19- StringBuilder sb = new StringBuilder ();
20- int totalLines = 8 ;
21- for (int i = 0 ; i < totalLines - 1 ; i ++) {
22- sb .append (i ).append ("\n " );
23- }
24- sb .append (totalLines );
25- EIGHT_LINES = sb .toString ();
26- }
17+ private static final String EIGHT_LINES = TextBuildingUtils .buildLines (8 );
2718
2819 @ Override
2920 public void start (Stage stage ) throws Exception {
Original file line number Diff line number Diff line change @@ -792,9 +792,9 @@ public final double getViewportHeight() {
792792 @ Override
793793 public final Optional <Integer > allParToVisibleParIndex (int allParIndex ) {
794794 if (allParIndex < 0 ) {
795- throw new IllegalArgumentException ("Visible paragraph index cannot be negative but was " + allParIndex );
795+ throw new IllegalArgumentException ("The given paragraph index (allParIndex) cannot be negative but was " + allParIndex );
796796 }
797- if (allParIndex >= getVisibleParagraphs ().size ()) {
797+ if (allParIndex >= getParagraphs ().size ()) {
798798 throw new IllegalArgumentException (String .format (
799799 "Paragraphs' last index is [%s] but allParIndex was [%s]" ,
800800 getParagraphs ().size () - 1 , allParIndex )
You can’t perform that action at this time.
0 commit comments