<commit_before><?php

use DSH\Bencode\Collection\Dictionary;

class DictionaryTestCase extends PHPUnit_Framework_TestCase
{
    public function testBasicConstruction()
    {
        $dictionary = new Dictionary(['key' => 'value']);
        $this->assertEquals('d3:key5:valuee', $dictionary->encode());

        return $dictionary;
    }

    public function testStreamDecoding()
    {
        $stream = 'd3:key5:valuee';
        $dictionary = new Dictionary();
        
        $dictionary->decode($stream);

        $this->assertEquals($stream, $dictionary->encode());
    }

    public function testBigStreamReading()
    {
        $buffer = [
            'first' => 'value',
            'second' => 'another value',
            'third' => 'neat!'
        ];

        $stream = 'd5:first5:value6:second13:another value5:third5:neat!e';
        
        $dictionary = new Dictionary($buffer);
        $this->assertEquals($stream, $dictionary->encode());
    }

    /**
     * @expectedException \DSH\Bencode\Exception\DictionaryException
     */
    public function testImproperEncoding()
    {
        $dictionary = new Dictionary();
        $stream = 'd3:key4:valueel';

        $dictionary->decode($stream);
    }

    /**
     * @expectedException \DSH\Bencode\Exception\DictionaryException
     */
    public function testImproperByteEncoding()
    {
        $dictionary = new Dictionary();
        $stream = 'd3:key4:valuee';

        $dictionary->decode($stream);
    }
    
    /**
     * Reads a Bencoded file and puts it into and array.
     */
    public function testReadingFile()
    {
        $stream = file_get_contents(__DIR__ . '/assets/test.be');
        
        if (substr($stream, -1) === "\n") {
            $stream = substr($stream, 0, -1);
        }
        
        $dictionary = new Dictionary();
        $dictionary->decode($stream);
        
        $this->assertEquals($stream, $dictionary->encode());
    }
}<commit_msg>Reads from a file, documents from a file.<commit_after><?php

use DSH\Bencode\Collection\Dictionary;

class DictionaryTestCase extends PHPUnit_Framework_TestCase
{
    public function testBasicConstruction()
    {
        $dictionary = new Dictionary(['key' => 'value']);
        $this->assertEquals('d3:key5:valuee', $dictionary->encode());

        return $dictionary;
    }

    public function testStreamDecoding()
    {
        $stream = 'd3:key5:valuee';
        $dictionary = new Dictionary();
        
        $dictionary->decode($stream);

        $this->assertEquals($stream, $dictionary->encode());
    }

    public function testBigStreamReading()
    {
        $buffer = [
            'first' => 'value',
            'second' => 'another value',
            'third' => 'neat!'
        ];

        $stream = 'd5:first5:value6:second13:another value5:third5:neat!e';
        
        $dictionary = new Dictionary($buffer);
        $this->assertEquals($stream, $dictionary->encode());
    }

    /**
     * @expectedException \DSH\Bencode\Exception\DictionaryException
     */
    public function testImproperEncoding()
    {
        $dictionary = new Dictionary();
        $stream = 'd3:key4:valueel';

        $dictionary->decode($stream);
    }

    /**
     * @expectedException \DSH\Bencode\Exception\DictionaryException
     */
    public function testImproperByteEncoding()
    {
        $dictionary = new Dictionary();
        $stream = 'd3:key4:valuee';

        $dictionary->decode($stream);
    }
    
    /**
     * Reads a Bencoded file and puts it into and array.
     */
    public function testReadingFile()
    {
        $stream = file_get_contents(__DIR__ . '/assets/test.be');
        
        // you should always trim and opened file, in case of a
        // newline character at the end, fucking some shit up
        $stream = trim($stream);
        
        $dictionary = new Dictionary();
        $dictionary->decode($stream);
        
        $this->assertEquals($stream, $dictionary->encode());
    }
}
{'fraction_non_alphanumeric': 0.13888192529456003, 'fraction_numerical': 0.008272750062672349, 'mean_word_length': 2.2893652102225888, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1755857', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1089, 'n_words': 221}