@owenlamont/ryl 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/dependabot.yml +13 -0
  3. package/.github/workflows/ci.yml +107 -0
  4. package/.github/workflows/release.yml +613 -0
  5. package/.github/workflows/update_dependencies.yml +61 -0
  6. package/.github/workflows/update_linters.yml +56 -0
  7. package/.pre-commit-config.yaml +87 -0
  8. package/.yamllint +4 -0
  9. package/AGENTS.md +200 -0
  10. package/Cargo.lock +908 -0
  11. package/Cargo.toml +32 -0
  12. package/LICENSE +21 -0
  13. package/README.md +230 -0
  14. package/bin/ryl.js +1 -0
  15. package/clippy.toml +1 -0
  16. package/docs/config-presets.md +100 -0
  17. package/img/benchmark-5x5-5runs.svg +2176 -0
  18. package/package.json +28 -0
  19. package/pyproject.toml +42 -0
  20. package/ruff.toml +107 -0
  21. package/rumdl.toml +20 -0
  22. package/rust-toolchain.toml +3 -0
  23. package/rustfmt.toml +3 -0
  24. package/scripts/benchmark_perf_vs_yamllint.py +400 -0
  25. package/scripts/coverage-missing.ps1 +80 -0
  26. package/scripts/coverage-missing.sh +60 -0
  27. package/src/bin/discover_config_bin.rs +24 -0
  28. package/src/cli_support.rs +33 -0
  29. package/src/conf/mod.rs +85 -0
  30. package/src/config.rs +2099 -0
  31. package/src/decoder.rs +326 -0
  32. package/src/discover.rs +31 -0
  33. package/src/lib.rs +19 -0
  34. package/src/lint.rs +558 -0
  35. package/src/main.rs +535 -0
  36. package/src/migrate.rs +233 -0
  37. package/src/rules/anchors.rs +517 -0
  38. package/src/rules/braces.rs +77 -0
  39. package/src/rules/brackets.rs +77 -0
  40. package/src/rules/colons.rs +475 -0
  41. package/src/rules/commas.rs +372 -0
  42. package/src/rules/comments.rs +299 -0
  43. package/src/rules/comments_indentation.rs +243 -0
  44. package/src/rules/document_end.rs +175 -0
  45. package/src/rules/document_start.rs +84 -0
  46. package/src/rules/empty_lines.rs +152 -0
  47. package/src/rules/empty_values.rs +255 -0
  48. package/src/rules/float_values.rs +259 -0
  49. package/src/rules/flow_collection.rs +562 -0
  50. package/src/rules/hyphens.rs +104 -0
  51. package/src/rules/indentation.rs +803 -0
  52. package/src/rules/key_duplicates.rs +218 -0
  53. package/src/rules/key_ordering.rs +303 -0
  54. package/src/rules/line_length.rs +326 -0
  55. package/src/rules/mod.rs +25 -0
  56. package/src/rules/new_line_at_end_of_file.rs +23 -0
  57. package/src/rules/new_lines.rs +95 -0
  58. package/src/rules/octal_values.rs +121 -0
  59. package/src/rules/quoted_strings.rs +577 -0
  60. package/src/rules/span_utils.rs +37 -0
  61. package/src/rules/trailing_spaces.rs +65 -0
  62. package/src/rules/truthy.rs +420 -0
  63. package/tests/brackets_carriage_return.rs +114 -0
  64. package/tests/build_global_cfg_error.rs +23 -0
  65. package/tests/cli_anchors_rule.rs +143 -0
  66. package/tests/cli_braces_rule.rs +104 -0
  67. package/tests/cli_brackets_rule.rs +104 -0
  68. package/tests/cli_colons_rule.rs +65 -0
  69. package/tests/cli_commas_rule.rs +104 -0
  70. package/tests/cli_comments_indentation_rule.rs +61 -0
  71. package/tests/cli_comments_rule.rs +67 -0
  72. package/tests/cli_config_data_error.rs +30 -0
  73. package/tests/cli_config_flags.rs +66 -0
  74. package/tests/cli_config_migrate.rs +229 -0
  75. package/tests/cli_document_end_rule.rs +92 -0
  76. package/tests/cli_document_start_rule.rs +92 -0
  77. package/tests/cli_empty_lines_rule.rs +87 -0
  78. package/tests/cli_empty_values_rule.rs +68 -0
  79. package/tests/cli_env_config.rs +34 -0
  80. package/tests/cli_exit_and_errors.rs +41 -0
  81. package/tests/cli_file_encoding.rs +203 -0
  82. package/tests/cli_float_values_rule.rs +64 -0
  83. package/tests/cli_format_options.rs +316 -0
  84. package/tests/cli_global_cfg_relaxed.rs +20 -0
  85. package/tests/cli_hyphens_rule.rs +104 -0
  86. package/tests/cli_indentation_rule.rs +65 -0
  87. package/tests/cli_invalid_project_config.rs +39 -0
  88. package/tests/cli_key_duplicates_rule.rs +104 -0
  89. package/tests/cli_key_ordering_rule.rs +59 -0
  90. package/tests/cli_line_length_rule.rs +85 -0
  91. package/tests/cli_list_files.rs +29 -0
  92. package/tests/cli_new_line_rule.rs +141 -0
  93. package/tests/cli_new_lines_rule.rs +119 -0
  94. package/tests/cli_octal_values_rule.rs +60 -0
  95. package/tests/cli_quoted_strings_rule.rs +47 -0
  96. package/tests/cli_toml_config.rs +119 -0
  97. package/tests/cli_trailing_spaces_rule.rs +77 -0
  98. package/tests/cli_truthy_rule.rs +83 -0
  99. package/tests/cli_yaml_files_negation.rs +45 -0
  100. package/tests/colons_rule.rs +303 -0
  101. package/tests/common/compat.rs +114 -0
  102. package/tests/common/fake_env.rs +93 -0
  103. package/tests/common/mod.rs +1 -0
  104. package/tests/conf_builtin.rs +9 -0
  105. package/tests/config_anchors.rs +84 -0
  106. package/tests/config_braces.rs +121 -0
  107. package/tests/config_brackets.rs +127 -0
  108. package/tests/config_commas.rs +79 -0
  109. package/tests/config_comments.rs +65 -0
  110. package/tests/config_comments_indentation.rs +20 -0
  111. package/tests/config_deep_merge_nonstring_key.rs +24 -0
  112. package/tests/config_document_end.rs +54 -0
  113. package/tests/config_document_start.rs +55 -0
  114. package/tests/config_empty_lines.rs +48 -0
  115. package/tests/config_empty_values.rs +35 -0
  116. package/tests/config_env_errors.rs +23 -0
  117. package/tests/config_env_invalid_inline.rs +15 -0
  118. package/tests/config_env_missing.rs +63 -0
  119. package/tests/config_env_shim.rs +301 -0
  120. package/tests/config_explicit_file_parse_error.rs +55 -0
  121. package/tests/config_extended_features.rs +225 -0
  122. package/tests/config_extends_inline.rs +185 -0
  123. package/tests/config_extends_sequence.rs +18 -0
  124. package/tests/config_find_project_home_boundary.rs +54 -0
  125. package/tests/config_find_project_two_files_in_cwd.rs +47 -0
  126. package/tests/config_float_values.rs +34 -0
  127. package/tests/config_from_yaml_paths.rs +32 -0
  128. package/tests/config_hyphens.rs +51 -0
  129. package/tests/config_ignore_errors.rs +243 -0
  130. package/tests/config_ignore_overrides.rs +83 -0
  131. package/tests/config_indentation.rs +65 -0
  132. package/tests/config_invalid_globs.rs +16 -0
  133. package/tests/config_invalid_types.rs +19 -0
  134. package/tests/config_key_duplicates.rs +34 -0
  135. package/tests/config_key_ordering.rs +70 -0
  136. package/tests/config_line_length.rs +65 -0
  137. package/tests/config_locale.rs +111 -0
  138. package/tests/config_merge.rs +26 -0
  139. package/tests/config_new_lines.rs +89 -0
  140. package/tests/config_octal_values.rs +33 -0
  141. package/tests/config_quoted_strings.rs +195 -0
  142. package/tests/config_rule_level.rs +147 -0
  143. package/tests/config_rules_non_string_keys.rs +23 -0
  144. package/tests/config_scalar_overrides.rs +27 -0
  145. package/tests/config_to_toml.rs +110 -0
  146. package/tests/config_toml_coverage.rs +80 -0
  147. package/tests/config_toml_discovery.rs +304 -0
  148. package/tests/config_trailing_spaces.rs +152 -0
  149. package/tests/config_truthy.rs +77 -0
  150. package/tests/config_yaml_files.rs +62 -0
  151. package/tests/config_yaml_files_all_non_string.rs +15 -0
  152. package/tests/config_yaml_files_empty.rs +30 -0
  153. package/tests/coverage_commas.rs +46 -0
  154. package/tests/decoder_decode.rs +338 -0
  155. package/tests/discover_config_bin_all.rs +66 -0
  156. package/tests/discover_config_bin_env_invalid_yaml.rs +26 -0
  157. package/tests/discover_config_bin_project_config_parse_error.rs +24 -0
  158. package/tests/discover_config_bin_user_global_error.rs +26 -0
  159. package/tests/discover_module.rs +30 -0
  160. package/tests/discover_per_file_dir.rs +10 -0
  161. package/tests/discover_per_file_project_config_error.rs +21 -0
  162. package/tests/float_values.rs +43 -0
  163. package/tests/lint_multi_errors.rs +32 -0
  164. package/tests/main_yaml_ok_filtering.rs +30 -0
  165. package/tests/migrate_module.rs +259 -0
  166. package/tests/resolve_ctx_empty_parent.rs +16 -0
  167. package/tests/rule_anchors.rs +442 -0
  168. package/tests/rule_braces.rs +258 -0
  169. package/tests/rule_brackets.rs +217 -0
  170. package/tests/rule_commas.rs +205 -0
  171. package/tests/rule_comments.rs +197 -0
  172. package/tests/rule_comments_indentation.rs +127 -0
  173. package/tests/rule_document_end.rs +118 -0
  174. package/tests/rule_document_start.rs +60 -0
  175. package/tests/rule_empty_lines.rs +96 -0
  176. package/tests/rule_empty_values.rs +102 -0
  177. package/tests/rule_float_values.rs +109 -0
  178. package/tests/rule_hyphens.rs +65 -0
  179. package/tests/rule_indentation.rs +455 -0
  180. package/tests/rule_key_duplicates.rs +76 -0
  181. package/tests/rule_key_ordering.rs +207 -0
  182. package/tests/rule_line_length.rs +200 -0
  183. package/tests/rule_new_lines.rs +51 -0
  184. package/tests/rule_octal_values.rs +53 -0
  185. package/tests/rule_quoted_strings.rs +290 -0
  186. package/tests/rule_trailing_spaces.rs +41 -0
  187. package/tests/rule_truthy.rs +236 -0
  188. package/tests/user_global_invalid_yaml.rs +32 -0
  189. package/tests/yamllint_compat_anchors.rs +280 -0
  190. package/tests/yamllint_compat_braces.rs +411 -0
  191. package/tests/yamllint_compat_brackets.rs +364 -0
  192. package/tests/yamllint_compat_colons.rs +298 -0
  193. package/tests/yamllint_compat_colors.rs +80 -0
  194. package/tests/yamllint_compat_commas.rs +375 -0
  195. package/tests/yamllint_compat_comments.rs +167 -0
  196. package/tests/yamllint_compat_comments_indentation.rs +281 -0
  197. package/tests/yamllint_compat_config.rs +170 -0
  198. package/tests/yamllint_compat_document_end.rs +243 -0
  199. package/tests/yamllint_compat_document_start.rs +136 -0
  200. package/tests/yamllint_compat_empty_lines.rs +117 -0
  201. package/tests/yamllint_compat_empty_values.rs +179 -0
  202. package/tests/yamllint_compat_float_values.rs +216 -0
  203. package/tests/yamllint_compat_hyphens.rs +223 -0
  204. package/tests/yamllint_compat_indentation.rs +398 -0
  205. package/tests/yamllint_compat_key_duplicates.rs +139 -0
  206. package/tests/yamllint_compat_key_ordering.rs +170 -0
  207. package/tests/yamllint_compat_line_length.rs +375 -0
  208. package/tests/yamllint_compat_list.rs +127 -0
  209. package/tests/yamllint_compat_new_line.rs +133 -0
  210. package/tests/yamllint_compat_newline_types.rs +185 -0
  211. package/tests/yamllint_compat_octal_values.rs +172 -0
  212. package/tests/yamllint_compat_quoted_strings.rs +154 -0
  213. package/tests/yamllint_compat_syntax.rs +200 -0
  214. package/tests/yamllint_compat_trailing_spaces.rs +162 -0
  215. package/tests/yamllint_compat_truthy.rs +130 -0
  216. package/tests/yamllint_compat_yaml_files.rs +81 -0
  217. package/typos.toml +2 -0
@@ -0,0 +1,338 @@
1
+ use std::path::Path;
2
+
3
+ use ryl::decoder;
4
+ use tempfile::tempdir;
5
+
6
+ #[test]
7
+ fn decode_utf8_plain() {
8
+ assert_eq!(decoder::decode_bytes(b"hello").unwrap(), "hello");
9
+ }
10
+
11
+ #[test]
12
+ fn decode_utf8_invalid_reports_error() {
13
+ let err = decoder::decode_bytes(&[0x80]).unwrap_err();
14
+ assert!(
15
+ err.contains("invalid utf-8 data"),
16
+ "expected utf-8 error, got: {err}"
17
+ );
18
+ }
19
+
20
+ #[test]
21
+ fn decode_utf8_bom_is_stripped() {
22
+ let data = [0xEF, 0xBB, 0xBF, b'h', b'i'];
23
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
24
+ }
25
+
26
+ #[test]
27
+ fn decode_utf8_sig_without_bom_is_identity() {
28
+ assert_eq!(
29
+ decoder::decode_bytes_with_override(b"hi", Some("utf-8-sig")).unwrap(),
30
+ "hi"
31
+ );
32
+ }
33
+
34
+ #[test]
35
+ fn decode_utf16_big_endian_with_bom() {
36
+ let data = [0xFE, 0xFF, 0x00, b'h', 0x00, b'i'];
37
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
38
+ }
39
+
40
+ #[test]
41
+ fn decode_utf16_little_endian_with_bom() {
42
+ let data = [0xFF, 0xFE, b'h', 0x00, b'i', 0x00];
43
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
44
+ }
45
+
46
+ #[test]
47
+ fn decode_utf16_big_endian_without_bom() {
48
+ let data = [0x00, b'h', 0x00, b'i'];
49
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
50
+ }
51
+
52
+ #[test]
53
+ fn decode_utf16_little_endian_without_bom() {
54
+ let data = [b'h', 0x00, b'i', 0x00];
55
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
56
+ }
57
+
58
+ #[test]
59
+ fn decode_utf16_invalid_length_reports_error() {
60
+ let err = decoder::decode_bytes(&[0xFF, 0xFE, 0x00]).unwrap_err();
61
+ assert!(err.contains("invalid utf-16"), "unexpected error: {err}");
62
+ }
63
+
64
+ #[test]
65
+ fn decode_utf32_big_endian_with_bom() {
66
+ let data = [
67
+ 0x00, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i',
68
+ ];
69
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
70
+ }
71
+
72
+ #[test]
73
+ fn decode_utf32_little_endian_with_bom() {
74
+ let data = [
75
+ 0xFF, 0xFE, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i', 0x00, 0x00, 0x00,
76
+ ];
77
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
78
+ }
79
+
80
+ #[test]
81
+ fn decode_utf32_big_endian_without_bom() {
82
+ let data = [0x00, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i'];
83
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
84
+ }
85
+
86
+ #[test]
87
+ fn decode_utf32_little_endian_without_bom() {
88
+ let data = [b'h', 0x00, 0x00, 0x00, b'i', 0x00, 0x00, 0x00];
89
+ assert_eq!(decoder::decode_bytes(&data).unwrap(), "hi");
90
+ }
91
+
92
+ #[test]
93
+ fn decode_utf32_invalid_length_reports_error() {
94
+ let data = [0x00, 0x00, 0x00, b'h', 0x00];
95
+ let err = decoder::decode_bytes(&data).unwrap_err();
96
+ assert!(err.contains("invalid utf-32"), "unexpected error: {err}");
97
+ }
98
+
99
+ #[test]
100
+ fn decode_utf32_invalid_scalar_reports_error() {
101
+ let data = [0x00, 0x00, 0xFE, 0xFF, 0x00, 0x11, 0x00, 0x00];
102
+ let err = decoder::decode_bytes(&data).unwrap_err();
103
+ assert!(
104
+ err.contains("invalid scalar value"),
105
+ "unexpected error: {err}"
106
+ );
107
+ }
108
+
109
+ #[test]
110
+ fn decode_utf16_invalid_scalar_reports_error() {
111
+ let err = decoder::decode_bytes_with_override(&[0xD8, 0x00], Some("utf-16be"))
112
+ .unwrap_err();
113
+ assert!(err.contains("invalid utf-16"));
114
+ }
115
+
116
+ #[test]
117
+ fn decode_with_override_utf16_variants() {
118
+ let big = [0xFE, 0xFF, 0x00, b'h', 0x00, b'i'];
119
+ assert_eq!(
120
+ decoder::decode_bytes_with_override(&big, Some("utf-16")).unwrap(),
121
+ "hi"
122
+ );
123
+ let big_no_bom = [0x00, b'h', 0x00, b'i'];
124
+ assert_eq!(
125
+ decoder::decode_bytes_with_override(&big_no_bom, Some("utf-16")).unwrap(),
126
+ "hi"
127
+ );
128
+ let little_bom = [0xFF, 0xFE, b'h', 0x00];
129
+ assert_eq!(
130
+ decoder::decode_bytes_with_override(&little_bom, Some("UTF_16")).unwrap(),
131
+ "h"
132
+ );
133
+ let little = [b'h', 0x00, b'i', 0x00];
134
+ assert_eq!(
135
+ decoder::decode_bytes_with_override(&little, Some("utf-16le")).unwrap(),
136
+ "hi"
137
+ );
138
+ let little_no_bom = [b'h', 0x00, b'i', 0x00];
139
+ assert_eq!(
140
+ decoder::decode_bytes_with_override(&little_no_bom, Some("utf-16")).unwrap(),
141
+ "hi"
142
+ );
143
+ }
144
+
145
+ #[test]
146
+ fn decode_with_override_utf16_fallbacks_to_little_when_ambiguous() {
147
+ let bytes = [0x2D, 0x4E, 0x87, 0x65]; // "中文" in little-endian without BOM or zero hints
148
+ assert_eq!(
149
+ decoder::decode_bytes_with_override(&bytes, Some("utf-16")).unwrap(),
150
+ "中文"
151
+ );
152
+ }
153
+
154
+ #[test]
155
+ fn decode_with_override_utf32_variants() {
156
+ let big = [0x00, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i'];
157
+ assert_eq!(
158
+ decoder::decode_bytes_with_override(&big, Some("utf-32")).unwrap(),
159
+ "hi"
160
+ );
161
+ let big_bom = [
162
+ 0x00, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i',
163
+ ];
164
+ assert_eq!(
165
+ decoder::decode_bytes_with_override(&big_bom, Some("utf-32")).unwrap(),
166
+ "hi"
167
+ );
168
+ let little = [b'h', 0x00, 0x00, 0x00, b'i', 0x00, 0x00, 0x00];
169
+ assert_eq!(
170
+ decoder::decode_bytes_with_override(&little, Some("utf-32le")).unwrap(),
171
+ "hi"
172
+ );
173
+ assert_eq!(
174
+ decoder::decode_bytes_with_override(&little, Some("utf-32")).unwrap(),
175
+ "hi"
176
+ );
177
+ }
178
+
179
+ #[test]
180
+ fn decode_with_override_utf32_detects_little_without_bom() {
181
+ let bytes = [0x2D, 0x4E, 0x00, 0x00, 0x87, 0x65, 0x00, 0x00];
182
+ assert_eq!(
183
+ decoder::decode_bytes_with_override(&bytes, Some("utf-32")).unwrap(),
184
+ "中文"
185
+ );
186
+ }
187
+
188
+ #[test]
189
+ fn decode_with_override_utf32_missing_hint_errors() {
190
+ let err =
191
+ decoder::decode_bytes_with_override(&[0x01, 0x02, 0x03, 0x04], Some("utf-32"))
192
+ .unwrap_err();
193
+ assert!(err.contains("utf-32"), "unexpected error: {err}");
194
+ }
195
+
196
+ #[test]
197
+ fn decode_with_override_utf8_alias() {
198
+ assert_eq!(
199
+ decoder::decode_bytes_with_override(b"hi", Some("utf-8")).unwrap(),
200
+ "hi"
201
+ );
202
+ }
203
+
204
+ #[test]
205
+ fn decode_with_override_utf16be_explicit() {
206
+ let data = [0x00, b'h', 0x00, b'i'];
207
+ assert_eq!(
208
+ decoder::decode_bytes_with_override(&data, Some("utf-16be")).unwrap(),
209
+ "hi"
210
+ );
211
+ }
212
+
213
+ #[test]
214
+ fn decode_with_override_utf32be_explicit() {
215
+ let data = [0x00, 0x00, 0x00, b'h', 0x00, 0x00, 0x00, b'i'];
216
+ assert_eq!(
217
+ decoder::decode_bytes_with_override(&data, Some("utf-32be")).unwrap(),
218
+ "hi"
219
+ );
220
+ }
221
+
222
+ #[test]
223
+ fn decode_with_override_latin1_variants() {
224
+ let bytes = [0xA1, 0x21];
225
+ assert_eq!(
226
+ decoder::decode_bytes_with_override(&bytes, Some("latin-1")).unwrap(),
227
+ "¡!"
228
+ );
229
+ let alias = [0xA1];
230
+ assert_eq!(
231
+ decoder::decode_bytes_with_override(&alias, Some("ISO_8859_1")).unwrap(),
232
+ "¡"
233
+ );
234
+ assert_eq!(
235
+ decoder::decode_bytes_with_override(&alias, Some("latin1")).unwrap(),
236
+ "¡"
237
+ );
238
+ }
239
+
240
+ #[test]
241
+ fn decode_with_override_utf8_sig() {
242
+ let data = [0xEF, 0xBB, 0xBF, b'h'];
243
+ assert_eq!(
244
+ decoder::decode_bytes_with_override(&data, Some("utf8-sig")).unwrap(),
245
+ "h"
246
+ );
247
+ }
248
+
249
+ #[test]
250
+ fn decode_with_override_utf16_only_bom() {
251
+ let data = [0xFF, 0xFE];
252
+ assert_eq!(
253
+ decoder::decode_bytes_with_override(&data, Some("utf-16")).unwrap(),
254
+ ""
255
+ );
256
+ }
257
+
258
+ #[test]
259
+ fn decode_with_override_utf32_only_bom() {
260
+ let data = [0xFF, 0xFE, 0x00, 0x00];
261
+ assert_eq!(
262
+ decoder::decode_bytes_with_override(&data, Some("utf-32")).unwrap(),
263
+ ""
264
+ );
265
+ }
266
+
267
+ #[test]
268
+ fn decode_with_override_utf16_empty_input() {
269
+ assert_eq!(
270
+ decoder::decode_bytes_with_override(&[], Some("utf-16le")).unwrap(),
271
+ ""
272
+ );
273
+ }
274
+
275
+ #[test]
276
+ fn decode_with_override_utf32_empty_input() {
277
+ assert_eq!(
278
+ decoder::decode_bytes_with_override(&[], Some("utf-32le")).unwrap(),
279
+ ""
280
+ );
281
+ }
282
+
283
+ #[test]
284
+ fn decode_with_override_unknown_errors() {
285
+ let err =
286
+ decoder::decode_bytes_with_override(b"data", Some("unsupported")).unwrap_err();
287
+ assert!(err.contains("unsupported label"));
288
+ }
289
+
290
+ #[test]
291
+ fn decode_with_override_empty_label_errors() {
292
+ let err = decoder::decode_bytes_with_override(b"data", Some(" ")).unwrap_err();
293
+ assert!(err.contains("cannot be empty"));
294
+ }
295
+
296
+ #[test]
297
+ fn decode_with_custom_encoding() {
298
+ let bytes = b"hello";
299
+ assert_eq!(
300
+ decoder::decode_bytes_with_override(bytes, Some("koi8-r")).unwrap(),
301
+ "hello"
302
+ );
303
+ assert_eq!(
304
+ decoder::decode_bytes_with_override(bytes, Some("KOI8_R")).unwrap(),
305
+ "hello"
306
+ );
307
+ }
308
+
309
+ #[test]
310
+ fn decode_with_custom_encoding_errors() {
311
+ let err =
312
+ decoder::decode_bytes_with_override(&[0x82], Some("shift_jis")).unwrap_err();
313
+ assert!(err.contains("decode error"));
314
+ }
315
+
316
+ #[test]
317
+ fn read_file_decodes_utf8() {
318
+ let dir = tempdir().unwrap();
319
+ let path = dir.path().join("sample.yml");
320
+ std::fs::write(&path, "key: value\n").unwrap();
321
+ let content = decoder::read_file(&path).unwrap();
322
+ assert!(content.contains("key: value"));
323
+ }
324
+
325
+ #[test]
326
+ fn read_file_invalid_utf8_errors() {
327
+ let dir = tempdir().unwrap();
328
+ let path = dir.path().join("invalid.yml");
329
+ std::fs::write(&path, [0xFF]).unwrap();
330
+ let err = decoder::read_file(&path).unwrap_err();
331
+ assert!(err.contains("invalid utf-8 data"));
332
+ }
333
+
334
+ #[test]
335
+ fn read_file_missing_file_errors() {
336
+ let err = decoder::read_file(Path::new("no_such_decoder_file.yml")).unwrap_err();
337
+ assert!(err.contains("failed to read"));
338
+ }
@@ -0,0 +1,66 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run helper");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn dc_ok_prints_empty_when_no_configs() {
16
+ let td = tempdir().unwrap();
17
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
18
+ let (code, out, err) = run(Command::new(exe).arg(td.path()));
19
+ assert_eq!(code, 0, "expected success: {err}");
20
+ assert_eq!(out.trim(), "");
21
+ }
22
+
23
+ #[test]
24
+ fn dc_ok_prints_env_config_path() {
25
+ let td = tempdir().unwrap();
26
+ let cfg = td.path().join("envcfg.yml");
27
+ fs::write(&cfg, "ignore: ['**/skip/**']\n").unwrap();
28
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
29
+ let (code, out, err) = run(Command::new(exe)
30
+ .env("YAMLLINT_CONFIG_FILE", &cfg)
31
+ .arg(td.path()));
32
+ assert_eq!(code, 0, "expected success: {err}");
33
+ assert!(out.trim_end().ends_with(cfg.to_string_lossy().as_ref()));
34
+ }
35
+
36
+ #[test]
37
+ fn dc_error_on_project_config_dir() {
38
+ let td = tempdir().unwrap();
39
+ let root = td.path();
40
+ fs::create_dir(root.join(".yamllint")).unwrap();
41
+ fs::write(root.join("a.yaml"), "a: 1\n").unwrap();
42
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
43
+ let (code, _out, err) = run(Command::new(exe).arg(root));
44
+ assert_eq!(code, 2, "expected exit 2: {err}");
45
+ assert!(err.contains("failed to read"));
46
+ }
47
+
48
+ #[test]
49
+ fn dc_ok_prints_user_global_path_when_present() {
50
+ let td = tempdir().unwrap();
51
+ let xdg = td.path().join("xdg").join("yamllint");
52
+ fs::create_dir_all(&xdg).unwrap();
53
+ let global_cfg = xdg.join("config");
54
+ fs::write(&global_cfg, "ignore: ['**/a.yaml']\n").unwrap();
55
+ let proj = td.path().join("proj");
56
+ fs::create_dir_all(&proj).unwrap();
57
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
58
+ let (code, out, err) = run(Command::new(exe)
59
+ .env("XDG_CONFIG_HOME", td.path().join("xdg"))
60
+ .arg(&proj));
61
+ assert_eq!(code, 0, "expected success: {err}");
62
+ assert!(
63
+ out.trim_end()
64
+ .ends_with(global_cfg.to_string_lossy().as_ref())
65
+ );
66
+ }
@@ -0,0 +1,26 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run helper");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn dc_error_on_env_config_parse_error() {
16
+ let td = tempdir().unwrap();
17
+ let cfg = td.path().join("envcfg.yml");
18
+ fs::write(&cfg, "rules: {\n").unwrap();
19
+
20
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
21
+ let (code, _out, err) = run(Command::new(exe)
22
+ .env("YAMLLINT_CONFIG_FILE", &cfg)
23
+ .arg(td.path()));
24
+ assert_eq!(code, 2, "expected exit 2: {err}");
25
+ assert!(err.contains("failed to parse config data"));
26
+ }
@@ -0,0 +1,24 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run helper");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn dc_error_on_project_config_parse_error() {
16
+ let td = tempdir().unwrap();
17
+ let root = td.path();
18
+ fs::write(root.join(".yamllint"), "rules: {\n").unwrap();
19
+ fs::write(root.join("a.yaml"), "a: 1\n").unwrap();
20
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
21
+ let (code, _out, err) = run(Command::new(exe).arg(root));
22
+ assert_eq!(code, 2, "expected exit 2: {err}");
23
+ assert!(err.contains("failed to parse config data"));
24
+ }
@@ -0,0 +1,26 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run helper");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn dc_error_on_user_global_config_dir() {
16
+ let td = tempdir().unwrap();
17
+ let xdg = td.path().join("xdg").join("yamllint");
18
+ fs::create_dir_all(xdg.join("config")).unwrap(); // create directory where file is expected
19
+
20
+ let exe = env!("CARGO_BIN_EXE_discover_config_bin");
21
+ let (code, _out, err) = run(Command::new(exe)
22
+ .env("XDG_CONFIG_HOME", td.path().join("xdg"))
23
+ .current_dir(td.path()));
24
+ assert_eq!(code, 2, "expected exit 2: {err}");
25
+ assert!(err.contains("failed to read"));
26
+ }
@@ -0,0 +1,30 @@
1
+ use std::fs;
2
+ use std::path::PathBuf;
3
+
4
+ use ryl::discover::{gather_yaml_from_dir, is_yaml_path};
5
+ use tempfile::tempdir;
6
+
7
+ #[test]
8
+ fn is_yaml_path_matches_common_extensions_case_insensitive() {
9
+ assert!(is_yaml_path(&PathBuf::from("foo.yaml")));
10
+ assert!(is_yaml_path(&PathBuf::from("bar.yml")));
11
+ assert!(is_yaml_path(&PathBuf::from("BAZ.YAML")));
12
+ assert!(!is_yaml_path(&PathBuf::from("nope.txt")));
13
+ }
14
+
15
+ #[test]
16
+ fn gather_yaml_from_dir_finds_yaml_files_only() {
17
+ let td = tempdir().unwrap();
18
+ let root = td.path();
19
+ fs::write(root.join("a.yaml"), "a: 1\n").unwrap();
20
+ fs::write(root.join("b.yml"), "b: 1\n").unwrap();
21
+ fs::write(root.join("not.yaml.txt"), "noop\n").unwrap();
22
+
23
+ let files = gather_yaml_from_dir(root);
24
+ let mut names: Vec<_> = files
25
+ .into_iter()
26
+ .map(|p| p.file_name().unwrap().to_string_lossy().into_owned())
27
+ .collect();
28
+ names.sort();
29
+ assert_eq!(names, vec!["a.yaml", "b.yml"]);
30
+ }
@@ -0,0 +1,10 @@
1
+ use ryl::config::discover_per_file;
2
+ use tempfile::tempdir;
3
+
4
+ #[test]
5
+ fn discover_per_file_handles_directory_input() {
6
+ let td = tempdir().unwrap();
7
+ // No project or user config; falls back to built-in default.
8
+ let ctx = discover_per_file(td.path()).expect("discover default for dir");
9
+ assert!(ctx.config.rule_names().iter().any(|r| r == "anchors"));
10
+ }
@@ -0,0 +1,21 @@
1
+ use std::fs;
2
+
3
+ use ryl::config::discover_per_file;
4
+ use tempfile::tempdir;
5
+
6
+ #[test]
7
+ fn discover_per_file_errors_on_invalid_project_config() {
8
+ let td = tempdir().unwrap();
9
+ let root = td.path();
10
+ fs::write(root.join(".yamllint"), "rules: {\n").unwrap();
11
+ let file = root.join("a.yaml");
12
+ fs::write(&file, "a: 1\n").unwrap();
13
+
14
+ let res = discover_per_file(&file);
15
+ assert!(
16
+ res.is_err(),
17
+ "expected parse error from invalid project config"
18
+ );
19
+ let err = res.err().unwrap();
20
+ assert!(err.contains("failed to parse config data"));
21
+ }
@@ -0,0 +1,43 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::float_values::{Config, check};
3
+
4
+ fn resolve_config(yaml: &str) -> Config {
5
+ let cfg = YamlLintConfig::from_yaml_str(yaml).expect("valid yaml config");
6
+ Config::resolve(&cfg)
7
+ }
8
+
9
+ #[test]
10
+ fn float_values_flags_special_variants() {
11
+ let config = resolve_config(
12
+ "---\nrules:\n float-values:\n forbid-nan: true\n forbid-inf: true\n forbid-scientific-notation: true\n require-numeral-before-decimal: true\n",
13
+ );
14
+
15
+ let buffer = "a: .NaN\nb: -.INF\nc: +.inf\nd: 1e2\ne: +.5\n";
16
+ let diagnostics = check(buffer, &config);
17
+ let messages: Vec<_> = diagnostics.iter().map(|d| d.message.as_str()).collect();
18
+ assert!(
19
+ messages.contains(&"forbidden not a number value \".NaN\""),
20
+ "messages: {:?}",
21
+ messages
22
+ );
23
+ assert!(
24
+ messages.contains(&"forbidden infinite value \"-.INF\""),
25
+ "messages: {:?}",
26
+ messages
27
+ );
28
+ assert!(
29
+ messages.contains(&"forbidden infinite value \"+.inf\""),
30
+ "messages: {:?}",
31
+ messages
32
+ );
33
+ assert!(
34
+ messages.contains(&"forbidden scientific notation \"1e2\""),
35
+ "messages: {:?}",
36
+ messages
37
+ );
38
+ assert!(
39
+ messages.contains(&"forbidden decimal missing 0 prefix \"+.5\""),
40
+ "messages: {:?}",
41
+ messages
42
+ );
43
+ }
@@ -0,0 +1,32 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run ryl");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn multiple_invalid_files_print_multiple_errors() {
16
+ let td = tempdir().unwrap();
17
+ let root = td.path();
18
+ fs::write(root.join("a.yaml"), "a: [1\n").unwrap();
19
+ fs::write(root.join("b.yaml"), "b: [2\n").unwrap();
20
+
21
+ let exe = env!("CARGO_BIN_EXE_ryl");
22
+ let (code, _out, err) = run(Command::new(exe).arg(root));
23
+ assert_eq!(code, 1, "expected failure");
24
+ let count = err
25
+ .lines()
26
+ .filter(|l| l.trim().ends_with("(syntax)"))
27
+ .count();
28
+ assert!(
29
+ count >= 2,
30
+ "expected at least two syntax error lines, got: {err}"
31
+ );
32
+ }
@@ -0,0 +1,30 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ fn run(cmd: &mut Command) -> (i32, String, String) {
7
+ let out = cmd.output().expect("failed to run ryl");
8
+ let code = out.status.code().unwrap_or(-1);
9
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
+ (code, stdout, stderr)
12
+ }
13
+
14
+ #[test]
15
+ fn yaml_files_filtering_excludes_dir_and_explicit() {
16
+ let td = tempdir().unwrap();
17
+ let root = td.path();
18
+ fs::write(root.join("a.yaml"), "a: 1\n").unwrap();
19
+ fs::write(root.join("b.yaml"), "b: 1\n").unwrap();
20
+
21
+ let exe = env!("CARGO_BIN_EXE_ryl");
22
+ let (code, out, err) = run(Command::new(exe)
23
+ .arg("--list-files")
24
+ .arg("-d")
25
+ .arg("yaml-files: ['*.none']\n")
26
+ .arg(root)
27
+ .arg(root.join("a.yaml")));
28
+ assert_eq!(code, 0, "expected success: {err}");
29
+ assert!(out.trim().is_empty(), "expected no files listed: {out}");
30
+ }