hirb-unicode 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hirb-unicode.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ NOT READY TO RELEASE
2
+
3
+ UNDER DEVELOPMENT
4
+
5
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ namespace :test do
6
+ desc 'Run tests of hirb gem with hirb-unicode'
7
+ task :hirb do |t|
8
+ gem 'hirb' # Load hirb specified in gemfile
9
+ hirb_gem_path = Gem.loaded_specs["hirb"].full_gem_path
10
+ test_path = File.expand_path(File.join(hirb_gem_path, 'test', '*_test.rb'))
11
+ sh "bundle exec bacon -q hirb-unicode.rb #{test_path}"
12
+ end
13
+
14
+ desc 'Run tests of hirb-unicode gem'
15
+ task :unicode do |t|
16
+ sh 'bundle exec bacon -I. -q test/*_test.rb'
17
+ end
18
+
19
+ end
20
+
21
+ desc 'Run all tests'
22
+ task :test => ["test:hirb", "test:unicode"]
23
+
24
+ task :default => :test
25
+
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hirb-unicode/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hirb-unicode"
7
+ s.version = Hirb::Unicode::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["miaout17"]
10
+ s.email = ["miaout17 at gmail dot com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Unicode support for hirb}
13
+ s.description = %q{Unicode support for hirb}
14
+
15
+ s.rubyforge_project = "hirb-unicode"
16
+
17
+ s.add_dependency 'hirb', '~> 0.3.6'
18
+ s.add_dependency 'unicode-display_width', '~> 0.1.1'
19
+ # Use the same test utility as `hirb`
20
+ s.add_development_dependency 'bacon', '>= 1.1.0'
21
+ s.add_development_dependency 'mocha'
22
+ s.add_development_dependency 'mocha-on-bacon'
23
+ s.add_development_dependency 'bacon-bits'
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,31 @@
1
+ require 'hirb'
2
+ require 'unicode/display_width'
3
+
4
+ module Hirb
5
+ module Unicode
6
+ module StringUtility
7
+ def size(string)
8
+ string.display_width
9
+ end
10
+
11
+ def slice(string, offset, width)
12
+ chars = string.chars.to_a[offset..-1].to_a
13
+
14
+ current_length = 0
15
+ split_index = 0
16
+ chars.each_with_index do |c, i|
17
+ char_width = self.size(c)
18
+ break if current_length + char_width > width
19
+ split_index = i+1
20
+ current_length += char_width
21
+ end
22
+
23
+ split_index ||= chars.count
24
+ head = chars[0, split_index].join
25
+ head
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Hirb::String.extend(Hirb::Unicode::StringUtility)
@@ -0,0 +1,5 @@
1
+ module Hirb
2
+ module Unicode
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'test_helper')
3
+
4
+ describe "String" do
5
+
6
+ describe ".size returns correct width" do
7
+ it "given non-unicode string" do
8
+ Hirb::String.size("Hello, world.").should == 13
9
+ end
10
+ it "given unicode string" do
11
+ Hirb::String.size("鄉民您好").should == 8
12
+ Hirb::String.size("こんにちは").should == 10
13
+ Hirb::String.size("中英夾雜yoo").should == 11
14
+ end
15
+ end
16
+
17
+ describe ".ljust returns justified string" do
18
+ it "given non-unicode string" do
19
+ Hirb::String.ljust("Hello, world.", 15).should == "Hello, world. "
20
+ Hirb::String.ljust("Hello, world.", 5).should == "Hello, world."
21
+ end
22
+ it "given unicode string" do
23
+ Hirb::String.ljust("還我牛", 9).should == "還我牛 "
24
+ Hirb::String.ljust("維大利", 5).should == "維大利"
25
+ end
26
+ end
27
+
28
+ describe ".rjust returns justified string" do
29
+ it "given non-unicode string" do
30
+ Hirb::String.rjust("Hello, world.", 15).should == " Hello, world."
31
+ Hirb::String.rjust("Hello, world.", 1).should == "Hello, world."
32
+ end
33
+ it "given unicode string" do
34
+ Hirb::String.rjust("恭喜發財", 13).should == " 恭喜發財"
35
+ Hirb::String.rjust("紅包拿來", 1).should == "紅包拿來"
36
+ end
37
+ end
38
+
39
+ describe ".slice returns sliced string" do
40
+ it "given non-unicode string" do
41
+ Hirb::String.slice("Hello, world.", 0, 10).should == "Hello, wor"
42
+ end
43
+ it "given unicode string that could exactly match the length" do
44
+ Hirb::String.slice("三民主義五權憲法", 0, 8).should == "三民主義"
45
+ end
46
+ it "given unicode string that couldn't exactly match the length" do
47
+ Hirb::String.slice("六合彩大樂透", 0, 5).should == "六合"
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,63 @@
1
+ require 'bacon'
2
+ require 'bacon/bits'
3
+ require 'mocha'
4
+ require 'mocha-on-bacon'
5
+ require 'hirb'
6
+ require 'hirb-unicode'
7
+
8
+ include Hirb
9
+
10
+ module TestHelpers
11
+ # set these to avoid invoking stty multiple times which doubles test suite running time
12
+ ENV["LINES"] = ENV["COLUMNS"] = "20"
13
+ def reset_terminal_size
14
+ ENV["LINES"] = ENV["COLUMNS"] = "20"
15
+ end
16
+
17
+ def capture_stdout(&block)
18
+ original_stdout = $stdout
19
+ $stdout = fake = StringIO.new
20
+ begin
21
+ yield
22
+ ensure
23
+ $stdout = original_stdout
24
+ end
25
+ fake.string
26
+ end
27
+
28
+ def capture_stderr(&block)
29
+ original_stderr = $stderr
30
+ $stderr = fake = StringIO.new
31
+ begin
32
+ yield
33
+ ensure
34
+ $stderr = original_stderr
35
+ end
36
+ fake.string
37
+ end
38
+
39
+ def reset_config
40
+ View.instance_eval "@config = nil"
41
+ end
42
+ end
43
+
44
+ class Bacon::Context
45
+ include TestHelpers
46
+ end
47
+
48
+ class String
49
+ def unindent(num=nil)
50
+ regex = num ? /^\s{#{num}}/ : /^\s*/
51
+ gsub(regex, '').chomp
52
+ end
53
+ end
54
+
55
+ # mocks IRB for View + Pager
56
+ module ::IRB
57
+ class Irb
58
+ def initialize(context)
59
+ @context = context
60
+ end
61
+ def output_value; end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hirb-unicode
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - miaout17
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-17 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hirb
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 6
34
+ version: 0.3.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: unicode-display_width
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 25
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 1
50
+ version: 0.1.1
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bacon
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 1
64
+ - 1
65
+ - 0
66
+ version: 1.1.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :development
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha-on-bacon
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ type: :development
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: bacon-bits
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :development
110
+ version_requirements: *id006
111
+ description: Unicode support for hirb
112
+ email:
113
+ - miaout17 at gmail dot com
114
+ executables: []
115
+
116
+ extensions: []
117
+
118
+ extra_rdoc_files: []
119
+
120
+ files:
121
+ - .gitignore
122
+ - Gemfile
123
+ - README.md
124
+ - Rakefile
125
+ - hirb-unicode.gemspec
126
+ - lib/hirb-unicode.rb
127
+ - lib/hirb-unicode/version.rb
128
+ - test/string_test.rb
129
+ - test/test_helper.rb
130
+ has_rdoc: true
131
+ homepage: ""
132
+ licenses: []
133
+
134
+ post_install_message:
135
+ rdoc_options: []
136
+
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ requirements: []
158
+
159
+ rubyforge_project: hirb-unicode
160
+ rubygems_version: 1.3.7
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: Unicode support for hirb
164
+ test_files:
165
+ - test/string_test.rb
166
+ - test/test_helper.rb