<?php

namespace Buckhill\Support\tests\units;

use mageekguy\atoum;
use function Buckhill\Support\base32_decode;
use function Buckhill\Support\base32_encode;

class Base32 extends atoum
{
    public function testEncodePasses()
    {
        $test = [
            [
                'raw' => 'Lorem',
                'expected' => 'JRXXEZLN'
            ],

            [
                'raw' => 'Lorem Ipsum Dolor Sit',
                'expected' => 'JRXXEZLNEBEXA43VNUQEI33MN5ZCAU3JOQ======'
            ],

            [
                'raw' => 'Lorem Ipsum Dolor Sit Amet Consetetur. Another part of the text and so on.',
                'expected' => 'JRXXEZLNEBEXA43VNUQEI33MN5ZCAU3JOQQEC3LFOQQEG33OONSXIZLUOVZC4ICBNZXXI2DFOIQHAYLSOQQG6ZRAORUGKIDUMV4HIIDBNZSCA43PEBXW4LQ='
            ]
        ];

        foreach($test as $data)
        {
            $this->string($data['expected'])->isEqualTo(base32_encode($data['raw']));
        }
    }

    public function testDecode()
    {
        $this->given($input = 'OQ======')->and($decoded = base32_decode($input))
            ->then
            ->string($decoded)->isEqualTo('t');

    }

    public function testDecodeEmptyString()
    {
        $this->given($input = '')
            ->then
            ->string(base32_decode($input))->isEqualTo('');
    }

    public function testDecodeBinary()
    {
        $this->given($input = chr(27))
            ->then
                ->string(base32_decode($input))->isEqualTo('');
    }
}