aboutsummaryrefslogtreecommitdiffstats
path: root/test/core/test_cairo_textselector.rb
blob: 076b52fed9c367f077269934f5dedd1974da8a3d (plain)
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
# -*- coding: utf-8 -*-
$cairo = true
require File.expand_path(File.dirname(__FILE__) + '/../helper')

# require File.expand_path(File.dirname(__FILE__) + '/../utils')
miquire :mui, 'textselector'

$debug = true # !> instance variable @textselect_start not initialized
# seterrorlevel(:notice)
$logfile = nil
$daemon = false

class MockPainter
  include Gdk::TextSelector
  def on_modify
  end
end

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',
                 mp.textselector_press(2).textselector_release(12).textselector_markup(S1))
    assert_equal('th<span background="#000000" foreground="#ffffff">is i</span>s <b>a <a>test</a></b> text',
                 mp.textselector_press(2).textselector_release(6).textselector_markup(S1))
    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; </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
# >> Loaded suite -
# >> Started
# >> .
# >> Finished in 0.002221 seconds.
# >> 
# >> 1 tests, 5 assertions, 0 failures, 0 errors