open OUnit2 let test_get_title test_ctxt = let body = " Fabien

Header

" in 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 (Some str) in assert_equal (Some "foo bar baz") cleaned_str let test_escape_characters text_ctx = let html_str = "I'll" in let expected = "I'll" in assert_equal expected (SimpleHttp.decode_esc_char html_str) let test_https test_ctx = let url = "https://en.wikipedia.org/wiki/Main_Page" in let title = SimpleHttp.get_http_title (SimpleHttp.get_body url) in assert_equal (Some "Wikipedia, the free encyclopedia") title let test_is_url test_ctx = let urls = [ ("http://foo.bar", true); ("https://foo.bar", true); ("www.foo.bar", true); ("foo.bar", true); ("http://www.foo.bar", true); ("foo-bar", false); ("http://www.foo.bar/baz/quuz", true) ] in let check (url, b) = assert_equal (Evaluate.is_url url) b in List.iter check urls let test_is_imgur test_ctx = let urls = [ ("http://imgur.com", false); ("https://foo.bar", false); ("http://i.imgur.com/", false); ("http://i.imgur.com/foobar.png", true) ] in let check (url, b) = assert_equal (Evaluate.is_imgur_url url) b in List.iter check urls let test_imgur_gallery test_ctx = let urls = [ ("http://imgur.com", None); ("https://foo.bar", None); ("http://i.imgur.com/", None); ("http://i.imgur.com/foobar.png", Some "http://imgur.com/foobar"); ("https://i.imgur.com/foobar.png", Some "https://imgur.com/foobar") ] in let check (url, r) = assert_equal (Evaluate.get_imgur_gallery_url url) r in List.iter check urls (* Name the test cases and group them together *) let suite = "suite">::: [ "test get_title">:: test_get_title; "test remove_spaces">:: test_remove_spaces; "test HTML character escaping">:: test_escape_characters; "test HTTPS">:: test_https; "test urls">:: test_is_url; "test is_imgur">:: test_is_imgur; "test imgur gallery">:: test_imgur_gallery ] let () = run_test_tt_main suite