<commit_before>% (Abstract) tree validators for Wallaroo commits and tags
% Copyright (c) 2011 Red Hat, Inc., and <NAME>

-module(wallaroo_validators).
-export([succeed/2, compose/1]).

succeed(_Tree, _StoreMod) ->
    ok.

compose([]) ->    
    fun(T,S) -> succeed(T,S) end;
compose([V|Vs]) when is_function(V,2) -> 
    K = compose(Vs),
    fun(Tree, StoreMod) ->
	    case V(Tree, StoreMod) of
		ok ->
		    K(Tree, StoreMod);
		{fail, _Why}=F ->
		    F
	    end
    end.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

always(_,_) ->
    ok.

never(_,_) ->
    {fail, because}.

sometimes(X,_) ->
    case X of
	nowork ->
	    {fail, "nowork specified"};
	_ -> ok
    end.

bizarro_sometimes(X,_) ->
    case X of
	work ->
	    {fail, "work specified"};
	_ -> ok
    end.

basic_test_() ->
    {inorder,
     {setup,
      fun() -> ok end,
      fun(_) -> ok end,
      [?_assertEqual(ok, (compose([]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2, fun always/2]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2, fun bizarro_sometimes/2]))(work, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2]))(work, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2, fun always/2]))(work, bogus_mod)),
       ?_assertEqual({fail, "work specified"}, (compose([fun always/2, fun bizarro_sometimes/2]))(work, bogus_mod)),
       ?_assertEqual({fail, "nowork specified"}, (compose([fun always/2, fun bizarro_sometimes/2, fun sometimes/2]))(nowork, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2, fun bizarro_sometimes/2]))(maybe_work, bogus_mod))]}}.

-endif.<commit_msg>added another validators test<commit_after>% (Abstract) tree validators for Wallaroo commits and tags
% Copyright (c) 2011 Red Hat, Inc., and <NAME>

-module(wallaroo_validators).
-export([succeed/2, compose/1]).

succeed(_Tree, _StoreMod) ->
    ok.

compose([]) ->    
    fun(T,S) -> succeed(T,S) end;
compose([V|Vs]) when is_function(V,2) -> 
    K = compose(Vs),
    fun(Tree, StoreMod) ->
	    case V(Tree, StoreMod) of
		ok ->
		    K(Tree, StoreMod);
		{fail, _Why}=F ->
		    F
	    end
    end.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

always(_,_) ->
    ok.

never(_,_) ->
    {fail, because}.

sometimes(X,_) ->
    case X of
	nowork ->
	    {fail, "nowork specified"};
	_ -> ok
    end.

bizarro_sometimes(X,_) ->
    case X of
	work ->
	    {fail, "work specified"};
	_ -> ok
    end.

basic_test_() ->
    {inorder,
     {setup,
      fun() -> ok end,
      fun(_) -> ok end,
      [?_assertEqual(ok, (compose([]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2, fun always/2]))(work, bogus_mod)),
       ?_assertEqual({fail, because}, (compose([fun always/2, fun never/2, fun bizarro_sometimes/2]))(work, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2]))(work, bogus_mod)),
       ?_assertEqual(ok, (compose([(compose([fun always/2, fun sometimes/2])),(compose([fun always/2, fun sometimes/2]))]))(work, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2, fun always/2]))(work, bogus_mod)),
       ?_assertEqual({fail, "work specified"}, (compose([fun always/2, fun bizarro_sometimes/2]))(work, bogus_mod)),
       ?_assertEqual({fail, "nowork specified"}, (compose([fun always/2, fun bizarro_sometimes/2, fun sometimes/2]))(nowork, bogus_mod)),
       ?_assertEqual(ok, (compose([fun always/2, fun sometimes/2, fun bizarro_sometimes/2]))(maybe_work, bogus_mod))]}}.

-endif.
{'fraction_non_alphanumeric': 0.1880674448767834, 'fraction_numerical': 0.01556420233463035, 'mean_word_length': 3.5046728971962615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1065196', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1379, 'n_words': 313}