sawarineko 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/README.md +7 -1
- data/Rakefile +14 -0
- data/lib/sawarineko/converter.rb +1 -1
- data/lib/sawarineko/version.rb +1 -1
- data/sawarineko.gemspec +2 -0
- data/spec/sawarineko/cli_spec.rb +39 -0
- data/spec/sawarineko/converter_spec.rb +41 -0
- data/spec/sawarineko/option_spec.rb +44 -0
- data/spec/sawarineko/version_spec.rb +11 -0
- data/spec/spec_helper.rb +87 -0
- data/spec/support/exit_code_matchers.rb +27 -0
- data/spec/support/file_helper.rb +39 -0
- data/spec/support/isolated_environment.rb +14 -0
- metadata +49 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75980ca94a35d77ff9069f6eeb2491e7522167dd
|
4
|
+
data.tar.gz: 3c56c3c707b69d61a026ce95d3770d5d19e6a5db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bd502c4127d2a492c343b8b4fd3e9798330a0121cb130e1bb2f4647f0b49997c7585e9067b2d6ec144f7fc6784d4e23b60e5c23f67c9b4db04ed089cccac5e1
|
7
|
+
data.tar.gz: 0a5f6a6ec900623a52c5eacb7511fd9a543c8cda2729c6d7bedee03468024fe2e5774fd168e2376bc3b4d43dc484cae24bb6106b4e7c992333c4f050909d768c
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Sawarineko
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/sawarineko)
|
4
|
+
[](https://travis-ci.org/yous/sawarineko)
|
5
|
+
[](https://gemnasium.com/yous/sawarineko)
|
6
|
+
[](http://inch-ci.org/github/yous/sawarineko)
|
7
|
+
[](https://www.omniref.com/ruby/gems/sawarineko)
|
8
|
+
|
3
9
|
> ななめななじゅうななどのならびでなくなくいななくななはんななだいなんなくならべてながながめ
|
4
10
|
|
5
11
|
Get your Nya!
|
@@ -43,7 +49,7 @@ Command flag | Description
|
|
43
49
|
|
44
50
|
## Contributing
|
45
51
|
|
46
|
-
1. Fork it (https://github.com/yous/sawarineko/fork
|
52
|
+
1. Fork it (https://github.com/yous/sawarineko/fork)
|
47
53
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
54
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
55
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new(:rubocop)
|
10
|
+
|
11
|
+
desc 'Run RSpec with code coverage'
|
12
|
+
task :coverage do
|
13
|
+
ENV['COVERAGE'] = 'true'
|
14
|
+
Rake::Task[:spec].execute
|
15
|
+
end
|
16
|
+
|
17
|
+
task default: [:spec, :rubocop]
|
data/lib/sawarineko/converter.rb
CHANGED
data/lib/sawarineko/version.rb
CHANGED
data/sawarineko.gemspec
CHANGED
@@ -21,5 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
25
|
spec.add_development_dependency 'rubocop', '~> 0.26.1'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
25
27
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Sawarineko::CLI do
|
6
|
+
include FileHelper
|
7
|
+
include_context 'isolated environment'
|
8
|
+
|
9
|
+
subject(:cli) { described_class.new }
|
10
|
+
|
11
|
+
before(:example) { $stdout = StringIO.new }
|
12
|
+
after(:example) { $stdout = STDOUT }
|
13
|
+
|
14
|
+
it 'converts text file passed as an argument' do
|
15
|
+
create_file('sawarineko.txt',
|
16
|
+
['ななめななじゅうななどの' \
|
17
|
+
'ならびでなくなくいななく' \
|
18
|
+
'ななはんななだいなんなく' \
|
19
|
+
'ならべてながながめ'])
|
20
|
+
expect(cli.run(['sawarineko.txt'])).to be(0)
|
21
|
+
expect($stdout.string).to eq('にゃにゃめにゃにゃじゅうにゃにゃどの' \
|
22
|
+
'にゃらびでにゃくにゃくいにゃにゃく' \
|
23
|
+
'にゃにゃはんにゃにゃだいにゃんにゃく' \
|
24
|
+
"にゃらべてにゃがにゃがめ\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'converts string passed as an stdin argument' do
|
28
|
+
allow($stdin).to receive(:read).once
|
29
|
+
.and_return('ななめななじゅうななどの' \
|
30
|
+
'ならびでなくなくいななく' \
|
31
|
+
'ななはんななだいなんなく' \
|
32
|
+
'ならべてながながめ')
|
33
|
+
expect(cli.run([])).to be(0)
|
34
|
+
expect($stdout.string).to eq('にゃにゃめにゃにゃじゅうにゃにゃどの' \
|
35
|
+
'にゃらびでにゃくにゃくいにゃにゃく' \
|
36
|
+
'にゃにゃはんにゃにゃだいにゃんにゃく' \
|
37
|
+
"にゃらべてにゃがにゃがめ\n")
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Sawarineko::Converter do
|
6
|
+
subject(:converter) { described_class }
|
7
|
+
|
8
|
+
it 'converts hiragana な to にゃ' do
|
9
|
+
expect(converter.new('な').convert).to eq('にゃ')
|
10
|
+
expect(converter.new('ななめななじゅうななどのならびで' \
|
11
|
+
'なくなくいななくななはんななだい' \
|
12
|
+
'なんなくならべてながながめ').convert)
|
13
|
+
.to eq('にゃにゃめにゃにゃじゅうにゃにゃどのにゃらびで' \
|
14
|
+
'にゃくにゃくいにゃにゃくにゃにゃはんにゃにゃだい' \
|
15
|
+
'にゃんにゃくにゃらべてにゃがにゃがめ')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'converts katakana ナ to ニャ' do
|
19
|
+
expect(converter.new('ナ').convert).to eq('ニャ')
|
20
|
+
expect(converter.new('ナナメナナジュウナナドノナラビデ' \
|
21
|
+
'ナクナクイナナクナナハンナナダイ' \
|
22
|
+
'ナンナクナラベテナガナガメ').convert)
|
23
|
+
.to eq('ニャニャメニャニャジュウニャニャドノニャラビデ' \
|
24
|
+
'ニャクニャクイニャニャクニャニャハンニャニャダイ' \
|
25
|
+
'ニャンニャクニャラベテニャガニャガメ')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'converts hangul 나-낳 to 냐-냫' do
|
29
|
+
('나'..'낳').zip('냐'..'냫').each do |na, nya|
|
30
|
+
expect(converter.new(na).convert).to eq(nya)
|
31
|
+
end
|
32
|
+
expect(converter.new('나랑 너랑 봄나들이 배낭 매고 봄나들이 ' \
|
33
|
+
'버드나무 낭창낭창 남실바람 남실남실 ' \
|
34
|
+
'개나리 꽃에 나비가 하나 ' \
|
35
|
+
'배낭 속에 바나나가 하나').convert)
|
36
|
+
.to eq('냐랑 너랑 봄냐들이 배냥 매고 봄냐들이 ' \
|
37
|
+
'버드냐무 냥창냥창 냠실바람 냠실냠실 ' \
|
38
|
+
'개냐리 꽃에 냐비가 하냐 ' \
|
39
|
+
'배냥 속에 바냐냐가 하냐')
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Sawarineko::Option do
|
6
|
+
include ExitCodeMatchers
|
7
|
+
|
8
|
+
subject(:option) { described_class.new }
|
9
|
+
|
10
|
+
before(:example) { $stdout = StringIO.new }
|
11
|
+
after(:example) { $stdout = STDOUT }
|
12
|
+
|
13
|
+
describe 'option' do
|
14
|
+
describe '-h/--help' do
|
15
|
+
it 'exits cleanly' do
|
16
|
+
expect { option.parse(['-h']) }.to exit_with_code(0)
|
17
|
+
expect { option.parse(['--help']) }.to exit_with_code(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'shows help text' do
|
21
|
+
begin
|
22
|
+
option.parse(['--help'])
|
23
|
+
rescue SystemExit # rubocop:disable Lint/HandleExceptions
|
24
|
+
end
|
25
|
+
|
26
|
+
expected_help = <<-END
|
27
|
+
Usage: sawarineko [options] [source]
|
28
|
+
-h, --help Print this message.
|
29
|
+
-v, --version Print version.
|
30
|
+
END
|
31
|
+
|
32
|
+
expect($stdout.string).to eq(expected_help)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '-v/--version' do
|
37
|
+
it 'exists cleanly' do
|
38
|
+
expect { option.parse(['-v']) }.to exit_with_code(0)
|
39
|
+
expect { option.parse(['--version']) }.to exit_with_code(0)
|
40
|
+
expect($stdout.string).to eq("#{Sawarineko::Version::STRING}\n" * 2)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if ENV['TRAVIS'] || ENV['COVERAGE']
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
if ENV['TRAVIS']
|
7
|
+
require 'coveralls'
|
8
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
9
|
+
end
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter '/spec/'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'sawarineko'
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# These two settings work together to allow you to limit a spec run
|
44
|
+
# to individual examples or groups you care about by tagging them with
|
45
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
46
|
+
# get run.
|
47
|
+
config.filter_run :focus
|
48
|
+
config.run_all_when_everything_filtered = true
|
49
|
+
|
50
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
51
|
+
# recommended. For more details, see:
|
52
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
53
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
54
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
55
|
+
config.disable_monkey_patching!
|
56
|
+
|
57
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
58
|
+
# be too noisy due to issues in dependencies.
|
59
|
+
config.warnings = true
|
60
|
+
|
61
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
62
|
+
# file, and it's useful to allow more verbose output when running an
|
63
|
+
# individual spec file.
|
64
|
+
if config.files_to_run.one?
|
65
|
+
# Use the documentation formatter for detailed output,
|
66
|
+
# unless a formatter has already been configured
|
67
|
+
# (e.g. via a command-line flag).
|
68
|
+
config.default_formatter = 'doc'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Print the 10 slowest examples and example groups at the
|
72
|
+
# end of the spec run, to help surface which specs are running
|
73
|
+
# particularly slow.
|
74
|
+
config.profile_examples = 10
|
75
|
+
|
76
|
+
# Run specs in random order to surface order dependencies. If you find an
|
77
|
+
# order dependency and want to debug it, you can fix the order by providing
|
78
|
+
# the seed, which is printed after each run.
|
79
|
+
# --seed 1234
|
80
|
+
config.order = :random
|
81
|
+
|
82
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
83
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
84
|
+
# test failures related to randomization by passing the same `--seed` value
|
85
|
+
# as the one that triggered the failure.
|
86
|
+
Kernel.srand config.seed
|
87
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Matches exit code of block with SystemExit.
|
4
|
+
module ExitCodeMatchers
|
5
|
+
RSpec::Matchers.define :exit_with_code do |code|
|
6
|
+
supports_block_expectations
|
7
|
+
actual = nil
|
8
|
+
match do |block|
|
9
|
+
begin
|
10
|
+
block.call
|
11
|
+
rescue SystemExit => e
|
12
|
+
actual = e.status
|
13
|
+
end
|
14
|
+
actual && actual == code
|
15
|
+
end
|
16
|
+
failure_message do
|
17
|
+
"expected block to call exit(#{code}) but exit" +
|
18
|
+
(actual.nil? ? ' not called' : "(#{actual}) was called")
|
19
|
+
end
|
20
|
+
failure_message_when_negated do
|
21
|
+
"expected block not to call exit(#{code})"
|
22
|
+
end
|
23
|
+
description do
|
24
|
+
"expect block to call exit(#{code})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# Util methods for processing file.
|
6
|
+
module FileHelper
|
7
|
+
# Create file with at given path with given content. Ensure parent directories
|
8
|
+
# are exists.
|
9
|
+
#
|
10
|
+
# path - An String path of file.
|
11
|
+
# content - An String or an Array of Strings content of file.
|
12
|
+
#
|
13
|
+
# Returns nothing.
|
14
|
+
def create_file(path, content)
|
15
|
+
file_path = File.expand_path(path)
|
16
|
+
dir_path = File.dirname(file_path)
|
17
|
+
FileUtils.makedirs(dir_path) unless File.exist?(dir_path)
|
18
|
+
write_file(path, content)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Write file content at given path.
|
22
|
+
#
|
23
|
+
# path - An String path of file.
|
24
|
+
# content - An String or an Array of Strings content of file.
|
25
|
+
#
|
26
|
+
# Returns nothing.
|
27
|
+
def write_file(path, content)
|
28
|
+
File.open(path, 'w') do |file|
|
29
|
+
case content
|
30
|
+
when ''
|
31
|
+
# Create empty file.
|
32
|
+
when String
|
33
|
+
file.puts content
|
34
|
+
when Array
|
35
|
+
file.puts content.join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sawarineko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ChaYoung You
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 0.26.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
55
83
|
description: Get your Nya!
|
56
84
|
email:
|
57
85
|
- yousbe@gmail.com
|
@@ -61,8 +89,10 @@ extensions: []
|
|
61
89
|
extra_rdoc_files: []
|
62
90
|
files:
|
63
91
|
- ".gitignore"
|
92
|
+
- ".rspec"
|
64
93
|
- ".rubocop.yml"
|
65
94
|
- ".rubocop_todo.yml"
|
95
|
+
- ".travis.yml"
|
66
96
|
- CHANGELOG.md
|
67
97
|
- Gemfile
|
68
98
|
- LICENSE.txt
|
@@ -75,6 +105,14 @@ files:
|
|
75
105
|
- lib/sawarineko/option.rb
|
76
106
|
- lib/sawarineko/version.rb
|
77
107
|
- sawarineko.gemspec
|
108
|
+
- spec/sawarineko/cli_spec.rb
|
109
|
+
- spec/sawarineko/converter_spec.rb
|
110
|
+
- spec/sawarineko/option_spec.rb
|
111
|
+
- spec/sawarineko/version_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/exit_code_matchers.rb
|
114
|
+
- spec/support/file_helper.rb
|
115
|
+
- spec/support/isolated_environment.rb
|
78
116
|
homepage: ''
|
79
117
|
licenses:
|
80
118
|
- MIT
|
@@ -99,4 +137,12 @@ rubygems_version: 2.2.2
|
|
99
137
|
signing_key:
|
100
138
|
specification_version: 4
|
101
139
|
summary: Get your Nya!
|
102
|
-
test_files:
|
140
|
+
test_files:
|
141
|
+
- spec/sawarineko/cli_spec.rb
|
142
|
+
- spec/sawarineko/converter_spec.rb
|
143
|
+
- spec/sawarineko/option_spec.rb
|
144
|
+
- spec/sawarineko/version_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/support/exit_code_matchers.rb
|
147
|
+
- spec/support/file_helper.rb
|
148
|
+
- spec/support/isolated_environment.rb
|