<commit_before>/**
* @file      DecoderTests.cpp
* @copyright (c) 2014 by <NAME> (<EMAIL>) and contributors
* @license   BSD, see the @c LICENSE file for more details
* @brief     Tests for the Decoder class.
*/

#include <memory>
#include <sstream>

#include <gtest/gtest.h>

#include "BInteger.h"
#include "Decoder.h"
#include "TestUtils.h"

namespace bencoding {
namespace tests {

using namespace testing;

class DecoderTests: public Test {
protected:
	DecoderTests(): decoder(Decoder::create()) {}

	template <typename T>
	void assertDecodedAs(std::shared_ptr<BItem> bItem);

protected:
	std::unique_ptr<Decoder> decoder;
};

template <typename T>
void DecoderTests::assertDecodedAs(
		std::shared_ptr<BItem> bItem) {

	ASSERT_NE(bItem, nullptr)
		<< "expected a correctly decoded item";
	ASSERT_NE(bItem->as<T>(), nullptr)
		<< "expected " << typeid(T).name() << ", "
		<< "got " << typeid(*bItem).name();
}

TEST_F(DecoderTests,
IntegerZeroIsCorrectlyDecodedFromStream) {
	std::istringstream input{"i0e"};
	std::shared_ptr<BItem> bItem{decoder->decode(input)};

	ADD_SCOPED_TRACE;
	assertDecodedAs<BInteger>(bItem);
	auto bInteger = bItem->as<BInteger>();
	ASSERT_EQ(0, bInteger->value());
}

TEST_F(DecoderTests,
IntegerZeroIsCorrectlyDecodedFromString) {
	std::string data{"i0e"};
	std::shared_ptr<BItem> bItem{decoder->decode(data)};

	ADD_SCOPED_TRACE;
	assertDecodedAs<BInteger>(bItem);
	auto bInteger = bItem->as<BInteger>();
	ASSERT_EQ(0, bInteger->value());
}

} // namespace tests
} // namespace bencoding<commit_msg>DecoderTests: Reorganize tests.<commit_after>/**
* @file      DecoderTests.cpp
* @copyright (c) 2014 by <NAME> (<EMAIL>) and contributors
* @license   BSD, see the @c LICENSE file for more details
* @brief     Tests for the Decoder class.
*/

#include <memory>
#include <sstream>

#include <gtest/gtest.h>

#include "BInteger.h"
#include "Decoder.h"
#include "TestUtils.h"

namespace bencoding {
namespace tests {

using namespace testing;

class DecoderTests: public Test {
protected:
	DecoderTests(): decoder(Decoder::create()) {}

	template <typename T>
	void assertDecodedAs(std::shared_ptr<BItem> bItem);

protected:
	std::unique_ptr<Decoder> decoder;
};

template <typename T>
void DecoderTests::assertDecodedAs(
		std::shared_ptr<BItem> bItem) {

	ASSERT_NE(bItem, nullptr)
		<< "expected a correctly decoded item";
	ASSERT_NE(bItem->as<T>(), nullptr)
		<< "expected " << typeid(T).name() << ", "
		<< "got " << typeid(*bItem).name();
}

TEST_F(DecoderTests,
IntegerZeroIsCorrectlyDecoded) {
	std::string data{"i0e"};
	std::shared_ptr<BItem> bItem{decoder->decode(data)};

	ADD_SCOPED_TRACE;
	assertDecodedAs<BInteger>(bItem);
	auto bInteger = bItem->as<BInteger>();
	ASSERT_EQ(0, bInteger->value());
}

TEST_F(DecoderTests,
DecodeFromStreamWorksAsDecodeFromString) {
	std::istringstream input{"i0e"};
	std::shared_ptr<BItem> bItem{decoder->decode(input)};

	ADD_SCOPED_TRACE;
	assertDecodedAs<BInteger>(bItem);
	auto bInteger = bItem->as<BInteger>();
	ASSERT_EQ(0, bInteger->value());
}

} // namespace tests
} // namespace bencoding
{'fraction_non_alphanumeric': 0.1561483409238777, 'fraction_numerical': 0.00520494469746259, 'mean_word_length': 6.02054794520548, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 51, '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': '3478134', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1069, 'n_words': 225}