forked from vlang/vglyph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_validation_test.v
More file actions
153 lines (135 loc) · 3.88 KB
/
Copy path_validation_test.v
File metadata and controls
153 lines (135 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
module vglyph
import os
fn test_validate_text_valid() {
// Normal UTF-8 should pass
result := validate_text_input('Hello, World!', 1024, 'test') or {
assert false, 'Valid text should not error: ${err}'
return
}
assert result == 'Hello, World!'
}
fn test_validate_text_valid_unicode() {
// Multi-byte UTF-8 (CJK, emoji) should pass
result := validate_text_input('Hello', 1024, 'test') or {
assert false, 'Valid unicode should not error: ${err}'
return
}
assert result.len > 0
}
fn test_validate_text_invalid_utf8() {
// Invalid UTF-8 bytes should be rejected
invalid_bytes := [u8(0xff), 0xfe].bytestr()
validate_text_input(invalid_bytes, 1024, 'test') or {
assert err.msg().contains('invalid UTF-8')
return
}
assert false, 'Invalid UTF-8 should error'
}
fn test_validate_text_empty() {
// Empty string should be rejected
validate_text_input('', 1024, 'test') or {
assert err.msg().contains('empty string')
return
}
assert false, 'Empty string should error'
}
fn test_validate_text_too_long() {
// Text exceeding limit should be rejected
long_text := 'x'.repeat(2000)
validate_text_input(long_text, 1000, 'test') or {
assert err.msg().contains('exceeds max')
return
}
assert false, 'Too long text should error'
}
fn test_validate_path_valid() {
// Create temp file to test valid path
tmp_path := os.temp_dir() + '/vglyph_test_font.ttf'
os.write_file(tmp_path, 'dummy') or { return }
defer { os.rm(tmp_path) or {} }
result := validate_font_path(tmp_path, 'test') or {
assert false, 'Valid path should not error: ${err}'
return
}
assert result == tmp_path
}
fn test_validate_path_traversal() {
// Path with ".." should be rejected
validate_font_path('/fonts/../etc/passwd', 'test') or {
assert err.msg().contains('path traversal')
return
}
assert false, 'Path traversal should error'
}
fn test_validate_path_nonexistent() {
// Non-existent path should be rejected
validate_font_path('/nonexistent/path/to/font.ttf', 'test') or {
assert err.msg().contains('does not exist')
return
}
assert false, 'Nonexistent path should error'
}
fn test_validate_path_empty() {
// Empty path should be rejected
validate_font_path('', 'test') or {
assert err.msg().contains('empty font path')
return
}
assert false, 'Empty path should error'
}
fn test_validate_size_valid() {
// Size within bounds should pass
result := validate_size(12.0, 0.1, 500.0, 'font size', 'test') or {
assert false, 'Valid size should not error: ${err}'
return
}
assert result == 12.0
}
fn test_validate_size_bounds() {
// Size below minimum should be rejected
validate_size(0.05, 0.1, 500.0, 'font size', 'test') or {
assert err.msg().contains('out of range')
return
}
assert false, 'Size below min should error'
}
fn test_validate_size_above_max() {
// Size above maximum should be rejected
validate_size(600.0, 0.1, 500.0, 'font size', 'test') or {
assert err.msg().contains('out of range')
return
}
assert false, 'Size above max should error'
}
fn test_validate_dimension_valid() {
// Valid dimension should pass
result := validate_dimension(1024, 'width', 'test') or {
assert false, 'Valid dimension should not error: ${err}'
return
}
assert result == 1024
}
fn test_validate_dimension_zero() {
// Zero dimension should be rejected
validate_dimension(0, 'width', 'test') or {
assert err.msg().contains('must be positive')
return
}
assert false, 'Zero dimension should error'
}
fn test_validate_dimension_negative() {
// Negative dimension should be rejected
validate_dimension(-100, 'height', 'test') or {
assert err.msg().contains('must be positive')
return
}
assert false, 'Negative dimension should error'
}
fn test_validate_dimension_exceeds_max() {
// Dimension exceeding max should be rejected
validate_dimension(20000, 'atlas size', 'test') or {
assert err.msg().contains('exceeds max')
return
}
assert false, 'Dimension exceeding max should error'
}