<commit_before>#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • http://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • http://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • http://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests if assignments work
#
use i3test i3_autostart => 0;

sub open_special {
    my %args = @_;
    $args{name} //= 'special window';

    # We use dont_map because i3 will not map the window on the current
    # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
    my $window = open_window(
        %args,
        wm_class => 'special',
        dont_map => 1,
    );
    $window->map;
    return $window;
}

sub test_workspace_assignment {
    my $target_ws = "@_";

    # initialize the target workspace, then go to a fresh one
    ok(!($target_ws ~~ @{get_workspace_names()}), "$target_ws does not exist yet");
    cmd "workspace $target_ws";
    cmp_ok(@{get_ws_content($target_ws)}, '==', 0, "no containers on $target_ws yet");
    cmd 'open';
    cmp_ok(@{get_ws_content($target_ws)}, '==', 1, "one container on $target_ws");
    my $tmp = fresh_workspace;

    ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
    ok($target_ws ~~ @{get_workspace_names()}, "$target_ws does not exist yet");

    # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
    # map the window -- it will be assigned to a different workspace and will only
    # be mapped once you switch to that workspace
    my $window = open_special(dont_map => 1);
    $window->map;
    sync_with_i3;

    ok(@{get_ws_content($tmp)} == 0, 'still no containers');
    ok(@{get_ws_content($target_ws)} == 2, "two containers on $target_ws");

    return $window
}

#####################################################################
# start a window and see that it does not get assigned with an empty config
#####################################################################

my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
EOT
<commit_msg>166-assign.t: improve open_special call<commit_after>#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • http://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • http://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • http://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests if assignments work
#
use i3test i3_autostart => 0;

sub open_special {
    my %args = @_;
    $args{name} //= 'special window';
    $args{wm_class} //= 'special';

    # We use dont_map because i3 will not map the window on the current
    # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
    my $window = open_window(
        %args,
        dont_map => 1,
    );
    $window->map;
    return $window;
}

sub test_workspace_assignment {
    my $target_ws = "@_";

    # initialize the target workspace, then go to a fresh one
    ok(!($target_ws ~~ @{get_workspace_names()}), "$target_ws does not exist yet");
    cmd "workspace $target_ws";
    cmp_ok(@{get_ws_content($target_ws)}, '==', 0, "no containers on $target_ws yet");
    cmd 'open';
    cmp_ok(@{get_ws_content($target_ws)}, '==', 1, "one container on $target_ws");
    my $tmp = fresh_workspace;

    ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
    ok($target_ws ~~ @{get_workspace_names()}, "$target_ws does not exist yet");

    # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
    # map the window -- it will be assigned to a different workspace and will only
    # be mapped once you switch to that workspace
    my $window = open_special;
    sync_with_i3;

    ok(@{get_ws_content($tmp)} == 0, 'still no containers');
    ok(@{get_ws_content($target_ws)} == 2, "two containers on $target_ws");

    return $window
}

#####################################################################
# start a window and see that it does not get assigned with an empty config
#####################################################################

my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
EOT

{'fraction_non_alphanumeric': 0.19204719248415994, 'fraction_numerical': 0.01878960017478698, 'mean_word_length': 3.839323467230444, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7116615', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1517, 'n_words': 429}