Add tests for the couch_util:find_in_binary/2 Based off the tests that Nick North wrote for COUCHDB-1953.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/94b93f76 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/94b93f76 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/94b93f76 Branch: refs/heads/1953-fix-mime-multipart-parsing Commit: 94b93f761db121e40758898f59c82dc2312ed7f1 Parents: 25cceb0 Author: Paul J. Davis <[email protected]> Authored: Fri Jan 24 19:00:36 2014 -0600 Committer: Paul J. Davis <[email protected]> Committed: Fri Jan 24 19:03:01 2014 -0600 ---------------------------------------------------------------------- test/etap/043-find-in-binary.t | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/94b93f76/test/etap/043-find-in-binary.t ---------------------------------------------------------------------- diff --git a/test/etap/043-find-in-binary.t b/test/etap/043-find-in-binary.t new file mode 100755 index 0000000..dca1d9c --- /dev/null +++ b/test/etap/043-find-in-binary.t @@ -0,0 +1,68 @@ +#!/usr/bin/env escript +%% -*- erlang -*- + +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +main(_) -> + test_util:init_code_path(), + + etap:plan(length(cases())), + case (catch test()) of + ok -> + etap:end_tests(); + Other -> + etap:diag(io_lib:format("Test died abnormally: ~p", [Other])), + etap:bail(Other) + end, + ok. + + +test() -> + lists:foreach(fun({Needle, Haystack, Result}) -> + try + Msg = io_lib:format("Looking for ~s in ~s", [Needle, Haystack]), + etap:is(couch_util:find_in_binary(Needle, Haystack), Result, Msg) + catch _T:_R -> + etap:diag("~p", [{_T, _R}]) + end + end, cases()), + ok. + + +cases() -> + [ + {<<"foo">>, <<"foobar">>, {exact, 0}}, + {<<"foo">>, <<"foofoo">>, {exact, 0}}, + {<<"foo">>, <<"barfoo">>, {exact, 3}}, + {<<"foo">>, <<"barfo">>, {partial, 3}}, + {<<"f">>, <<"fobarfff">>, {exact, 0}}, + {<<"f">>, <<"obarfff">>, {exact, 4}}, + {<<"f">>, <<"obarggf">>, {exact, 6}}, + {<<"f">>, <<"f">>, {exact, 0}}, + {<<"f">>, <<"g">>, not_found}, + {<<"foo">>, <<"f">>, {partial, 0}}, + {<<"foo">>, <<"g">>, not_found}, + {<<"foo">>, <<"">>, not_found}, + {<<"fofo">>, <<"foofo">>, {partial, 3}}, + {<<"foo">>, <<"gfobarfo">>, {partial, 6}}, + {<<"foo">>, <<"gfobarf">>, {partial, 6}}, + {<<"foo">>, <<"gfobar">>, not_found}, + {<<"fog">>, <<"gbarfogquiz">>, {exact, 4}}, + {<<"ggg">>, <<"ggg">>, {exact, 0}}, + {<<"ggg">>, <<"ggggg">>, {exact, 0}}, + {<<"ggg">>, <<"bggg">>, {exact, 1}}, + {<<"ggg">>, <<"bbgg">>, {partial, 2}}, + {<<"ggg">>, <<"bbbg">>, {partial, 3}}, + {<<"ggg">>, <<"bgbggbggg">>, {exact, 6}}, + {<<"ggg">>, <<"bgbggb">>, not_found} + ].
