Anonymous avatar Anonymous committed 0b8aac8

some webmachine_util tests

Comments (0)

Files changed (1)

src/webmachine_util.erl

       || I <- HtmlMatch ],
     [ ?assertEqual("image/jpeg", choose_media_type(Provided, I))
       || I <- JpgMatch ].
+
+convert_request_date_test() ->
+    ?assertMatch({{_,_,_},{_,_,_}},
+                 convert_request_date("Wed, 30 Dec 2009 14:39:02 GMT")),
+    ?assertMatch(bad_date,
+                 convert_request_date(<<"does not handle binaries">>)).
+
+compare_ims_dates_test() ->
+    Late = {{2009,12,30},{14,39,02}},
+    Early = {{2009,12,30},{13,39,02}},
+    ?assertEqual(true, compare_ims_dates(Late, Early)),
+    ?assertEqual(false, compare_ims_dates(Early, Late)).
+
+guess_mime_test() ->
+    TextTypes = [".html",".css",".htc",".manifest",".txt"],
+    AppTypes = [".xhtml",".xml",".js",".swf",".zip",".bz2",
+                ".gz",".tar",".tgz"],
+    ImgTypes = [".jpg",".jpeg",".gif",".png",".ico",".svg"],
+    ?assertEqual([], [ T || T <- TextTypes,
+                            1 /= string:str(guess_mime(T),"text/") ]),
+    ?assertEqual([], [ T || T <- AppTypes,
+                            1 /= string:str(guess_mime(T),"application/") ]),
+    ?assertEqual([], [ T || T <- ImgTypes,
+                            1 /= string:str(guess_mime(T),"image/") ]).
+
+unquote_header_test() ->
+    ?assertEqual("hello", unquote_header("hello")),
+    ?assertEqual("hello", unquote_header("\"hello\"")),
+    ?assertEqual("hello", unquote_header("\"hello")),
+    ?assertEqual("hello", unquote_header("\"\\h\\e\\l\\l\\o\"")).
+
+now_diff_milliseconds_test() ->
+    Late = {10, 10, 10},
+    Early1 = {10, 9, 9},
+    Early2 = {9, 9, 9},
+    ?assertEqual(1000, now_diff_milliseconds(Late, Early1)),
+    ?assertEqual(1000001000, now_diff_milliseconds(Late, Early2)).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.