diff --git a/ocaml/evaluate.ml b/ocaml/evaluate.ml index c561401..3a100df 100644 --- a/ocaml/evaluate.ml +++ b/ocaml/evaluate.ml @@ -11,10 +11,19 @@ let is_youtube_url url = string_match regexp url 0 +let remove_spaces str = + match str with + | Some s -> + let spaces = regexp "\\( *\\\n\\)+ *" in + Some (global_replace spaces "" s) + | None -> None + + + (* Maybe have a list of functions and * iter on all the items in the list *) let evaluate str = match str with | str when is_url str -> - SimpleHttp.get_http_title (SimpleHttp.get_body str) + SimpleHttp.get_http_title (SimpleHttp.get_body str) |> remove_spaces | _ -> None diff --git a/ocaml/test.ml b/ocaml/test.ml index d817e86..91ffef3 100644 --- a/ocaml/test.ml +++ b/ocaml/test.ml @@ -15,11 +15,22 @@ let test_get_title test_ctxt = let title = SimpleHttp.get_http_title body in assert_equal (Some "Fabien") title +let test_remove_spaces test_ctxt = + let str = " + + + foo bar baz + + " in + let cleaned_str = Evaluate.remove_spaces str in + assert_equal "foo bar baz" cleaned_str + (* Name the test cases and group them together *) let suite = "suite">::: - ["test get_title">:: test_get_title] + ["test get_title">:: test_get_title; + "test remove_spaces">:: test_remove_spaces] let () = run_test_tt_main suite