@owenlamont/ryl 0.4.1 → 0.4.2

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 (216) hide show
  1. package/README.md +13 -0
  2. package/bin/ryl.js +195 -1
  3. package/package.json +35 -13
  4. package/.github/CODEOWNERS +0 -1
  5. package/.github/dependabot.yml +0 -13
  6. package/.github/workflows/ci.yml +0 -107
  7. package/.github/workflows/release.yml +0 -613
  8. package/.github/workflows/update_dependencies.yml +0 -61
  9. package/.github/workflows/update_linters.yml +0 -56
  10. package/.pre-commit-config.yaml +0 -87
  11. package/.yamllint +0 -4
  12. package/AGENTS.md +0 -200
  13. package/Cargo.lock +0 -908
  14. package/Cargo.toml +0 -32
  15. package/clippy.toml +0 -1
  16. package/docs/config-presets.md +0 -100
  17. package/img/benchmark-5x5-5runs.svg +0 -2176
  18. package/pyproject.toml +0 -42
  19. package/ruff.toml +0 -107
  20. package/rumdl.toml +0 -20
  21. package/rust-toolchain.toml +0 -3
  22. package/rustfmt.toml +0 -3
  23. package/scripts/benchmark_perf_vs_yamllint.py +0 -400
  24. package/scripts/coverage-missing.ps1 +0 -80
  25. package/scripts/coverage-missing.sh +0 -60
  26. package/src/bin/discover_config_bin.rs +0 -24
  27. package/src/cli_support.rs +0 -33
  28. package/src/conf/mod.rs +0 -85
  29. package/src/config.rs +0 -2099
  30. package/src/decoder.rs +0 -326
  31. package/src/discover.rs +0 -31
  32. package/src/lib.rs +0 -19
  33. package/src/lint.rs +0 -558
  34. package/src/main.rs +0 -535
  35. package/src/migrate.rs +0 -233
  36. package/src/rules/anchors.rs +0 -517
  37. package/src/rules/braces.rs +0 -77
  38. package/src/rules/brackets.rs +0 -77
  39. package/src/rules/colons.rs +0 -475
  40. package/src/rules/commas.rs +0 -372
  41. package/src/rules/comments.rs +0 -299
  42. package/src/rules/comments_indentation.rs +0 -243
  43. package/src/rules/document_end.rs +0 -175
  44. package/src/rules/document_start.rs +0 -84
  45. package/src/rules/empty_lines.rs +0 -152
  46. package/src/rules/empty_values.rs +0 -255
  47. package/src/rules/float_values.rs +0 -259
  48. package/src/rules/flow_collection.rs +0 -562
  49. package/src/rules/hyphens.rs +0 -104
  50. package/src/rules/indentation.rs +0 -803
  51. package/src/rules/key_duplicates.rs +0 -218
  52. package/src/rules/key_ordering.rs +0 -303
  53. package/src/rules/line_length.rs +0 -326
  54. package/src/rules/mod.rs +0 -25
  55. package/src/rules/new_line_at_end_of_file.rs +0 -23
  56. package/src/rules/new_lines.rs +0 -95
  57. package/src/rules/octal_values.rs +0 -121
  58. package/src/rules/quoted_strings.rs +0 -577
  59. package/src/rules/span_utils.rs +0 -37
  60. package/src/rules/trailing_spaces.rs +0 -65
  61. package/src/rules/truthy.rs +0 -420
  62. package/tests/brackets_carriage_return.rs +0 -114
  63. package/tests/build_global_cfg_error.rs +0 -23
  64. package/tests/cli_anchors_rule.rs +0 -143
  65. package/tests/cli_braces_rule.rs +0 -104
  66. package/tests/cli_brackets_rule.rs +0 -104
  67. package/tests/cli_colons_rule.rs +0 -65
  68. package/tests/cli_commas_rule.rs +0 -104
  69. package/tests/cli_comments_indentation_rule.rs +0 -61
  70. package/tests/cli_comments_rule.rs +0 -67
  71. package/tests/cli_config_data_error.rs +0 -30
  72. package/tests/cli_config_flags.rs +0 -66
  73. package/tests/cli_config_migrate.rs +0 -229
  74. package/tests/cli_document_end_rule.rs +0 -92
  75. package/tests/cli_document_start_rule.rs +0 -92
  76. package/tests/cli_empty_lines_rule.rs +0 -87
  77. package/tests/cli_empty_values_rule.rs +0 -68
  78. package/tests/cli_env_config.rs +0 -34
  79. package/tests/cli_exit_and_errors.rs +0 -41
  80. package/tests/cli_file_encoding.rs +0 -203
  81. package/tests/cli_float_values_rule.rs +0 -64
  82. package/tests/cli_format_options.rs +0 -316
  83. package/tests/cli_global_cfg_relaxed.rs +0 -20
  84. package/tests/cli_hyphens_rule.rs +0 -104
  85. package/tests/cli_indentation_rule.rs +0 -65
  86. package/tests/cli_invalid_project_config.rs +0 -39
  87. package/tests/cli_key_duplicates_rule.rs +0 -104
  88. package/tests/cli_key_ordering_rule.rs +0 -59
  89. package/tests/cli_line_length_rule.rs +0 -85
  90. package/tests/cli_list_files.rs +0 -29
  91. package/tests/cli_new_line_rule.rs +0 -141
  92. package/tests/cli_new_lines_rule.rs +0 -119
  93. package/tests/cli_octal_values_rule.rs +0 -60
  94. package/tests/cli_quoted_strings_rule.rs +0 -47
  95. package/tests/cli_toml_config.rs +0 -119
  96. package/tests/cli_trailing_spaces_rule.rs +0 -77
  97. package/tests/cli_truthy_rule.rs +0 -83
  98. package/tests/cli_yaml_files_negation.rs +0 -45
  99. package/tests/colons_rule.rs +0 -303
  100. package/tests/common/compat.rs +0 -114
  101. package/tests/common/fake_env.rs +0 -93
  102. package/tests/common/mod.rs +0 -1
  103. package/tests/conf_builtin.rs +0 -9
  104. package/tests/config_anchors.rs +0 -84
  105. package/tests/config_braces.rs +0 -121
  106. package/tests/config_brackets.rs +0 -127
  107. package/tests/config_commas.rs +0 -79
  108. package/tests/config_comments.rs +0 -65
  109. package/tests/config_comments_indentation.rs +0 -20
  110. package/tests/config_deep_merge_nonstring_key.rs +0 -24
  111. package/tests/config_document_end.rs +0 -54
  112. package/tests/config_document_start.rs +0 -55
  113. package/tests/config_empty_lines.rs +0 -48
  114. package/tests/config_empty_values.rs +0 -35
  115. package/tests/config_env_errors.rs +0 -23
  116. package/tests/config_env_invalid_inline.rs +0 -15
  117. package/tests/config_env_missing.rs +0 -63
  118. package/tests/config_env_shim.rs +0 -301
  119. package/tests/config_explicit_file_parse_error.rs +0 -55
  120. package/tests/config_extended_features.rs +0 -225
  121. package/tests/config_extends_inline.rs +0 -185
  122. package/tests/config_extends_sequence.rs +0 -18
  123. package/tests/config_find_project_home_boundary.rs +0 -54
  124. package/tests/config_find_project_two_files_in_cwd.rs +0 -47
  125. package/tests/config_float_values.rs +0 -34
  126. package/tests/config_from_yaml_paths.rs +0 -32
  127. package/tests/config_hyphens.rs +0 -51
  128. package/tests/config_ignore_errors.rs +0 -243
  129. package/tests/config_ignore_overrides.rs +0 -83
  130. package/tests/config_indentation.rs +0 -65
  131. package/tests/config_invalid_globs.rs +0 -16
  132. package/tests/config_invalid_types.rs +0 -19
  133. package/tests/config_key_duplicates.rs +0 -34
  134. package/tests/config_key_ordering.rs +0 -70
  135. package/tests/config_line_length.rs +0 -65
  136. package/tests/config_locale.rs +0 -111
  137. package/tests/config_merge.rs +0 -26
  138. package/tests/config_new_lines.rs +0 -89
  139. package/tests/config_octal_values.rs +0 -33
  140. package/tests/config_quoted_strings.rs +0 -195
  141. package/tests/config_rule_level.rs +0 -147
  142. package/tests/config_rules_non_string_keys.rs +0 -23
  143. package/tests/config_scalar_overrides.rs +0 -27
  144. package/tests/config_to_toml.rs +0 -110
  145. package/tests/config_toml_coverage.rs +0 -80
  146. package/tests/config_toml_discovery.rs +0 -304
  147. package/tests/config_trailing_spaces.rs +0 -152
  148. package/tests/config_truthy.rs +0 -77
  149. package/tests/config_yaml_files.rs +0 -62
  150. package/tests/config_yaml_files_all_non_string.rs +0 -15
  151. package/tests/config_yaml_files_empty.rs +0 -30
  152. package/tests/coverage_commas.rs +0 -46
  153. package/tests/decoder_decode.rs +0 -338
  154. package/tests/discover_config_bin_all.rs +0 -66
  155. package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
  156. package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
  157. package/tests/discover_config_bin_user_global_error.rs +0 -26
  158. package/tests/discover_module.rs +0 -30
  159. package/tests/discover_per_file_dir.rs +0 -10
  160. package/tests/discover_per_file_project_config_error.rs +0 -21
  161. package/tests/float_values.rs +0 -43
  162. package/tests/lint_multi_errors.rs +0 -32
  163. package/tests/main_yaml_ok_filtering.rs +0 -30
  164. package/tests/migrate_module.rs +0 -259
  165. package/tests/resolve_ctx_empty_parent.rs +0 -16
  166. package/tests/rule_anchors.rs +0 -442
  167. package/tests/rule_braces.rs +0 -258
  168. package/tests/rule_brackets.rs +0 -217
  169. package/tests/rule_commas.rs +0 -205
  170. package/tests/rule_comments.rs +0 -197
  171. package/tests/rule_comments_indentation.rs +0 -127
  172. package/tests/rule_document_end.rs +0 -118
  173. package/tests/rule_document_start.rs +0 -60
  174. package/tests/rule_empty_lines.rs +0 -96
  175. package/tests/rule_empty_values.rs +0 -102
  176. package/tests/rule_float_values.rs +0 -109
  177. package/tests/rule_hyphens.rs +0 -65
  178. package/tests/rule_indentation.rs +0 -455
  179. package/tests/rule_key_duplicates.rs +0 -76
  180. package/tests/rule_key_ordering.rs +0 -207
  181. package/tests/rule_line_length.rs +0 -200
  182. package/tests/rule_new_lines.rs +0 -51
  183. package/tests/rule_octal_values.rs +0 -53
  184. package/tests/rule_quoted_strings.rs +0 -290
  185. package/tests/rule_trailing_spaces.rs +0 -41
  186. package/tests/rule_truthy.rs +0 -236
  187. package/tests/user_global_invalid_yaml.rs +0 -32
  188. package/tests/yamllint_compat_anchors.rs +0 -280
  189. package/tests/yamllint_compat_braces.rs +0 -411
  190. package/tests/yamllint_compat_brackets.rs +0 -364
  191. package/tests/yamllint_compat_colons.rs +0 -298
  192. package/tests/yamllint_compat_colors.rs +0 -80
  193. package/tests/yamllint_compat_commas.rs +0 -375
  194. package/tests/yamllint_compat_comments.rs +0 -167
  195. package/tests/yamllint_compat_comments_indentation.rs +0 -281
  196. package/tests/yamllint_compat_config.rs +0 -170
  197. package/tests/yamllint_compat_document_end.rs +0 -243
  198. package/tests/yamllint_compat_document_start.rs +0 -136
  199. package/tests/yamllint_compat_empty_lines.rs +0 -117
  200. package/tests/yamllint_compat_empty_values.rs +0 -179
  201. package/tests/yamllint_compat_float_values.rs +0 -216
  202. package/tests/yamllint_compat_hyphens.rs +0 -223
  203. package/tests/yamllint_compat_indentation.rs +0 -398
  204. package/tests/yamllint_compat_key_duplicates.rs +0 -139
  205. package/tests/yamllint_compat_key_ordering.rs +0 -170
  206. package/tests/yamllint_compat_line_length.rs +0 -375
  207. package/tests/yamllint_compat_list.rs +0 -127
  208. package/tests/yamllint_compat_new_line.rs +0 -133
  209. package/tests/yamllint_compat_newline_types.rs +0 -185
  210. package/tests/yamllint_compat_octal_values.rs +0 -172
  211. package/tests/yamllint_compat_quoted_strings.rs +0 -154
  212. package/tests/yamllint_compat_syntax.rs +0 -200
  213. package/tests/yamllint_compat_trailing_spaces.rs +0 -162
  214. package/tests/yamllint_compat_truthy.rs +0 -130
  215. package/tests/yamllint_compat_yaml_files.rs +0 -81
  216. package/typos.toml +0 -2
@@ -1,338 +0,0 @@
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
- }
@@ -1,66 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- }