#!/usr/bin/perl
#
# rlkeymaps: Tests for keymap functions
#
#   Copyright(C) 2024 Hiroo Hayashi
#
# Derived from: examples/rlkeymaps.c in the GNU Readline Library

use strict;
use warnings;
use Term::ReadLine;

my $t = new Term::ReadLine 'rlkeymaps';

my $errs = 0;
my $r;

my $nmap = $t->make_keymap();

$r = $t->set_keymap_name("emacs", $nmap);
if ($r >= 0) {
    warn("rlkeymaps: error: able to rename `emacs' keymap\n");
    $errs++;
}

my $emacsmap = $t->get_keymap_by_name("emacs");
$r = $t->set_keymap_name("newemacs", $emacsmap);
if ($r >= 0) {
    warn("rlkeymaps: error: able to set new name for emacs keymap\n");
    $errs++;
}

$r = $t->set_keymap_name("newemacs", $nmap);
if ($r < 0) {
    warn("rlkeymaps: error: newemacs: could not set keymap name\n");
    $errs++;
}

my $newemacs = $t->copy_keymap($emacsmap);
$r = $t->set_keymap_name("newemacs", $newemacs);
if ($r < 0) {
    warn <<EOM;
rlkeymaps: error: newemacs: could not set `newemacs' keymap to new map
EOM
    $errs++;
}

$r = $t->set_keymap_name("emacscopy", $newemacs);
if ($r < 0) {
    warn("rlkeymaps: error: emacscopy: could not rename created keymap\n");
    $errs++;
}

exit $errs;
