File: simple_ui.t

package info (click to toggle)
libconfig-model-perl 2.155-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,172 kB
  • sloc: perl: 15,117; makefile: 19
file content (103 lines) | stat: -rw-r--r-- 2,825 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- cperl -*-
use ExtUtils::testlib;
use Test::More;

use Test::Memory::Cycle;
use Config::Model;
use Config::Model::Tester::Setup qw/init_test/;
use Config::Model::SimpleUI;

use warnings;
use strict;
use lib "t/lib";
use utf8;
use open      qw(:std :utf8);    # undeclared streams in UTF-8

use Data::Dumper;

my ($model, $trace, $args) = init_test('interactive');

note("you can run the test in interactive mode by passing '--interactive' option, e.g. perl -Ilib t/simple_ui.t --interactive");

my $inst = $model->instance(
    root_class_name => 'Master',
    instance_name   => 'test1'
);
ok( $inst, "created dummy instance" );

my $root = $inst->config_root;

my $step = 'std_id:ab X=Bv - std_id:bc X=Av - a_string="toto tata"';
ok( $root->load( step => $step ), "set up data in tree with '$step'" );

# this test test only execution of user command, not their actual
# input
my $prompt = 'Test Prompt';

my $ui = Config::Model::SimpleUI->new(
    root   => $root,
    title  => 'Test Title',
    prompt => $prompt,
);

my $expected_prompt = $prompt . ':$ ';

ok( $ui, "Created ui" );

if ($args->{interactive}) {
    $ui->run_loop;
    done_testing;
    exit;
}

my $path = $ui->list_cd_path;

is_deeply(
    $path,
    [
        qw/std_id:ab std_id:bc tree_macro warp slave_y
            string_with_def a_uniline a_string int_v my_check_list
            a_boolean yes_no_boolean my_reference/
    ],
    'check list cd path at root'
);

is( $ui->prompt, $expected_prompt, 'test prompt at root' );

my @test = (
    [ 'vf std_id:ab', "Unexpected command 'vf'", $expected_prompt ],
    [
        'ls',
        join(' ', $root->get_element_names() ),
        $expected_prompt
    ],
    [ 'ls hash*', 'hash_a hash_b', $expected_prompt],
    [
        'll hash*',
        "name   │ type       │ value       \n".
        "───────┼────────────┼─────────────\n".
        "hash_a │ value hash │ [empty hash]\n".
        "hash_b │ value hash │ [empty hash]\n",
        $expected_prompt
    ],
    [ 'set a_string="some value with space"', "",   $expected_prompt ],
    [ 'cd std_id:ab',                         "",   $prompt . ': std_id:ab $ ' ],
    [ 'set X=Av',                             "",   $prompt . ': std_id:ab $ ' ],
    [ 'display X',                            "Av", $prompt . ': std_id:ab $ ' ],
    [ 'cd !',                                 "",   $expected_prompt ],
    [ 'delete std_id:ab',                     "",   $expected_prompt ],
);

foreach my $a_test (@test) {
    my ( $cmd, $expect, $expect_prompt ) = @$a_test;

    my $res = $ui->run($cmd);
    is($res , $expect, "exec $cmd" );

    is( $ui->prompt, $expect_prompt, "test prompt is $expect_prompt" );
}

memory_cycle_ok($model, "memory cycle");

done_testing;