[OCaml] Mobile-friendly clone of cgit.
test add dispatch and list_ext test suites
- test_dispatch: 5 test cases covering basic actions, parametric routes, nested repo paths, implicit summary fallback, and malformed URL rejection (commit/file/raw without hash → None) - test_list_ext: 2 test cases covering take/drop edge cases (empty list, beyond length, negative n, exact length) Total: 62 tests (was 55).
Changed files
test/test_dispatch.ml
@@ -0,0 +1,76 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
3
Added:
let action_to_string = function
4
Added:
| Ogit.Routes.Summary -> "Summary"
5
Added:
| Ogit.Routes.Commits_page -> "Commits_page"
6
Added:
| Ogit.Routes.Commits_for_branch b -> "Commits_for_branch " ^ b
7
Added:
| Ogit.Routes.Commit_detail h -> "Commit_detail " ^ h
8
Added:
| Ogit.Routes.Files_page -> "Files_page"
9
Added:
| Ogit.Routes.File_detail h -> "File_detail " ^ h
10
Added:
| Ogit.Routes.Branches_page -> "Branches_page"
11
Added:
| Ogit.Routes.Tags_page -> "Tags_page"
12
Added:
| Ogit.Routes.Readme_page -> "Readme_page"
13
Added:
| Ogit.Routes.Raw h -> "Raw " ^ h
14
Added:
15
Added:
let check_dispatch msg path expected =
16
Added:
let result = Ogit.Routes.dispatch path in
17
Added:
let pp fmt = function
18
Added:
| None -> Format.fprintf fmt "None"
19
Added:
| Some (repo, action) ->
20
Added:
Format.fprintf fmt "Some (%S, %s)" repo (action_to_string action)
21
Added:
in
22
Added:
let eq a b =
23
Added:
match (a, b) with
24
Added:
| None, None -> true
25
Added:
| Some (r1, a1), Some (r2, a2) ->
26
Added:
r1 = r2 && action_to_string a1 = action_to_string a2
27
Added:
| _ -> false
28
Added:
in
29
Added:
let testable = Alcotest.testable pp eq in
30
Added:
Alcotest.check testable msg expected result
31
Added:
32
Added:
let test_basic_actions () =
33
Added:
check_dispatch "summary" "myrepo/summary/" (Some ("myrepo", Summary));
34
Added:
check_dispatch "commits" "myrepo/commits/" (Some ("myrepo", Commits_page));
35
Added:
check_dispatch "files" "myrepo/files/" (Some ("myrepo", Files_page));
36
Added:
check_dispatch "branches" "myrepo/branches/" (Some ("myrepo", Branches_page));
37
Added:
check_dispatch "tags" "myrepo/tags/" (Some ("myrepo", Tags_page));
38
Added:
check_dispatch "readme" "myrepo/README" (Some ("myrepo", Readme_page))
39
Added:
40
Added:
let test_parametric_actions () =
41
Added:
check_dispatch "commit with hash" "myrepo/commit/abc123"
42
Added:
(Some ("myrepo", Commit_detail "abc123"));
43
Added:
check_dispatch "file with hash" "myrepo/file/def456"
44
Added:
(Some ("myrepo", File_detail "def456"));
45
Added:
check_dispatch "raw with hash" "myrepo/raw/789abc"
46
Added:
(Some ("myrepo", Raw "789abc"));
47
Added:
check_dispatch "commits for branch" "myrepo/commits/main"
48
Added:
(Some ("myrepo", Commits_for_branch "main"))
49
Added:
50
Added:
let test_nested_repo () =
51
Added:
check_dispatch "nested summary" "sub/dir/repo/summary/"
52
Added:
(Some ("sub/dir/repo", Summary));
53
Added:
check_dispatch "nested commit" "sub/repo/commit/abc"
54
Added:
(Some ("sub/repo", Commit_detail "abc"));
55
Added:
check_dispatch "deeply nested" "a/b/c/repo/files/"
56
Added:
(Some ("a/b/c/repo", Files_page))
57
Added:
58
Added:
let test_implicit_summary () =
59
Added:
check_dispatch "bare repo path" "myrepo" (Some ("myrepo", Summary));
60
Added:
check_dispatch "bare with trailing slash" "myrepo/" (Some ("myrepo", Summary))
61
Added:
62
Added:
let test_malformed () =
63
Added:
check_dispatch "empty path" "" None;
64
Added:
check_dispatch "commit without hash" "myrepo/commit/" None;
65
Added:
check_dispatch "file without hash" "myrepo/file/" None;
66
Added:
check_dispatch "raw without hash" "myrepo/raw/" None
67
Added:
68
Added:
let suite =
69
Added:
( "dispatch",
70
Added:
[
71
Added:
Alcotest.test_case "basic actions" `Quick test_basic_actions;
72
Added:
Alcotest.test_case "parametric actions" `Quick test_parametric_actions;
73
Added:
Alcotest.test_case "nested repo" `Quick test_nested_repo;
74
Added:
Alcotest.test_case "implicit summary" `Quick test_implicit_summary;
75
Added:
Alcotest.test_case "malformed URLs" `Quick test_malformed;
76
Added:
] )
test/test_list_ext.ml
@@ -0,0 +1,30 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
3
Added:
let list_int = Alcotest.(list int)
4
Added:
5
Added:
let test_take () =
6
Added:
Alcotest.check list_int "take 0" [] (Ogit.List_ext.take 0 [ 1; 2; 3 ]);
7
Added:
Alcotest.check list_int "take 2" [ 1; 2 ] (Ogit.List_ext.take 2 [ 1; 2; 3 ]);
8
Added:
Alcotest.check list_int "take all" [ 1; 2; 3 ]
9
Added:
(Ogit.List_ext.take 3 [ 1; 2; 3 ]);
10
Added:
Alcotest.check list_int "take beyond" [ 1; 2; 3 ]
11
Added:
(Ogit.List_ext.take 5 [ 1; 2; 3 ]);
12
Added:
Alcotest.check list_int "take from empty" [] (Ogit.List_ext.take 3 []);
13
Added:
Alcotest.check list_int "take negative" [] (Ogit.List_ext.take (-1) [ 1; 2 ])
14
Added:
15
Added:
let test_drop () =
16
Added:
Alcotest.check list_int "drop 0" [ 1; 2; 3 ]
17
Added:
(Ogit.List_ext.drop 0 [ 1; 2; 3 ]);
18
Added:
Alcotest.check list_int "drop 2" [ 3 ] (Ogit.List_ext.drop 2 [ 1; 2; 3 ]);
19
Added:
Alcotest.check list_int "drop all" [] (Ogit.List_ext.drop 3 [ 1; 2; 3 ]);
20
Added:
Alcotest.check list_int "drop beyond" [] (Ogit.List_ext.drop 5 [ 1; 2; 3 ]);
21
Added:
Alcotest.check list_int "drop from empty" [] (Ogit.List_ext.drop 3 []);
22
Added:
Alcotest.check list_int "drop negative" [ 1; 2 ]
23
Added:
(Ogit.List_ext.drop (-1) [ 1; 2 ])
24
Added:
25
Added:
let suite =
26
Added:
( "list_ext",
27
Added:
[
28
Added:
Alcotest.test_case "take" `Quick test_take;
29
Added:
Alcotest.test_case "drop" `Quick test_drop;
30
Added:
] )
test/test_ogit.ml
@@ -9,6 +9,8 @@
9
9
Test_discovery.suite;
10
10
Test_tree_paths.suite;
11
11
Test_router.suite;
12
Added:
Test_dispatch.suite;
13
Added:
Test_list_ext.suite;
12
14
Test_diff.suite;
13
15
Test_views.suite;
14
16
]