summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 13:48:39 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 13:48:39 +0200
commit59fbd3718dbf2721557b97d7b4e87dce38fb745c (patch)
tree818feefb15c328bca3ecf9b1a24a2023d57980c4 /test
parent6bdd5afc5e185b639f9cf5e7c3d662ddc3ecf0e1 (diff)
downloadcolitur-59fbd3718dbf2721557b97d7b4e87dce38fb745c.tar.gz
colitur-59fbd3718dbf2721557b97d7b4e87dce38fb745c.zip
fix(naming): config fix round 1 -- unknown sections, O(n) accumulate
F1: test_unknown_key_is_reported_not_fatal never asserted unknown_keys itself, only that parsing survives -- a no-op accumulator passed it. Now asserts the key is actually collected. F2: a misspelled section name, e.g. [deafults], was silently discarded -- Ok empty, lang and everything else gone, nothing reported. That is the highest-value typo this feature exists to catch. Any section other than [defaults] is now collected into a new Config.unknown_sections, kept separate from unknown_keys so the CLI can word the two warnings differently. Still non-fatal: a newer colitur's added section must not break an older binary. F3: overlays and unknown_keys accumulated with '@ [v]' per line, O(n^2) over the field count. Cons during the fold, List.rev once at the end. F4: documented that lang/template/format are last-wins on a repeated key, the opposite direction from Overlay_ini.get's first-wins over the same section type.
Diffstat (limited to 'test')
-rw-r--r--test/test_config.ml22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/test_config.ml b/test/test_config.ml
index 9100380..067b255 100644
--- a/test/test_config.ml
+++ b/test/test_config.ml
@@ -46,11 +46,25 @@ let test_malformed_is_error_not_crash () =
(* An unknown key is a WARNING case, not a hard error: a config written for a
newer colitur must still work on an older one. But it must be reportable, so
- it is not silently dropped either. *)
+ it is not silently dropped either -- assert it is actually COLLECTED, not
+ only that parsing survives it: a no-op accumulator would also pass a test
+ that checked survival alone. *)
let test_unknown_key_is_reported_not_fatal () =
match C.of_string "[defaults]\nlang = la\nnonsense = 1\n" with
| Error _ -> Alcotest.fail "an unknown key must not be fatal"
- | Ok c -> Alcotest.(check (option string)) "known key still read" (Some "la") (C.lang c)
+ | Ok c ->
+ Alcotest.(check (option string)) "known key still read" (Some "la") (C.lang c);
+ Alcotest.(check (list string)) "unknown key reported" [ "nonsense" ] (C.unknown_keys c)
+
+(* The highest-value case: a misspelled SECTION name (not merely a misspelled
+ key inside a recognised one). Before this fix the whole section, lang
+ included, vanished with nothing reported -- exactly the typo this feature
+ exists to surface, in its worst form: a user whose config silently does
+ nothing has no way to discover why. *)
+let test_misspelled_section_is_reported_not_silently_dropped () =
+ let c = ok (C.of_string "[deafults]\nlang = pl\n") in
+ Alcotest.(check (option string)) "lang not read from the wrong section" None (C.lang c);
+ Alcotest.(check (list string)) "section reported" [ "deafults" ] (C.unknown_sections c)
let suite =
( "Config",
@@ -59,4 +73,6 @@ let suite =
Alcotest.test_case "empty is all none" `Quick test_empty_config_is_all_none;
Alcotest.test_case "precedence and provenance" `Quick test_precedence_and_provenance;
Alcotest.test_case "malformed is error" `Quick test_malformed_is_error_not_crash;
- Alcotest.test_case "unknown key not fatal" `Quick test_unknown_key_is_reported_not_fatal ] )
+ Alcotest.test_case "unknown key not fatal" `Quick test_unknown_key_is_reported_not_fatal;
+ Alcotest.test_case "misspelled section reported"
+ `Quick test_misspelled_section_is_reported_not_silently_dropped ] )