aboutsummaryrefslogtreecommitdiffstats
path: root/test/core
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2016-02-13 03:18:54 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2016-02-13 03:18:54 +0900
commit1a111b7f6a493b590187a60c2cecbe59d749b315 (patch)
tree93e6f384ad813479be80bad6e1607584caa31661 /test/core
parent4bac234c28f32c53b3d1e9df260bc65c1b0978ef (diff)
downloadmikutter-1a111b7f6a493b590187a60c2cecbe59d749b315.tar.gz
cairo_textselectorは&<>が出現するとインデックスがずれる refs #813
Diffstat (limited to 'test/core')
-rw-r--r--test/core/test_cairo_textselector.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/test/core/test_cairo_textselector.rb b/test/core/test_cairo_textselector.rb
index 17a5f050..076b52fe 100644
--- a/test/core/test_cairo_textselector.rb
+++ b/test/core/test_cairo_textselector.rb
@@ -21,10 +21,31 @@ class TC_TextSelector < Test::Unit::TestCase
S1 = 'this is <b>a <a>test</a></b> text'.freeze
S2 = 'escape &gt; text'
S3 = 'にほんごもじれつ'
+ S4 = 'エンティティのテスト &lt;&lt;&lt;&lt; &amp;&amp;&amp;&amp; &gt;&gt;&gt; ておくれ'
+ S5 = 'f<a><b>a</b>v</a>'
def setup
end
+ def test_get_aindex
+ mp = MockPainter.new
+
+ s1 = S1.scan(Gdk::TextSelector::CHUNK_PATTERN)
+ assert_equal 8, mp.get_aindex(s1, 8)
+ assert_equal 10, mp.get_aindex(s1, 9)
+ assert_equal 9, mp.get_aindex(s1, 8, last: true)
+ assert_equal 10, mp.get_aindex(s1, 9, last: true)
+
+ s5 = S5.scan(Gdk::TextSelector::CHUNK_PATTERN)
+ assert_equal 0, mp.get_aindex(s5, 0)
+ assert_equal 1, mp.get_aindex(s5, 1)
+ assert_equal 4, mp.get_aindex(s5, 2)
+ assert_equal 3, mp.get_aindex(s5, 1, last: true)
+ assert_equal 5, mp.get_aindex(s5, 2, last: true)
+
+ assert_equal 9, mp.get_aindex(S2.scan(Gdk::TextSelector::CHUNK_PATTERN), 9)
+ end
+
def test_select
mp = MockPainter.new
assert_equal('th<span background="#000000" foreground="#ffffff">is is </span><b><span background="#000000" foreground="#ffffff">a </span><a><span background="#000000" foreground="#ffffff">te</span>st</a></b> text',
@@ -34,12 +55,21 @@ class TC_TextSelector < Test::Unit::TestCase
assert_equal('th<span background="#000000" foreground="#ffffff">is is <b>a <a>test</a></b> tex</span>t',
mp.textselector_press(2).textselector_release(18).textselector_markup(S1))
- assert_equal('esca<span background="#000000" foreground="#ffffff">pe &gt; t</span>ext',
+ assert_equal('esca<span background="#000000" foreground="#ffffff">pe &gt; </span>text',
mp.textselector_press(4).textselector_release(9).textselector_markup(S2))
assert_equal('にほ<span background="#000000" foreground="#ffffff">んごも</span>じれつ',
mp.textselector_press(2).textselector_release(5).textselector_markup(S3))
+ assert_equal('エンティティのテス<span background="#000000" foreground="#ffffff">ト</span> &lt;&lt;&lt;&lt; &amp;&amp;&amp;&amp; &gt;&gt;&gt; ておくれ',
+ mp.textselector_press(9).textselector_release(10).textselector_markup(S4))
+
+ assert_equal('エンティティのテス<span background="#000000" foreground="#ffffff">ト </span>&lt;&lt;&lt;&lt; &amp;&amp;&amp;&amp; &gt;&gt;&gt; ておくれ',
+ mp.textselector_press(9).textselector_release(11).textselector_markup(S4))
+
+ assert_equal('エンティティのテス<span background="#000000" foreground="#ffffff">ト &lt;</span>&lt;&lt;&lt; &amp;&amp;&amp;&amp; &gt;&gt;&gt; ておくれ',
+ mp.textselector_press(9).textselector_release(12).textselector_markup(S4))
+
end
end