### ----------------------------------------------------
### -- Terminal::ANSIParser
### -- Licenses: Artistic-2.0
### -- Authors: Geoffrey Broadwell
### -- File: t/03-csi.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use lib $*PROGRAM.sibling('lib');
use ParserTestHelpers;

use Terminal::ANSIParser;


plan 6;


for 0x9B, (0x1B, 0x5B) -> $introducer {
    # CSI + Final Byte
    subtest "All final bytes produce valid sequences for CSI $introducer", {
        for flat 0x40..0x7E, 0xC0..0xFF -> $fb {
            my @input = flat $introducer.list, $fb;
            csi-test(@input, "CSI + Final Byte $fb parsed correctly");
        }
    }

    # CSI + Intermediate Byte + Final Byte
    subtest "Single intermediate bytes produce valid sequences for CSI $introducer", {
        for flat 0x20..0x2F, 0xA1..0xAF -> $ib {
            my @input = flat $introducer.list, $ib, $ib + 0x20;
            csi-test(@input, "CSI + Intermediate Byte $ib + Final Byte {$ib + 0x20} parsed correctly");
        }
    }

    # CSI Ignores
    subtest "Invalid sequences correctly ignored for CSI $introducer", {
        for 0x40, 0x7E, 0xC0, 0xFE -> $final {
            my @input = flat $introducer.list, 0x3A, $final;
            csi-ignore(@input, "CSI + 0x3A + $final is ignored");

            for 0x20, 0x2F, 0xA1, 0xAF -> $ib {
                for flat 0x30..0x3F, 0xB0..0xBF -> $error {
                    my @input = flat $introducer.list, $ib, $error, $final;
                    csi-ignore(@input, "CSI + $ib + $error + $final is ignored");
                }
            }
        }
    }
}


done-testing;


