PHP Classes

File: tests/AsciiTest.php

Recommend this page to a friend!
  Classes of Lars Moelleken   portable ascii   tests/AsciiTest.php   Download  
File: tests/AsciiTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: portable ascii
Manipulate text strings without special extensions
Author: By
Last change:
Date: 5 years ago
Size: 2,606 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
voku\tests;

use
voku\helper\ASCII;

/**
 * @internal
 */
final class AsciiTest extends \PHPUnit\Framework\TestCase
{
    public function
testUtf8()
    {
       
$str = 'testiñg';
        static::
assertFalse(ASCII::is_ascii($str));
    }

    public function
testAscii()
    {
       
$str = 'testing';
        static::
assertTrue(ASCII::is_ascii($str));
    }

    public function
testInvalidChar()
    {
       
$str = "tes\xe9ting";
        static::
assertFalse(ASCII::is_ascii($str));
    }

    public function
testEmptyStr()
    {
       
$str = '';
        static::
assertTrue(ASCII::is_ascii($str));
    }

    public function
testNewLine()
    {
       
$str = "a\nb\nc";
        static::
assertTrue(ASCII::is_ascii($str));
    }

    public function
testTab()
    {
       
$str = "a\tb\tc";
        static::
assertTrue(ASCII::is_ascii($str));
    }

    public function
testUtf8ToAscii()
    {
       
$str = 'testiñg';
        static::
assertSame('testing', ASCII::to_ascii($str));
    }

    public function
testAsciiToAscii()
    {
       
$str = 'testing';
        static::
assertSame('testing', ASCII::to_ascii($str));
    }

    public function
testInvalidCharToAscii()
    {
       
$str = "tes\xe9ting";
        static::
assertSame('testing', ASCII::to_transliterate($str));

       
// ---

       
$str = "tes\xe9ting";
        static::
assertSame('', ASCII::to_ascii($str));
    }

    public function
testEmptyStrToAscii()
    {
       
$str = '';
        static::
assertSame('', ASCII::to_ascii($str));
    }

    public function
testNulAndNon7Bit()
    {
       
$str = "a\x00ñ\x00c";
        static::
assertSame('anc', ASCII::to_ascii($str));
    }

    public function
testNul()
    {
       
$str = "a\x00b\x00c";
        static::
assertSame('abc', ASCII::to_ascii($str));
    }

    public function
testNewLineToAscii()
    {
       
$str = "a\nb\nc";
        static::
assertSame("a\nb\nc", ASCII::to_transliterate($str));

       
// ---

       
$str = "a\nb\nc";
        static::
assertSame("a\nb\nc", ASCII::to_ascii($str, 'en', false));

       
// ---

       
$str = "a\nb\nc";
        static::
assertSame('a b c', ASCII::to_ascii($str, 'en', true));
    }

    public function
testTabToAscii()
    {
       
$str = "a\tb\tc";
        static::
assertSame("a\tb\tc", ASCII::to_transliterate($str));

       
// ---

       
$str = "a\tb\tc";
        static::
assertSame("a\tb\tc", ASCII::to_ascii($str, 'en', false));

       
// ---

       
$str = "a\tb\tc";
        static::
assertSame('a b c', ASCII::to_ascii($str, 'en', true));
    }
}