<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace li3_bot\tests\cases\extensions\command\bot;

use lithium\console\Request;
use li3_bot\tests\mocks\extensions\command\bot\MockIrc;

class IrcTest extends \lithium\test\Unit {

	public function setUp() {
		$this->irc = new MockIrc(array(
			'request' => new Request(array('input' => fopen('php://temp', 'w+'))),
			'host' => 'localhost',
			'classes' => array(
				'socket' => 'li3_bot\tests\mocks\extensions\command\MockIrcStream',
				'response' => 'lithium\tests\mocks\console\MockResponse'
			)
		));
	}

	public function tearDown() {
		unset($this->irc);
	}

	public function testRun() {
		$result = $this->irc->run();
		$resource = $this->irc->socket->resource();
		rewind($resource);

		$expected = "connected\n";

		$result = $this->irc->response->output;
		$this->assertTrue(strpos($result, $expected) !== false);

		$expected = "NICK li3_bot\r\nUSER li3_bot localhost\r\n";
		$result = fread($resource, 1024);
		$this->assertEqual($expected, $result);
	}

	public function testParseMessage() {
		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot :hello';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);
		$expected = array(
			0 => '',
			1 => 'nperson!~<EMAIL>014212.<EMAIL>',
			2 => 'PRIVMSG',
			3 => '#li3_bot',
			4 => 'hello'
		);
		$this->assertEqual($expected, $result);

		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot :This test.';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);
		$this->assertEqual('This test.', $result[4]);

		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot ::)';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);<commit_msg>Fix one failing assertion in `IrcTest`. All green baby<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace li3_bot\tests\cases\extensions\command\bot;

use lithium\console\Request;
use li3_bot\tests\mocks\extensions\command\bot\MockIrc;

class IrcTest extends \lithium\test\Unit {

	public function setUp() {
		$this->irc = new MockIrc(array(
			'request' => new Request(array('input' => fopen('php://temp', 'w+'))),
			'host' => 'localhost',
			'classes' => array(
				'socket' => 'li3_bot\tests\mocks\extensions\command\MockIrcStream',
				'response' => 'lithium\tests\mocks\console\MockResponse'
			)
		));
	}

	public function tearDown() {
		unset($this->irc);
	}

	public function testRun() {
		$result = $this->irc->run();
		$resource = $this->irc->socket->resource();
		rewind($resource);

		$expected = "connected\n";

		$result = $this->irc->response->output;
		$this->assertTrue(strpos($result, $expected) !== false);

		$expected = "NICK li3_bot\r\nUSER li3_bot localhost IRC BOT\r\n";
		$result = fread($resource, 1024);
		$this->assertEqual($expected, $result);
	}

	public function testParseMessage() {
		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot :hello';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);
		$expected = array(
			0 => '',
			1 => 'nperson!~<EMAIL>',
			2 => 'PRIVMSG',
			3 => '#li3_bot',
			4 => 'hello'
		);
		$this->assertEqual($expected, $result);

		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot :This test.';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);
		$this->assertEqual('This test.', $result[4]);

		$line = ':nperson!~<EMAIL> PRIVMSG #li3_bot ::)';
		$result = $this->irc->parse("(\s|(?<=\s):|^:)", $line, 5);
{'fraction_non_alphanumeric': 0.22186059126661242, 'fraction_numerical': 0.015730946569026308, 'mean_word_length': 4.115117891816921, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 74, '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': '2486371', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1356, 'n_words': 255}