fortrangoingonforty/facsimile / de5bbe1

Browse files

automated tests utf8 fixes

Authored by espadonne
SHA
de5bbe1d8375f3f2b98a0f515082a7caa548aab3
Parents
48e6d83
Tree
7ee594f

1 changed file

StatusFile+-
A test/test_utf8_integration.f90 151 0
test/test_utf8_integration.f90added
@@ -0,0 +1,151 @@
1
+program test_utf8_integration
2
+    use test_framework
3
+    use utf8_module
4
+    use text_buffer_module
5
+    implicit none
6
+
7
+    type(test_suite) :: suite
8
+
9
+    ! Initialize test suite
10
+    suite%name = "UTF-8 Integration Tests"
11
+    allocate(suite%tests(10))
12
+
13
+    ! UTF-8 Module Tests
14
+    suite%tests(1) = test_case("UTF-8 ASCII char count", test_utf8_ascii_count)
15
+    suite%tests(2) = test_case("UTF-8 box char count", test_utf8_box_char_count)
16
+    suite%tests(3) = test_case("UTF-8 mixed content count", test_utf8_mixed_count)
17
+    suite%tests(4) = test_case("UTF-8 char to byte index", test_char_to_byte_index)
18
+    suite%tests(5) = test_case("UTF-8 byte to char index", test_byte_to_char_index)
19
+    suite%tests(6) = test_case("UTF-8 display width", test_display_width)
20
+    suite%tests(7) = test_case("UTF-8 char extraction", test_char_at)
21
+
22
+    ! Buffer UTF-8 Tests
23
+    suite%tests(8) = test_case("Buffer UTF-8 line char count", test_buffer_char_count)
24
+    suite%tests(9) = test_case("Buffer char to byte conversion", test_buffer_conversions)
25
+    suite%tests(10) = test_case("Buffer UTF-8 char extraction", test_buffer_char_at)
26
+
27
+    ! Run all tests
28
+    call run_tests(suite)
29
+
30
+    ! Exit with proper code
31
+    if (suite%num_failed > 0) then
32
+        stop 1
33
+    end if
34
+
35
+contains
36
+
37
+    subroutine test_utf8_ascii_count()
38
+        integer :: count
39
+        count = utf8_char_count("Hello")
40
+        call assert_equals(5, count, "ASCII string char count")
41
+    end subroutine test_utf8_ascii_count
42
+
43
+    subroutine test_utf8_box_char_count()
44
+        integer :: count
45
+        ! Box drawing chars: ├ (3 bytes) ─ (3 bytes) ─ (3 bytes) = 9 bytes, 3 chars
46
+        count = utf8_char_count("├──")
47
+        call assert_equals(3, count, "Box drawing chars count")
48
+    end subroutine test_utf8_box_char_count
49
+
50
+    subroutine test_utf8_mixed_count()
51
+        integer :: count
52
+        ! "    ├── Tab" = 4 spaces + 3 box chars + space + 3 letters = 11 chars
53
+        count = utf8_char_count("    ├── Tab")
54
+        call assert_equals(11, count, "Mixed content char count")
55
+    end subroutine test_utf8_mixed_count
56
+
57
+    subroutine test_char_to_byte_index()
58
+        integer :: byte_idx
59
+        ! In "├──", char 2 (second ─) starts at byte 4
60
+        byte_idx = utf8_char_to_byte_index("├──", 2)
61
+        call assert_equals(4, byte_idx, "Char 2 to byte index")
62
+
63
+        ! Char 3 starts at byte 7
64
+        byte_idx = utf8_char_to_byte_index("├──", 3)
65
+        call assert_equals(7, byte_idx, "Char 3 to byte index")
66
+    end subroutine test_char_to_byte_index
67
+
68
+    subroutine test_byte_to_char_index()
69
+        integer :: char_idx
70
+        ! In "├──", byte 4 is start of char 2
71
+        char_idx = utf8_byte_to_char_index("├──", 4)
72
+        call assert_equals(2, char_idx, "Byte 4 to char index")
73
+
74
+        ! Byte 7 is start of char 3
75
+        char_idx = utf8_byte_to_char_index("├──", 7)
76
+        call assert_equals(3, char_idx, "Byte 7 to char index")
77
+    end subroutine test_byte_to_char_index
78
+
79
+    subroutine test_display_width()
80
+        integer :: width
81
+        ! ASCII: 1 char = 1 column
82
+        width = utf8_display_width("Hello")
83
+        call assert_equals(5, width, "ASCII display width")
84
+
85
+        ! Box chars: 1 char = 1 column
86
+        width = utf8_display_width("├──")
87
+        call assert_equals(3, width, "Box chars display width")
88
+    end subroutine test_display_width
89
+
90
+    subroutine test_char_at()
91
+        character(len=:), allocatable :: char_str
92
+
93
+        ! Get second character from "├──"
94
+        char_str = utf8_char_at("├──", 2)
95
+        call assert_true(allocated(char_str), "Char extraction allocated")
96
+        call assert_equals(3, len(char_str), "Second box char is 3 bytes")
97
+
98
+        if (allocated(char_str)) deallocate(char_str)
99
+    end subroutine test_char_at
100
+
101
+    subroutine test_buffer_char_count()
102
+        type(buffer_t) :: buffer
103
+        integer :: count
104
+
105
+        ! Create buffer with UTF-8 content
106
+        call init_buffer(buffer, "├── Box chars" // char(10) // "Normal line")
107
+
108
+        ! Line 1 should have 13 characters
109
+        count = buffer_get_line_char_count(buffer, 1)
110
+        call assert_equals(13, count, "Buffer line 1 char count")
111
+
112
+        ! Line 2 should have 11 characters
113
+        count = buffer_get_line_char_count(buffer, 2)
114
+        call assert_equals(11, count, "Buffer line 2 char count")
115
+
116
+        call cleanup_buffer(buffer)
117
+    end subroutine test_buffer_char_count
118
+
119
+    subroutine test_buffer_conversions()
120
+        type(buffer_t) :: buffer
121
+        integer :: byte_col, char_col
122
+
123
+        call init_buffer(buffer, "├──")
124
+
125
+        ! Char 2 should be at byte 4
126
+        byte_col = buffer_char_to_byte_col(buffer, 1, 2)
127
+        call assert_equals(4, byte_col, "Buffer char to byte")
128
+
129
+        ! Byte 4 should be char 2
130
+        char_col = buffer_byte_to_char_col(buffer, 1, 4)
131
+        call assert_equals(2, char_col, "Buffer byte to char")
132
+
133
+        call cleanup_buffer(buffer)
134
+    end subroutine test_buffer_conversions
135
+
136
+    subroutine test_buffer_char_at()
137
+        type(buffer_t) :: buffer
138
+        character(len=:), allocatable :: char_str
139
+
140
+        call init_buffer(buffer, "├──")
141
+
142
+        ! Get first character
143
+        char_str = buffer_char_at(buffer, 1, 1)
144
+        call assert_true(allocated(char_str), "Buffer char_at allocated")
145
+        call assert_equals(3, len(char_str), "First box char is 3 bytes")
146
+
147
+        if (allocated(char_str)) deallocate(char_str)
148
+        call cleanup_buffer(buffer)
149
+    end subroutine test_buffer_char_at
150
+
151
+end program test_utf8_integration