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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
# Copyright (C) 2015-2017 Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class TestGtkTextBuffer < Test::Unit::TestCase
include GtkTestUtils
sub_test_case "instance methods" do
def setup
@text_buffer = Gtk::TextBuffer.new
@text_buffer.text = "Hello World!"
end
sub_test_case "#insert" do
test "no options" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert(iter, "Ruby ")
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test "GLib::Bytes" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert(iter, GLib::Bytes.new("Ruby "))
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":interactive" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert(iter, "Ruby ", :interactive => true)
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":default_editable => true" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert(iter, "Ruby ",
:interactive => true,
:default_editable => true)
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":default_editable => false" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert(iter, "Ruby ",
:interactive => true,
:default_editable => false)
assert_equal("Hello World!", @text_buffer.text)
end
end
sub_test_case "#insert_markup" do
setup do
only_gtk_version(3, 16)
end
test "String" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert_markup(iter, "<b>Ruby</b> ")
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test "GLib::Bytes" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert_markup(iter, GLib::Bytes.new("<b>Ruby</b> "))
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test "n_bytes" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.insert_markup(iter, "<b>Ruby</b> language", 12)
assert_equal("Hello Ruby World!", @text_buffer.text)
end
end
sub_test_case "#insert_at_cursor" do
test "no options" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.place_cursor(iter)
@text_buffer.insert_at_cursor("Ruby ")
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":interactive" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.place_cursor(iter)
@text_buffer.insert_at_cursor("Ruby ",
:interactive => true)
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":default_editable => true" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.place_cursor(iter)
@text_buffer.insert_at_cursor("Ruby ",
:interactive => true,
:default_editable => true)
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test ":default_editable => false" do
iter = @text_buffer.get_iter_at(:offset => "Hello ".bytesize)
@text_buffer.place_cursor(iter)
@text_buffer.insert_at_cursor("Ruby ",
:interactive => true,
:default_editable => false)
assert_equal("Hello World!", @text_buffer.text)
end
end
test "#text=" do
@text_buffer.text = "Hello Ruby World!"
assert_equal("Hello Ruby World!", @text_buffer.text)
end
test "#serialize_formats" do
assert_equal([Gdk::Atom],
@text_buffer.serialize_formats.collect(&:class))
end
test "#deserialize_formats" do
@text_buffer.register_deserialize_tagset(nil)
assert_equal([Gdk::Atom],
@text_buffer.deserialize_formats.collect(&:class))
end
test "#serialize and #deserialize" do
format = @text_buffer.serialize_formats[0]
serialized = @text_buffer.serialize(@text_buffer,
format,
@text_buffer.start_iter,
@text_buffer.end_iter)
output_text_buffer = Gtk::TextBuffer.new
output_format = output_text_buffer.register_deserialize_tagset(nil)
output_text_buffer.deserialize(output_text_buffer,
output_format,
output_text_buffer.start_iter,
serialized)
assert_equal(@text_buffer.text,
output_text_buffer.text)
end
sub_test_case "#selection_bounds" do
test "selected" do
insert_iter =
@text_buffer.get_iter_at(:offset => "Hel".bytesize)
selection_bound_iter =
@text_buffer.get_iter_at(:offset => "Hello Wor".bytesize)
@text_buffer.select_range(insert_iter, selection_bound_iter)
assert_equal([insert_iter.offset, selection_bound_iter.offset],
@text_buffer.selection_bounds.collect(&:offset))
end
test "not selected" do
assert_nil(@text_buffer.selection_bounds)
end
end
sub_test_case "#create_tag" do
test "default" do
tag = @text_buffer.create_tag
assert_nil(tag.name)
end
test "named" do
tag = @text_buffer.create_tag("new-tag")
assert_equal("new-tag", tag.name)
end
end
end
end
|