east_asian_width 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d380b157a8f62b0b2d1bd3fdbd6ed9235f6b83a1af449fafcb84ff1c799548f2
4
- data.tar.gz: 2bf4eabfdabbe3497263ff32a6178250f9a924905fe28d2b3375d81f6936b40d
3
+ metadata.gz: a57ec0f2211341b25ee8c12efd1799bd89882c5fbc692b7b04f4b7a764c434cc
4
+ data.tar.gz: 41f3d5d9b4f78a269c16e34913b5edbe2f3a1cec73447c5c40ca0e1418822ead
5
5
  SHA512:
6
- metadata.gz: 79a0e27e8d8ca4304f8aa2e5d80df99cb6bf975efc13a2b3557051e4909ecc84d92766a88e55115f31eb777b4d966ae9ce6a693f4e280738ff5716f622add946
7
- data.tar.gz: 7b728293e52d8a687e7c76ad04bd058687fee83f28c3d4bd74974036743bb4400b5680e208383bf0b5ff76cc95130571f7b56107a40af0c9ef85524fc17cf42f
6
+ metadata.gz: 5aaa1c06e7f4f0e384a1cca154c12d22b6900675fa83a96f2be510e219ac1686daa44ef7191f0e73e6b5492c83088dfb65bae79c71f462546932c744063ce322
7
+ data.tar.gz: 963c89e847a9ceb945675d76d7d3b00c50ff56eb2443e7b3b9ea261a420fc280548a4a8a08f6b52116f4ea33c9619c9b6a97cd05b96338d6f339bcea938ee70c
@@ -0,0 +1,43 @@
1
+ # East Asian Width
2
+
3
+ Get [East Asian Width](http://www.unicode.org/reports/tr11/) from a character.
4
+
5
+ 'F'(Fullwidth), 'H'(Halfwidth), 'W'(Wide), 'Na'(Narrow), 'A'(Ambiguous) or 'N'(Natural).
6
+
7
+ Original Code is [東アジアの文字幅 (East Asian Width) の判定 - 中途](http://d.hatena.ne.jp/takenspc/20111126#1322252878).
8
+
9
+ ---
10
+
11
+ This is a Ruby port of [East Asian Width](https://github.com/komagata/eastasianwidth).
12
+
13
+ Status: [b89f04d](https://github.com/komagata/eastasianwidth/commit/b89f04d44dc786885615e94cd6e2ba1ef7866fa4)
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ gem install east_asian_width
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'east_asian_width'
25
+
26
+ puts EastAsianWidth.east_asian_width('₩') # -> 'F'
27
+ puts EastAsianWidth.east_asian_width('。') # -> 'H'
28
+ puts EastAsianWidth.east_asian_width('뀀') # -> 'W'
29
+ puts EastAsianWidth.east_asian_width('a') # -> 'Na'
30
+ puts EastAsianWidth.east_asian_width('①') # -> 'A'
31
+ puts EastAsianWidth.east_asian_width('ف') # -> 'N'
32
+
33
+ puts EastAsianWidth.character_length('₩') # -> 2
34
+ puts EastAsianWidth.character_length('。') # -> 1
35
+ puts EastAsianWidth.character_length('뀀') # -> 2
36
+ puts EastAsianWidth.character_length('a') # -> 1
37
+ puts EastAsianWidth.character_length('①') # -> 2
38
+ puts EastAsianWidth.character_length('ف') # -> 1
39
+
40
+ puts EastAsianWidth.length('あいうえお') # -> 10
41
+ puts EastAsianWidth.length('abcdefg') # -> 7
42
+ puts EastAsianWidth.length('¢₩。ᅵㄅ뀀¢⟭a⊙①بف') # -> 19
43
+ ```
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,136 @@
1
+ require "minitest/autorun"
2
+
3
+ require('./lib/east_asian_width.rb')
4
+
5
+ describe EastAsianWidth do
6
+ before do
7
+ @eaw = EastAsianWidth
8
+ end
9
+
10
+ describe "east_asian_width" do
11
+ it "Fullwidth" do
12
+ @eaw.east_asian_width('¢').must_equal "F"
13
+ @eaw.east_asian_width('₩').must_equal "F"
14
+ end
15
+
16
+ it "Halfwidth" do
17
+ @eaw.east_asian_width('。').must_equal "H"
18
+ @eaw.east_asian_width('ᅵ').must_equal "H"
19
+ end
20
+
21
+ it "Wide" do
22
+ @eaw.east_asian_width('ㄅ').must_equal "W"
23
+ @eaw.east_asian_width('뀀').must_equal "W"
24
+ end
25
+
26
+ it "Narrow" do
27
+ @eaw.east_asian_width('¢').must_equal "Na"
28
+ @eaw.east_asian_width('⟭').must_equal "Na"
29
+ @eaw.east_asian_width('a').must_equal "Na"
30
+ end
31
+
32
+ it "Ambiguous" do
33
+ @eaw.east_asian_width('⊙').must_equal "A"
34
+ @eaw.east_asian_width('①').must_equal "A"
35
+ end
36
+
37
+ it "Natural" do
38
+ @eaw.east_asian_width('ب').must_equal "N"
39
+ @eaw.east_asian_width('ف').must_equal "N"
40
+ end
41
+ end
42
+
43
+ describe "character_length" do
44
+ it "Fullwidth" do
45
+ @eaw.character_length('¢').must_equal 2
46
+ @eaw.character_length('₩').must_equal 2
47
+ @eaw.character_length('𩸽').must_equal 2
48
+ end
49
+
50
+ it "Halfwidth" do
51
+ @eaw.character_length('。').must_equal 1
52
+ @eaw.character_length('ᅵ').must_equal 1
53
+ end
54
+
55
+ it "Wide" do
56
+ @eaw.character_length('ㄅ').must_equal 2
57
+ @eaw.character_length('뀀').must_equal 2
58
+ end
59
+
60
+ it "Narrow" do
61
+ @eaw.character_length('¢').must_equal 1
62
+ @eaw.character_length('⟭').must_equal 1
63
+ @eaw.character_length('a').must_equal 1
64
+ end
65
+
66
+ it "Ambiguous" do
67
+ @eaw.character_length('⊙').must_equal 2
68
+ @eaw.character_length('①').must_equal 2
69
+ end
70
+
71
+ it "Natural" do
72
+ @eaw.character_length('ب').must_equal 1
73
+ @eaw.character_length('ف').must_equal 1
74
+ end
75
+ end
76
+
77
+ describe "length" do
78
+ it "Fullwidth" do
79
+ @eaw.length('あいうえお').must_equal 10
80
+ end
81
+
82
+ it "Halfwidth" do
83
+ @eaw.length('abcdefg').must_equal 7
84
+ end
85
+
86
+ it "Mixed" do
87
+ @eaw.length('¢₩。ᅵㄅ뀀¢⟭a⊙①بف').must_equal 19
88
+ end
89
+
90
+ it "Surrogate-Pair character included" do
91
+ @eaw.length('a𩸽b').must_equal 4
92
+ end
93
+ end
94
+
95
+ describe "slice" do
96
+ it "Fullwidth" do
97
+ @eaw.slice("あいうえお", 0, 6).must_equal "あいう"
98
+ @eaw.slice("あいうえお", 2, 8).must_equal "いうえ"
99
+ @eaw.slice("あいうえお", 4, 10).must_equal "うえお"
100
+ @eaw.slice("あいうえお", 2, -2).must_equal "いうえ"
101
+ @eaw.slice("あいうえお", -2, 10).must_equal "お"
102
+ end
103
+ it "Fullwidth, start / end is not aligned" do
104
+ @eaw.slice("あいうえお", 0, 1).must_equal ""
105
+ @eaw.slice("あいうえお", 1, 9).must_equal "あいうえ"
106
+ @eaw.slice("あいうえお", 9, 10).must_equal "お"
107
+ @eaw.slice("あいうえお", -1, 10).must_equal "お"
108
+ @eaw.slice("あいうえお", 1, -1).must_equal "あいうえ"
109
+ end
110
+ it "Halfwidth" do
111
+ @eaw.slice("abcdefg", 0, 3).must_equal "abc"
112
+ @eaw.slice("abcdefg", 3, 6).must_equal "def"
113
+ @eaw.slice("abcdefg", -2, 7).must_equal "fg"
114
+ @eaw.slice("abcdefg", 5, -1).must_equal "f"
115
+ end
116
+ it "Mixed" do
117
+ @eaw.slice("aあb", 0, 3).must_equal "aあ"
118
+ @eaw.slice("aあb", 1, 4).must_equal "あb"
119
+ end
120
+ it "Mixed, start / end is not aligned" do
121
+ @eaw.slice("aあb", 0, 2).must_equal "a"
122
+ @eaw.slice("aあb", 2, 4).must_equal "あb"
123
+ @eaw.slice("aあb", -2, 4).must_equal "あb"
124
+ @eaw.slice("aあb", 2, -1).must_equal "あ"
125
+ (@eaw.slice("aあb", 0, 2) + @eaw.slice("aあb", 2, 4)).must_equal "aあb"
126
+ end
127
+ it "Surrogate-Pair character included" do
128
+ @eaw.slice("a𩸽b", 0, 3).must_equal "a𩸽"
129
+ @eaw.slice("a𩸽b", 1, 4).must_equal "𩸽b"
130
+ end
131
+ it "Surrogate-Pair character included, start / end is not aligned" do
132
+ @eaw.slice("a𩸽b", 0, 2).must_equal "a"
133
+ @eaw.slice("a𩸽b", 2, 4).must_equal "𩸽b"
134
+ end
135
+ end
136
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: east_asian_width
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaizhao Zhang
@@ -44,7 +44,10 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - README.md
48
+ - Rakefile
47
49
  - lib/east_asian_width.rb
50
+ - test/test_east_asian_width.rb
48
51
  homepage: https://github.com/zhangkaizhao/east_asian_width
49
52
  licenses:
50
53
  - MIT