File: test_string.rb

package info (click to toggle)
sup-mail 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,412 kB
  • sloc: ruby: 13,047; sh: 167; makefile: 12
file content (63 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download
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
# encoding: utf-8

require "test_helper"

require "sup/util"

describe "Sup's String extension" do
  describe "#display_length" do
    let :data do
      [
        ['some words', 10,],
        ['δΈ­ζ–‡', 4,],
        ['Γ€', 1,],
        ['😱', 2],
        #['πŸ³οΈβ€πŸŒˆ', 2],  # Emoji ZWJ sequence not yet supported (see PR #563)
      ]
    end

    it "calculates display length of a string" do
      data.each do |(str, length)|
        assert_equal length, str.dup.display_length
      end
    end
  end

  describe "#slice_by_display_length(len)" do
    let :data do
      [
        ['some words', 6, 'some w'],
        ['δΈ­ζ–‡', 2, 'δΈ­'],
        ['Γ€lpha', 3, 'Γ€lp'],
        ['😱😱', 2, '😱'],
        #['πŸ³οΈβ€πŸŒˆ', 2, 'πŸ³οΈβ€πŸŒˆ'],  # Emoji ZWJ sequence not yet supported (see PR #563)
      ]
    end

    it "slices string by display length" do
      data.each do |(str, length, sliced)|
        assert_equal sliced, str.dup.slice_by_display_length(length)
      end
    end
  end

  describe "#wrap" do
    let :data do
      [
        ['some words', 6, ['some', 'words']],
        ['some words', 80, ['some words']],
        ['δΈ­ζ–‡', 2, ['δΈ­', 'ζ–‡']],
        ['δΈ­ζ–‡', 5, ['δΈ­ζ–‡']],
        ['Γ€lpha', 3, ['Γ€lp', 'ha']],
        ['😱😱', 2, ['😱', '😱']],
        #['πŸ³οΈβ€πŸŒˆπŸ³οΈβ€πŸŒˆ', 2, ['πŸ³οΈβ€πŸŒˆ', 'πŸ³οΈβ€πŸŒˆ']],  # Emoji ZWJ sequence not yet supported (see PR #563)
      ]
    end

    it "wraps string by display length" do
      data.each do |(str, length, wrapped)|
        assert_equal wrapped, str.dup.wrap(length)
      end
    end
  end
end