main_test.ml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. (*
  2. * _ _ ____ _
  3. * _| || |_/ ___| ___ _ __ _ __ ___ | |
  4. * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
  5. * |_ _|___) | __/ |_) | |_) | (_) |_|
  6. * |_||_| |____/ \___| .__/| .__/ \___/(_)
  7. * |_| |_|
  8. *
  9. * Personal Social Web.
  10. *
  11. * Copyright (C) The #Seppo contributors. All rights reserved.
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *)
  26. let tail x =
  27. Assrt.equals_string __LOC__ "ok" (if x |> Result.is_ok then "ok" else "no")
  28. open Seppo_lib
  29. let test_sift_handles () =
  30. let h = {|Some text with @
  31. linebreaks and @sepp0@example.com. And
  32. @other@example.com, even a @third@example.com!|} |> Main.find_handles in
  33. match h with
  34. | [a;b;c] ->
  35. a |> Assrt.equals_string __LOC__ "third@example.com";
  36. b |> Assrt.equals_string __LOC__ "other@example.com";
  37. c |> Assrt.equals_string __LOC__ "sepp0@example.com"
  38. | l -> l |> List.length |> Assrt.equals_int __LOC__ 30000
  39. let fn = Mapcdb.Cdb "tmp/main.cdb"
  40. let Mapcdb.Cdb fn' = fn
  41. let test_sift_tags () =
  42. Logr.debug (fun m -> m "%s.%s" "Main_test" "test_sift_tags");
  43. let open Rfc4287 in
  44. Unix.(try unlink fn' with Unix_error (ENOENT, "unlink", _) -> ());
  45. File.touch fn';
  46. let published = Rfc3339.T "2023-03-09T12:34:56+01:00" in
  47. let author = Uri.make ~userinfo:"uhu" () in
  48. let lang = Rfc4646 "en" in
  49. let uri = Uri.empty in
  50. let title = {|Just a #note|} in
  51. let content = {|th some #more #Hashtags.|} in
  52. (let* e = Entry.from_text_plain ~published ~author ~lang ~uri title content in
  53. let* e : Entry.t = Main.sift_tags fn e in
  54. let li = e.categories in
  55. li |> List.length |> Assrt.equals_int __LOC__ 3;
  56. let (Category.Label (Single la),Category.Term (Single te),sc) = li |> List.hd in
  57. la |> Assrt.equals_string __LOC__ "note";
  58. te |> Assrt.equals_string __LOC__ "note";
  59. sc |> Uri.to_string |> Assrt.equals_string __LOC__ "o/t/";
  60. let li = li |> List.tl in
  61. let (Category.Label (Single la),Category.Term (Single te),sc) = li |> List.hd in
  62. la |> Assrt.equals_string __LOC__ "more";
  63. te |> Assrt.equals_string __LOC__ "more";
  64. sc |> Uri.to_string |> Assrt.equals_string __LOC__ "o/t/";
  65. let li = li |> List.tl in
  66. let (Category.Label (Single la),Category.Term (Single te),sc) = li |> List.hd in
  67. la |> Assrt.equals_string __LOC__ "Hashtags";
  68. te |> Assrt.equals_string __LOC__ "Hashtags";
  69. sc |> Uri.to_string |> Assrt.equals_string __LOC__ "o/t/";
  70. let li = li |> List.tl in
  71. li |> List.length |> Assrt.equals_int __LOC__ 0;
  72. Ok e) |> tail;
  73. assert true
  74. let test_tmap_from_cdb () =
  75. let tm = Tag.Tmap.empty in
  76. let tm = Tag.Tmap.add "a" "A" tm in
  77. Tag.Tmap.find "a" tm |> Assrt.equals_string __LOC__ "A";
  78. assert true
  79. let () =
  80. Unix.chdir "../../../test/";
  81. test_sift_handles ();
  82. test_sift_tags ();
  83. test_tmap_from_cdb ();
  84. assert true