1+ require_relative 'test_helpers'
2+
3+ def test_default_height_is_calculated_from_padding_and_font_height ( _args , assert )
4+ _ , font_height = $gtk. calcstringbox ( 'A' , 0 )
5+ text_input = Input ::Text . new ( padding : 10 , size_enum : 0 )
6+
7+ assert . equal! text_input . h , font_height + 20
8+ end
9+
10+ def test_multiline_scrolls_in_font_height_steps_by_default ( args , assert )
11+ $args = args
12+ _ , font_height = $gtk. calcstringbox ( 'A' , 0 )
13+ input = Input ::Multiline . new ( x : 100 , y : 100 , w : 100 , size_enum : 0 )
14+ input . insert "line 1\n "
15+ input . insert "line 2\n "
16+ input . insert "line 3\n "
17+
18+ assert . equal! input . scroll_y , 0
19+
20+ mouse_is_inside ( input )
21+ args . inputs . mouse . wheel = { y : 1 }
22+ input . tick
23+
24+ assert . equal! input . scroll_y , font_height
25+ end
26+
27+ def test_text_click_inside_sets_selection ( args , assert )
28+ $args = args
29+ three_letters_wide , _ = $gtk. calcstringbox ( 'ABC' , 0 )
30+ input = Input ::Text . new ( x : 100 , y : 100 , w : 100 , size_enum : 0 , value : 'ABCDEF' , focussed : true )
31+
32+ mouse_is_inside ( input , x : 100 + three_letters_wide )
33+ mouse_down
34+ input . tick
35+
36+ mouse_up
37+ input . tick
38+
39+ assert . equal! input . selection_start , 3
40+ assert . equal! input . selection_end , 3
41+ end
42+
43+ def test_text_drag_inside_sets_selection ( args , assert )
44+ $args = args
45+ three_letters_wide , _ = $gtk. calcstringbox ( 'ABC' , 0 )
46+ six_letters_wide , _ = $gtk. calcstringbox ( 'ABCDEF' , 0 )
47+ input = Input ::Text . new ( x : 100 , y : 100 , w : 100 , size_enum : 0 , value : 'ABCDEFGH' , focussed : true )
48+
49+ mouse_is_inside ( input , x : 100 + three_letters_wide )
50+ mouse_down
51+ input . tick
52+ mouse_is_inside ( input , x : 100 + six_letters_wide )
53+ mouse_up
54+ input . tick
55+
56+ assert . equal! input . selection_start , 3
57+ assert . equal! input . selection_end , 6
58+ end
59+
60+ def test_multiline_click_inside_sets_selection ( args , assert )
61+ $args = args
62+ three_letters_wide , font_height = $gtk. calcstringbox ( 'ABC' , 0 )
63+ input = Input ::Multiline . new ( x : 100 , y : 100 , w : 100 , h : font_height * 2 , size_enum : 0 , value : "ABCDEF\n GHIJKL" , focussed : true )
64+ inside_second_line_y = input . y + font_height . half
65+
66+ mouse_is_at ( 100 + three_letters_wide , inside_second_line_y )
67+ mouse_down
68+ input . tick
69+ mouse_up
70+ input . tick
71+
72+
73+ # 10 = ABCDEF\nGHI
74+ assert . equal! input . selection_start , 10
75+ assert . equal! input . selection_end , 10
76+ end
77+
78+ def test_text_drag_inside_sets_selection ( args , assert )
79+ $args = args
80+ three_letters_wide , font_height = $gtk. calcstringbox ( 'ABC' , 0 )
81+ input = Input ::Multiline . new ( x : 100 , y : 100 , w : 100 , h : font_height * 2 , size_enum : 0 , value : "ABCDEF\n GHIJKL" , focussed : true )
82+ inside_second_line_y = input . y + font_height . half
83+ inside_first_line_y = inside_second_line_y + font_height
84+
85+ mouse_is_at ( 100 + three_letters_wide , inside_first_line_y )
86+ mouse_down
87+ input . tick
88+
89+ mouse_is_at ( 100 + three_letters_wide , inside_second_line_y )
90+ mouse_up
91+ input . tick
92+
93+ assert . equal! input . selection_start , 3
94+ assert . equal! input . selection_end , 10
95+ end
96+
97+ # Two representative test cases using size_px instead of size_enum
98+
99+ def test_default_height_is_calculated_from_padding_and_font_height_size_px ( _args , assert )
100+ _ , font_height = $gtk. calcstringbox ( 'A' , size_px : 30 )
101+ text_input = Input ::Text . new ( padding : 10 , size_px : 30 )
102+
103+ assert . equal! text_input . h , font_height + 20
104+ end
105+
106+ def test_text_drag_inside_sets_selection_size_px ( args , assert )
107+ $args = args
108+ three_letters_wide , _ = $gtk. calcstringbox ( 'ABC' , size_px : 44 )
109+ six_letters_wide , _ = $gtk. calcstringbox ( 'ABCDEF' , size_px : 44 )
110+ input = Input ::Text . new ( x : 100 , y : 100 , w : 200 , size_px : 44 , value : 'ABCDEFGH' , focussed : true )
111+
112+ mouse_is_inside ( input , x : 100 + three_letters_wide )
113+ mouse_down
114+ input . tick
115+ mouse_is_inside ( input , x : 100 + six_letters_wide )
116+ mouse_up
117+ input . tick
118+
119+ assert . equal! input . selection_start , 3
120+ assert . equal! input . selection_end , 6
121+ end
0 commit comments