File: ANSITest.php

package info (click to toggle)
php-phpseclib3 3.0.46-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,528 kB
  • sloc: php: 30,756; xml: 392; makefile: 21
file content (69 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

/**
 * @author    Jim Wigginton <terrafrost@php.net>
 * @copyright 2014 Jim Wigginton
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
 */

namespace phpseclib3\Tests\Unit\File;

use phpseclib3\File\ANSI;
use phpseclib3\Tests\PhpseclibTestCase;

class ANSITest extends PhpseclibTestCase
{
    public function testCase1()
    {
        $str = "\x1B[07m"; // turn reverse video on
        $str .= "aaaaaaaaaaaaaaaaaa";
        $str .= "\x1B[10D"; // move cursor left 10 lines
        $str .= "\x1B[m"; // reset everything
        $str .= "bbb";

        $ansi = new ANSI();
        $ansi->appendString($str);

        $expected = '<pre width="80" style="color: white; background: black">';
        $expected .= '<span style="color: black"><span style="background: white">aaaaaaaa</span></span>';
        $expected .= 'bbb';
        $expected .= '<span style="color: black"><span style="background: white">aaaaaaa</span></span>';
        $expected .= '</pre>';

        $this->assertSame($ansi->getScreen(), $expected);
    }

    public function testCaseJ()
    {
        $str = "\x1B[H"; // Move cursor to upper left corner
        $str .= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        $str .= "\x1B[H"; // Move cursor to upper left corner
        $str .= "\x1B[J"; // Clear screen from cursor down

        $ansi = new ANSI();
        $ansi->appendString($str);

        $expected = '<pre width="80" style="color: white; background: black">';
        $expected .= '</pre>';

        $this->assertSame($ansi->getScreen(), $expected);
    }

    public function testLineOverflow()
    {
        $str = '';
        foreach (range('a', 'y') as $char) {
            $str .= "$char\r\n";
        }
        $str .= str_repeat('z', 100);

        $ansi = new ANSI();
        $ansi->appendString($str);

        $screen = $ansi->getScreen();

        $lines = explode("\r\n", $screen);
        $this->assertCount(24, $lines);
        $this->assertSame(str_repeat('z', 80), $lines[22]);
    }
}