[perl-Gtk3] Improve the readability of a test



commit 90b03cf53777415ddd4d1b746a2b77387e9c0cbb
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Sat Jan 26 22:08:48 2013 +0100

    Improve the readability of a test

 t/zz-GtkTextBuffer.t |   87 ++++++++++++++++++++++++++-----------------------
 1 files changed, 46 insertions(+), 41 deletions(-)
---
diff --git a/t/zz-GtkTextBuffer.t b/t/zz-GtkTextBuffer.t
index a33dbaf..291b208 100644
--- a/t/zz-GtkTextBuffer.t
+++ b/t/zz-GtkTextBuffer.t
@@ -8,7 +8,7 @@ use strict;
 use warnings;
 use Glib qw/TRUE FALSE/;
 
-plan tests => 37;
+plan tests => 38;
 
 my $table = Gtk3::TextTagTable -> new();
 
@@ -24,12 +24,17 @@ isa_ok($buffer -> get_end_iter(), "Gtk3::TextIter");
 
 $buffer -> set_modified(FALSE);
 
-$buffer -> insert($buffer -> get_start_iter(), "Lore ipsem dolor.  I think that is misspelled.\n");
-ok($buffer -> insert_interactive($buffer -> get_start_iter(), "Lore ipsem dolor.  I think that is misspelled.\n", TRUE));
-$buffer -> insert_at_cursor("Lore ipsem dolor.  I think that is misspelled.\n");
-ok($buffer -> insert_interactive_at_cursor("Lore ipsem dolor.  I think that is misspelled.\n", TRUE));
-$buffer -> insert_range($buffer -> get_end_iter(), $buffer -> get_iter_at_offset(141), $buffer -> get_end_iter());
-ok($buffer -> insert_range_interactive($buffer -> get_end_iter(), $buffer -> get_iter_at_offset(188), $buffer -> get_end_iter(), TRUE));
+my $text = "Lore ipsem dolor.  I think that is misspelled.\n";
+my $start = sub { $buffer -> get_start_iter() };
+my $end = sub { $buffer -> get_end_iter() };
+my $bounds = sub { $buffer -> get_bounds() };
+
+$buffer -> insert($start->(), $text);
+ok($buffer -> insert_interactive($start->(), $text, TRUE));
+$buffer -> insert_at_cursor($text);
+ok($buffer -> insert_interactive_at_cursor($text, TRUE));
+$buffer -> insert_range($end->(), $bounds->());
+ok($buffer -> insert_range_interactive($end->(), $bounds->(), TRUE));
 
 my @tags = ($buffer -> create_tag("bla", indent => 2),
             $buffer -> create_tag("blub", indent => 2));
@@ -37,11 +42,12 @@ my @tags = ($buffer -> create_tag("bla", indent => 2),
 $buffer -> create_tag("blaa", indent => 2);
 $buffer -> create_tag("bluub", indent => 2);
 
-$buffer -> insert_with_tags($buffer -> get_start_iter(), "Lore ipsem dolor.  I think that is misspelled.\n", @tags);
-$buffer -> insert_with_tags_by_name($buffer -> get_start_iter(), "Lore ipsem dolor.  I think that is misspelled.\n", "blaa", "bluub");
+$buffer -> insert_with_tags($start->(), $text, @tags);
+$buffer -> insert_with_tags_by_name($start->(), $text, "blaa", "bluub");
 
-is($buffer -> get_line_count(), 9);
-is($buffer -> get_char_count(), 376);
+is($buffer -> get_text($bounds->(), TRUE), $text x 18);
+is($buffer -> get_line_count(), 18+1);
+is($buffer -> get_char_count(), 18 * length $text);
 ok($buffer -> get_modified());
 
 isa_ok($buffer -> get_iter_at_line_offset(1, 10), "Gtk3::TextIter");
@@ -49,67 +55,67 @@ isa_ok($buffer -> get_iter_at_offset(100), "Gtk3::TextIter");
 isa_ok($buffer -> get_iter_at_line(6), "Gtk3::TextIter");
 isa_ok($buffer -> get_iter_at_line_index(3, 12), "Gtk3::TextIter");
 
-my ($start, $end) = $buffer -> get_bounds();
-isa_ok($start, "Gtk3::TextIter");
-isa_ok($end, "Gtk3::TextIter");
+my ($start_iter, $end_iter) = $buffer -> get_bounds();
+isa_ok($start_iter, "Gtk3::TextIter");
+isa_ok($end_iter, "Gtk3::TextIter");
 
-$buffer -> set_text("Lore ipsem dolor.  I think that is misspelled.\n");
-is($buffer -> get_text($buffer -> get_start_iter(), $buffer -> get_end_iter(), TRUE), "Lore ipsem dolor.  I think that is misspelled.\n");
-is($buffer -> get_slice($buffer -> get_start_iter(), $buffer -> get_end_iter(), TRUE), "Lore ipsem dolor.  I think that is misspelled.\n");
+$buffer -> set_text($text);
+is($buffer -> get_text($bounds->(), TRUE), $text);
+is($buffer -> get_slice($bounds->(), TRUE), $text);
 
-$buffer -> delete($buffer -> get_start_iter(), $buffer -> get_end_iter());
-ok($buffer -> delete_interactive($buffer -> get_start_iter(), $buffer -> get_end_iter(), TRUE));
+$buffer -> delete($bounds->());
+ok($buffer -> delete_interactive($bounds->(), TRUE));
 
-$buffer -> insert_pixbuf($buffer -> get_start_iter(), Gtk3::Gdk::Pixbuf -> new("rgb", 0, 8, 10, 10));
+$buffer -> insert_pixbuf($start->(), Gtk3::Gdk::Pixbuf -> new("rgb", 0, 8, 10, 10));
 
 my $anchor = Gtk3::TextChildAnchor -> new();
-$buffer -> insert_child_anchor($buffer -> get_start_iter(), $anchor);
+$buffer -> insert_child_anchor($start->(), $anchor);
 
 isa_ok($buffer -> get_iter_at_child_anchor($anchor), "Gtk3::TextIter");
 
-isa_ok($buffer -> create_child_anchor($buffer -> get_start_iter()), "Gtk3::TextChildAnchor");
+isa_ok($buffer -> create_child_anchor($start->()), "Gtk3::TextChildAnchor");
 
-my $mark = $buffer -> create_mark("bla", $buffer -> get_start_iter(), TRUE);
+my $mark = $buffer -> create_mark("bla", $start->(), TRUE);
 isa_ok($mark, "Gtk3::TextMark");
 is($buffer -> get_mark("bla"), $mark);
 
 isa_ok($buffer -> get_iter_at_mark($mark), "Gtk3::TextIter");
 
-$buffer -> move_mark($mark, $buffer -> get_end_iter());
-$buffer -> move_mark_by_name("bla", $buffer -> get_start_iter());
+$buffer -> move_mark($mark, $end->());
+$buffer -> move_mark_by_name("bla", $start->());
 $buffer -> delete_mark($mark);
 
-$mark = $buffer -> create_mark("bla", $buffer -> get_start_iter(), TRUE);
+$mark = $buffer -> create_mark("bla", $start->(), TRUE);
 $buffer -> delete_mark_by_name("bla");
 
 isa_ok($buffer -> get_insert(), "Gtk3::TextMark");
 isa_ok($buffer -> get_selection_bound(), "Gtk3::TextMark");
 
-$buffer -> place_cursor($buffer -> get_end_iter());
+$buffer -> place_cursor($end->());
 
 ok(!$buffer -> delete_selection(TRUE, TRUE));
 ok(!$buffer -> get_selection_bounds());
 
-SKIP: {
-  $buffer -> select_range($buffer -> get_start_iter(), $buffer -> get_end_iter());
+{
+  $buffer -> select_range($bounds->());
 }
 
 my $tag_one = $buffer -> create_tag("alb", indent => 2);
 isa_ok($tag_one, "Gtk3::TextTag");
 
-$buffer -> apply_tag($tag_one, $buffer -> get_start_iter(), $buffer -> get_end_iter());
-$buffer -> apply_tag_by_name("alb", $buffer -> get_start_iter(), $buffer -> get_end_iter());
+$buffer -> apply_tag($tag_one, $bounds->());
+$buffer -> apply_tag_by_name("alb", $bounds->());
 
 my $tag_two = $buffer -> create_tag("bulb", indent => 2);
 my $tag_three = $buffer -> create_tag(undef, indent => 2);
 isa_ok($tag_two, "Gtk3::TextTag");
 isa_ok($tag_three, "Gtk3::TextTag");
 
-$buffer -> remove_tag($tag_one, $buffer -> get_start_iter(), $buffer -> get_end_iter());
-$buffer -> remove_tag_by_name("bulb", $buffer -> get_start_iter(), $buffer -> get_end_iter());
-$buffer -> remove_all_tags($buffer -> get_start_iter(), $buffer -> get_end_iter());
+$buffer -> remove_tag($tag_one, $bounds->());
+$buffer -> remove_tag_by_name("bulb", $bounds->());
+$buffer -> remove_all_tags($bounds->());
 
-SKIP: {
+{
   my $clipboard = Gtk3::Clipboard::get(Gtk3::Gdk::Atom::intern('clipboard', Glib::FALSE));
 
   $buffer -> paste_clipboard($clipboard, $buffer -> get_end_iter(), TRUE);
@@ -124,11 +130,11 @@ SKIP: {
 $buffer -> begin_user_action();
 $buffer -> end_user_action();
 
-SKIP: {
-  $buffer -> backspace($buffer -> get_end_iter(), TRUE, TRUE);
+{
+  $buffer -> backspace($end->(), TRUE, TRUE);
 }
 
-SKIP: {
+{
   my $bool = $buffer -> get_has_selection();
   ok (1);
 
@@ -141,8 +147,7 @@ SKIP: {
   isa_ok($buffer -> get('paste-target-list'), 'Gtk3::TargetList');
 }
 
-SKIP: {
+{
   my $mark = Gtk3::TextMark -> new('bla', TRUE);
-  my $iter = $buffer -> get_end_iter();
-  $buffer -> add_mark($mark, $iter);
+  $buffer -> add_mark($mark, $end->());
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]