summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dune2
-rw-r--r--test/test_colitur.ml1
-rw-r--r--test/test_lang.ml85
3 files changed, 87 insertions, 1 deletions
diff --git a/test/dune b/test/dune
index 8d0c551..b9cc2a7 100644
--- a/test/dune
+++ b/test/dune
@@ -1,6 +1,6 @@
(test
(name test_colitur)
- (libraries colitur_kernel colitur_render rite_ef alcotest qcheck qcheck-alcotest sexplib)
+ (libraries colitur_kernel colitur_naming colitur_render rite_ef alcotest qcheck qcheck-alcotest sexplib)
(deps
../data/ef/sanctoral.sexp
../data/ef/adjustments.sexp
diff --git a/test/test_colitur.ml b/test/test_colitur.ml
index 04bbdee..dd1274a 100644
--- a/test/test_colitur.ml
+++ b/test/test_colitur.ml
@@ -2,6 +2,7 @@
let () =
Alcotest.run "colitur"
[ Test_date.suite; Test_computus.suite; Test_colour.suite; Test_slug.suite; Test_names.suite;
+ Test_lang.suite;
Test_overlay.suite; Test_overlay_ini.suite; Test_temporal_ef.suite; Test_validate.suite; Test_precedence.suite;
Test_calendar.suite; Test_precedence_ef.suite; Test_sanctoral_ef.suite; Test_rite_ef.suite;
Test_differential.suite; Test_oracle.suite; Test_oracle.suite_2038; Test_oracle.suite_2035; Test_golden.suite;
diff --git a/test/test_lang.ml b/test/test_lang.ml
new file mode 100644
index 0000000..0b16b30
--- /dev/null
+++ b/test/test_lang.ml
@@ -0,0 +1,85 @@
+module L = Colitur_naming.Lang
+
+let ok = function Ok x -> x | Error e -> Alcotest.failf "parse: %s" e
+
+let sample =
+ "[meta]\n\
+ lang = xx\n\
+ fallback = la\n\
+ [celebration]\n\
+ ef-lent-3-monday = Feria II hebdomadae III Quadragesimae\n\
+ francis-de-sales = S. Francisci Salesii\n\
+ [weekday]\n\
+ sunday = Dominica\n\
+ monday = Feria II\n\
+ [month]\n\
+ 1 = Ianuarius\n\
+ [season]\n\
+ lent = Quadragesima\n\
+ [rank]\n\
+ class-1 = I classis\n\
+ [colour]\n\
+ white = albus\n\
+ [term]\n\
+ epistle = Epistola\n"
+
+let test_meta () =
+ let t = ok (L.of_string sample) in
+ Alcotest.(check string) "code" "xx" (L.code t);
+ Alcotest.(check (option string)) "fallback" (Some "la") (L.fallback_code t)
+
+let test_lookups () =
+ let t = ok (L.of_string sample) in
+ Alcotest.(check string) "celebration" "Feria II hebdomadae III Quadragesimae"
+ (L.celebration t "ef-lent-3-monday");
+ Alcotest.(check string) "weekday 0 is Sunday" "Dominica" (L.weekday t 0);
+ Alcotest.(check string) "month 1" "Ianuarius" (L.month t 1);
+ Alcotest.(check string) "season" "Quadragesima" (L.season t "lent");
+ Alcotest.(check string) "rank" "I classis" (L.rank t "class-1");
+ Alcotest.(check string) "colour" "albus" (L.colour t "white");
+ Alcotest.(check string) "term" "Epistola" (L.term t "epistle")
+
+(* THE load-bearing property: a missing key degrades to the key itself, never to
+ empty. A partial translation must be usable from its first line, and an
+ untranslated day must still say something a reader can act on. *)
+let test_missing_degrades_to_key () =
+ let t = ok (L.of_string sample) in
+ Alcotest.(check string) "unknown celebration" "ef-advent-1-monday"
+ (L.celebration t "ef-advent-1-monday");
+ Alcotest.(check string) "unknown colour" "rose" (L.colour t "rose");
+ Alcotest.(check string) "unknown term" "gospel" (L.term t "gospel")
+
+let test_fallback_chain () =
+ let base = ok (L.of_string "[meta]\nlang = la\n[celebration]\na = ALPHA\nb = BETA\n") in
+ let over = ok (L.of_string "[meta]\nlang = xx\nfallback = la\n[celebration]\nb = BETA-XX\n") in
+ let t = L.with_fallback over base in
+ Alcotest.(check string) "own key wins" "BETA-XX" (L.celebration t "b");
+ Alcotest.(check string) "falls back" "ALPHA" (L.celebration t "a");
+ Alcotest.(check string) "neither: the key" "c" (L.celebration t "c")
+
+(* --raw must be a real identity table, not a special case threaded through every
+ call site: one table the whole program can pass around. *)
+let test_raw_is_identity () =
+ Alcotest.(check string) "celebration" "ef-epiphany" (L.celebration L.raw "ef-epiphany");
+ Alcotest.(check string) "colour" "white" (L.colour L.raw "white");
+ Alcotest.(check string) "weekday" "0" (L.weekday L.raw 0)
+
+let test_malformed_is_error_not_crash () =
+ match L.of_string "[celebration\nbroken" with
+ | Error _ -> ()
+ | Ok _ -> Alcotest.fail "a malformed language file must be an Error, never accepted"
+
+let test_missing_meta_lang_is_error () =
+ match L.of_string "[celebration]\na = B\n" with
+ | Error _ -> ()
+ | Ok _ -> Alcotest.fail "a language file with no [meta] lang must be an Error"
+
+let suite =
+ ( "Lang",
+ [ Alcotest.test_case "meta" `Quick test_meta;
+ Alcotest.test_case "lookups" `Quick test_lookups;
+ Alcotest.test_case "missing degrades to key" `Quick test_missing_degrades_to_key;
+ Alcotest.test_case "fallback chain" `Quick test_fallback_chain;
+ Alcotest.test_case "raw is identity" `Quick test_raw_is_identity;
+ Alcotest.test_case "malformed is error" `Quick test_malformed_is_error_not_crash;
+ Alcotest.test_case "missing meta lang is error" `Quick test_missing_meta_lang_is_error ] )