<commit_before>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  
%  This file is part of Logtalk <http://logtalk.org/>  
%  Copyright 1998-2017 <NAME> <<EMAIL>>
%  
%  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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


:- object(tests,
	extends(lgtunit)).

	:- info([
		version is 0.1,
		author is '<NAME>. Adapted to Logtalk by <NAME>',
		date is 2017/04/26,
		comment is 'Unit tests for the "redis" library.'
	]).

	:- uses(redis, [
		connect/1, connect/3,
		send/3,
		disconnect/1
	]).

	:- uses(list, [
		length/2
	]).

	:- if(current_logtalk_flag(prolog_dialect, sicstus)).
		:- use_module(system, [sleep/1]).
	:- elif(current_logtalk_flag(prolog_dialect, qp)).
		:- uses(user, [thread_sleep/1 as sleep/1]).
	:- elif(current_logtalk_flag(prolog_dialect, xsb)).
		:- uses(shell, [sleep/1]).
	:- else.
		% ECLiPSe, GNU Prolog, and SWI-Prolog provide sleep/1 as
		% a built-in predicate but we list it here for clarity
		:- uses(user, [sleep/1]).
	:- endif.

	%% CONNECTION...
	
	test(default_connection_and_echo) :-
		connect(Connection),
		send(Connection, echo('GNU Prolog rocks!'), bulk(Output)),
		disconnect(Connection),
		Output == 'GNU Prolog rocks!'.

	test(explicit_connection_and_echo) :-
		connect(localhost, 6379, Connection),
		send(Connection, echo('GNU Prolog rocks!'), bulk(Output)),
		disconnect(Connection),
		Output == 'GNU Prolog rocks!'.

	test(ping_the_server) :-
		connect(Connection),
		send(Connection, ping, status(Output)),
		disconnect(Connection),
		Output == 'PONG'.

	%% SERVER...<commit_msg>Only run Redis client tests if there's a Redis server running on localhost<commit_after>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  
%  This file is part of Logtalk <http://logtalk.org/>  
%  Copyright 1998-2017 <NAME> <<EMAIL>>
%  
%  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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


:- object(tests,
	extends(lgtunit)).

	:- info([
		version is 0.1,
		author is '<NAME>. Adapted to Logtalk by <NAME>',
		date is 2017/04/26,
		comment is 'Unit tests for the "redis" library.'
	]).

	:- uses(redis, [
		connect/1, connect/3,
		send/3,
		disconnect/1
	]).

	:- uses(list, [
		length/2
	]).

	:- if(current_logtalk_flag(prolog_dialect, sicstus)).
		:- use_module(system, [sleep/1]).
	:- elif(current_logtalk_flag(prolog_dialect, qp)).
		:- uses(user, [thread_sleep/1 as sleep/1]).
	:- elif(current_logtalk_flag(prolog_dialect, xsb)).
		:- uses(shell, [sleep/1]).
	:- else.
		% ECLiPSe, GNU Prolog, and SWI-Prolog provide sleep/1 as
		% a built-in predicate but we list it here for clarity
		:- uses(user, [sleep/1]).
	:- endif.

	% only run the tests if there's a Redis server running on localhost
	condition :-
		catch(
			(connect(Connection), disconnect(Connection)),
			_,
			fail
		).

	%% CONNECTION...
	
	test(default_connection_and_echo) :-
		connect(Connection),
		send(Connection, echo('GNU Prolog rocks!'), bulk(Output)),
		disconnect(Connection),
		Output == 'GNU Prolog rocks!'.

	test(explicit_connection_and_echo) :-
		connect(localhost, 6379, Connection),
		send(Connection, echo('GNU Prolog rocks!'), bulk(Output)),
		disconnect(Connection),
		Output == 'GNU Prolog rocks!'.

	test(ping_the_server) :-
		connect(Connection),
		send(Connection, ping, status(Output)),
		disconnect(Connection),
		Output == 'PONG'.

	%% SERVER...
{'fraction_non_alphanumeric': 0.19395689846700734, 'fraction_numerical': 0.0164407909353477, 'mean_word_length': 4.081264108352144, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4858436', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1404, 'n_words': 416}