"Fossies" - the Fresh Open Source Software Archive

Member "Gtk3-0.035/t/zz-GtkTextBuffer.t" (1 May 2019, 5644 Bytes) of package /linux/privat/Gtk3-0.035.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 # Originally copied from Gtk2/t/GtkTextBuffer.t.
    4 
    5 BEGIN { require './t/inc/setup.pl' }
    6 
    7 use strict;
    8 use warnings;
    9 use utf8;
   10 use Glib qw/TRUE FALSE/;
   11 
   12 plan tests => 45;
   13 
   14 my $table = Gtk3::TextTagTable -> new();
   15 
   16 my $buffer = Gtk3::TextBuffer -> new($table);
   17 isa_ok($buffer, "Gtk3::TextBuffer");
   18 is($buffer -> get_tag_table(), $table);
   19 
   20 $buffer = Gtk3::TextBuffer -> new();
   21 isa_ok($buffer, "Gtk3::TextBuffer");
   22 
   23 isa_ok($buffer -> get_start_iter(), "Gtk3::TextIter");
   24 isa_ok($buffer -> get_end_iter(), "Gtk3::TextIter");
   25 
   26 $buffer -> set_modified(FALSE);
   27 
   28 # Use one multi-byte character to test length handling.
   29 my $text = "Lore ipsem dolor‽  I think that is misspelled.\n";
   30 my $start = sub { $buffer -> get_start_iter() };
   31 my $end = sub { $buffer -> get_end_iter() };
   32 my $bounds = sub { $buffer -> get_bounds() };
   33 
   34 $buffer -> insert($start->(), $text);
   35 ok($buffer -> insert_interactive($start->(), $text, TRUE));
   36 $buffer -> insert_at_cursor($text);
   37 ok($buffer -> insert_interactive_at_cursor($text, TRUE));
   38 $buffer -> insert_range($end->(), $bounds->());
   39 ok($buffer -> insert_range_interactive($end->(), $bounds->(), TRUE));
   40 
   41 my @tags = ($buffer -> create_tag("bla", indent => 2),
   42             $buffer -> create_tag("blub", indent => 2));
   43 
   44 $buffer -> create_tag("blaa", indent => 2);
   45 $buffer -> create_tag("bluub", indent => 2);
   46 
   47 $buffer -> insert_with_tags($start->(), $text, @tags);
   48 $buffer -> insert_with_tags_by_name($start->(), $text, "blaa", "bluub");
   49 
   50 is($buffer -> get_text($bounds->(), TRUE), $text x 18);
   51 is($buffer -> get_line_count(), 18+1);
   52 is($buffer -> get_char_count(), 18 * length $text);
   53 ok($buffer -> get_modified());
   54 
   55 isa_ok($buffer -> get_iter_at_line_offset(1, 10), "Gtk3::TextIter");
   56 isa_ok($buffer -> get_iter_at_offset(100), "Gtk3::TextIter");
   57 isa_ok($buffer -> get_iter_at_line(6), "Gtk3::TextIter");
   58 isa_ok($buffer -> get_iter_at_line_index(3, 12), "Gtk3::TextIter");
   59 
   60 my ($start_iter, $end_iter) = $buffer -> get_bounds();
   61 isa_ok($start_iter, "Gtk3::TextIter");
   62 isa_ok($end_iter, "Gtk3::TextIter");
   63 
   64 $buffer -> set_text($text);
   65 is($buffer -> get_text($bounds->(), TRUE), $text);
   66 is($buffer -> get_slice($bounds->(), TRUE), $text);
   67 
   68 $buffer -> delete($bounds->());
   69 ok($buffer -> delete_interactive($bounds->(), TRUE));
   70 
   71 $buffer -> insert_pixbuf($start->(), Gtk3::Gdk::Pixbuf -> new("rgb", 0, 8, 10, 10));
   72 
   73 my $anchor = Gtk3::TextChildAnchor -> new();
   74 $buffer -> insert_child_anchor($start->(), $anchor);
   75 
   76 isa_ok($buffer -> get_iter_at_child_anchor($anchor), "Gtk3::TextIter");
   77 
   78 isa_ok($buffer -> create_child_anchor($start->()), "Gtk3::TextChildAnchor");
   79 
   80 my $mark = $buffer -> create_mark("bla", $start->(), TRUE);
   81 isa_ok($mark, "Gtk3::TextMark");
   82 is($buffer -> get_mark("bla"), $mark);
   83 
   84 isa_ok($buffer -> get_iter_at_mark($mark), "Gtk3::TextIter");
   85 
   86 $buffer -> move_mark($mark, $end->());
   87 $buffer -> move_mark_by_name("bla", $start->());
   88 $buffer -> delete_mark($mark);
   89 
   90 $mark = $buffer -> create_mark("bla", $start->(), TRUE);
   91 $buffer -> delete_mark_by_name("bla");
   92 
   93 isa_ok($buffer -> get_insert(), "Gtk3::TextMark");
   94 isa_ok($buffer -> get_selection_bound(), "Gtk3::TextMark");
   95 
   96 $buffer -> place_cursor($end->());
   97 
   98 ok(!$buffer -> delete_selection(TRUE, TRUE));
   99 ok(!$buffer -> get_selection_bounds());
  100 
  101 {
  102   $buffer -> select_range($bounds->());
  103 }
  104 
  105 my $tag_one = $buffer -> create_tag("alb", indent => 2, justification => 'center');
  106 isa_ok($tag_one, "Gtk3::TextTag");
  107 is($tag_one->get ('indent'), 2);
  108 is($tag_one->get ('justification'), 'center');
  109 
  110 $buffer -> apply_tag($tag_one, $bounds->());
  111 $buffer -> apply_tag_by_name("alb", $bounds->());
  112 
  113 my $tag_two = $buffer -> create_tag("bulb", indent => 2);
  114 my $tag_three = $buffer -> create_tag(undef, indent => 2);
  115 isa_ok($tag_two, "Gtk3::TextTag");
  116 isa_ok($tag_three, "Gtk3::TextTag");
  117 
  118 $buffer -> remove_tag($tag_one, $bounds->());
  119 $buffer -> remove_tag_by_name("bulb", $bounds->());
  120 $buffer -> remove_all_tags($bounds->());
  121 
  122 SKIP: {
  123   skip 'clipboard stuff; missing annotations', 0
  124     unless Gtk3::CHECK_VERSION (3, 2, 0);
  125 
  126   my $clipboard = Gtk3::Clipboard::get(Gtk3::Gdk::Atom::intern('clipboard', Glib::FALSE));
  127 
  128   $buffer -> paste_clipboard($clipboard, $buffer -> get_end_iter(), TRUE);
  129   $buffer -> paste_clipboard($clipboard, undef, TRUE);
  130   $buffer -> copy_clipboard($clipboard);
  131   $buffer -> cut_clipboard($clipboard, TRUE);
  132 
  133   $buffer -> add_selection_clipboard($clipboard);
  134   $buffer -> remove_selection_clipboard($clipboard);
  135 }
  136 
  137 $buffer -> begin_user_action();
  138 $buffer -> end_user_action();
  139 
  140 {
  141   $buffer -> backspace($end->(), TRUE, TRUE);
  142 }
  143 
  144 {
  145   my $bool = $buffer -> get_has_selection();
  146   ok (1);
  147 
  148   my $targetlist = $buffer -> get_copy_target_list();
  149   isa_ok($targetlist, 'Gtk3::TargetList');
  150   $targetlist = $buffer -> get_paste_target_list();
  151   isa_ok($targetlist, 'Gtk3::TargetList');
  152 
  153   isa_ok($buffer -> get('copy-target-list'), 'Gtk3::TargetList');
  154   isa_ok($buffer -> get('paste-target-list'), 'Gtk3::TargetList');
  155 }
  156 
  157 {
  158   my $mark = Gtk3::TextMark -> new('bla', TRUE);
  159   $buffer -> add_mark($mark, $end->());
  160 }
  161 
  162 {
  163   my $buf = Gtk3::TextBuffer -> new();
  164   $buf -> set_text('v年x最y');
  165   my ($s,$e) = $buf -> get_bounds();
  166   ok($s -> forward_find_char(sub{shift eq '年'}));
  167   is($s -> get_char, '年');
  168   ok(not $e -> backward_find_char(sub{shift eq '%'}, undef, $s));
  169   is($e -> get_char, '年');
  170 }
  171 
  172 SKIP: {
  173   skip 'insert_markup', 1
  174     unless Gtk3::CHECK_VERSION (3, 16, 0);
  175 
  176   my $table = Gtk3::TextTagTable -> new();
  177   my $buffer = Gtk3::TextBuffer -> new($table);
  178   my $markup = "<b>Lore ipsem dolor‽</b>\n";
  179   $buffer -> insert_markup($buffer -> get_start_iter(), $markup);
  180   cmp_ok ($table -> get_size(), '>', 0);
  181 }
  182