<commit_before>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file rlp.cpp
 * @author <NAME> <<EMAIL>>
 * @date 2014
 * RLP test functions.
 */

#include <fstream>
#include <sstream>
#include <libdevcore/Log.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <boost/test/unit_test.hpp>
#include <algorithm>
#include "JsonSpiritHeaders.h"

using namespace std;
using namespace dev;
namespace js = json_spirit;

namespace dev
{
	namespace test
	{
		static void buildRLP(js::mValue& _v, RLPStream& _rlp)
		{
			if (_v.type() == js::array_type)
			{
				RLPStream s;
				for (auto& i: _v.get_array())
					buildRLP(i, s);
				_rlp.appendList(s.out());
			}
			else if (_v.type() == js::int_type)
				_rlp.append(_v.get_uint64());
			else if (_v.type() == js::str_type)
			{
				auto s = _v.get_str();
				if (s.size() && s[0] == '#')
					_rlp.append(bigint(s.substr(1)));
				else
					_rlp.append(s);
			}
		}

		static void getRLPTestCases(js::mValue& v)
		{
			string s = asString(contents("../../../tests/rlptest.json"));
			BOOST_REQUIRE_MESSAGE( s.length() > 0, 
				"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); 
			js::read_string(s, v);
		} 	

		static void checkRLPTestCase(js::mObject& o)
		{ 
			BOOST_REQUIRE( o.count("in") > 0 ); 
			BOOST_REQUIRE( o.count("out") > 0 ); 
			BOOST_REQUIRE(!o["out"].is_null());			
		} 

		static void checkRLPAgainstJson(js::mValue& v, RLP& u)
		{
			if ( v.type() == js::str_type ) 
			{ 
				const std::string& expectedText = v.get_str();
				if ( expectedText.front() == '#' ) 
				{ 
					// Deal with bigint instead of a raw string 
					std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); 
					std::stringstream bintStream(bigIntStr);  
					bigint val; 
					bintStream >> val; 
					BOOST_CHECK( !u.isList() ); <commit_msg>test/rlp bugfix: expectedText can be empty<commit_after>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file rlp.cpp
 * @author <NAME> <<EMAIL>>
 * @date 2014
 * RLP test functions.
 */

#include <fstream>
#include <sstream>
#include <libdevcore/Log.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <boost/test/unit_test.hpp>
#include <algorithm>
#include "JsonSpiritHeaders.h"

using namespace std;
using namespace dev;
namespace js = json_spirit;

namespace dev
{
	namespace test
	{
		static void buildRLP(js::mValue& _v, RLPStream& _rlp)
		{
			if (_v.type() == js::array_type)
			{
				RLPStream s;
				for (auto& i: _v.get_array())
					buildRLP(i, s);
				_rlp.appendList(s.out());
			}
			else if (_v.type() == js::int_type)
				_rlp.append(_v.get_uint64());
			else if (_v.type() == js::str_type)
			{
				auto s = _v.get_str();
				if (s.size() && s[0] == '#')
					_rlp.append(bigint(s.substr(1)));
				else
					_rlp.append(s);
			}
		}

		static void getRLPTestCases(js::mValue& v)
		{
			string s = asString(contents("../../../tests/rlptest.json"));
			BOOST_REQUIRE_MESSAGE( s.length() > 0, 
				"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); 
			js::read_string(s, v);
		} 	

		static void checkRLPTestCase(js::mObject& o)
		{ 
			BOOST_REQUIRE( o.count("in") > 0 ); 
			BOOST_REQUIRE( o.count("out") > 0 ); 
			BOOST_REQUIRE(!o["out"].is_null());			
		} 

		static void checkRLPAgainstJson(js::mValue& v, RLP& u)
		{
			if ( v.type() == js::str_type ) 
			{ 
				const std::string& expectedText = v.get_str();
				if ( !expectedText.empty() && expectedText.front() == '#' ) 
				{ 
					// Deal with bigint instead of a raw string 
					std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); 
					std::stringstream bintStream(bigIntStr);  
					bigint val; 
					bintStream >> val; 
					BOOST_CHECK( !u.isList() ); 
{'fraction_non_alphanumeric': 0.13881242626818718, 'fraction_numerical': 0.005505308690523005, 'mean_word_length': 3.3777969018932876, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 37, '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': '4686718', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1801, 'n_words': 506}