Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a test suite #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To test this gem, run `bundle exec rake test`.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

Contributing
Expand Down
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
require "bundler/gem_tasks"
task :default => :spec
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

task :default => :test
1 change: 1 addition & 0 deletions faker-okinawa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.14"
end
23 changes: 23 additions & 0 deletions test/faker/okinawa/address_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'test_helper'

class AddressTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Address
end

def test_city
assert word?(@tester.city)
end

def test_district
assert word?(@tester.district)
end

def test_island
assert word?(@tester.island)
end

def test_park
assert word?(@tester.park)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/awamori_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class AwamoriTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Awamori
end

def test_name
assert word?(@tester.name)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/base_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class BaseTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Base
end

def test_name
assert word?(@tester.name)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/fish_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class FishTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Fish
end

def test_name
assert word?(@tester.name)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/food_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class FoodTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Food
end

def test_name
assert word?(@tester.name)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/name_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class NameTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::Name
end

def test_last_name
assert word?(@tester.last_name)
end
end
77 changes: 77 additions & 0 deletions test/faker/okinawa/odic_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# coding: utf-8
require 'test_helper'

class OdicTest < Faker::Okinawa::TestCase

def test_normal
odic = Faker::Okinawa::Odic.new(dic_path("normal_entries.dic"))

assert_equal Faker::Okinawa::Odic::Entry.new("まちかじ", "松風", "普通名詞", "菓子"),
odic.entries[0]
end

def test_comment
odic = Faker::Okinawa::Odic.new(dic_path("comment.dic"))

# ignore comment line
assert_equal 23, File.readlines(dic_path("comment.dic"), encoding: 'utf-8').length
assert_equal 5, odic.entries.size

# tail comment
assert_equal "picked up", odic.entries[0].comment
assert !odic.entries[1].comment

# trivial comment rules
assert_equal "亜", odic.entries[2].word_class
assert_equal "コメント1", odic.entries[2].comment
assert_equal "亜#", odic.entries[3].word_class
assert !odic.entries[3].comment
assert_equal "亜#コメント3", odic.entries[4].word_class
assert !odic.entries[4].comment
end

def test_empty
odic = Faker::Okinawa::Odic.new(dic_path("empty.dic"))
assert_equal 0, odic.entries.size
end

def test_entry_from_entry_line
# match ENTRY_WITH_COMMENT_REGEXP
entry = Faker::Okinawa::Odic::Entry.from_entry_line('1 2 3 #4')
assert_equal "1", entry.phonate
assert_equal "2", entry.word
assert_equal "3", entry.word_class
assert_equal "4", entry.comment

# match ENTRY_WITHOUT_COMMENT_REGEXP
entry = Faker::Okinawa::Odic::Entry.from_entry_line('1 2 3')
assert_equal "1", entry.phonate
assert_equal "2", entry.word
assert_equal "3", entry.word_class
assert !entry.comment

# doesn't match both regex(ENTRY_WITH_COMMENT_REGEXP, ENTRY_WITHOUT_COMMENT_REGEXP)
entry = Faker::Okinawa::Odic::Entry.from_entry_line('')
assert !entry
end

def test_entry_valid?
# length(phonate: 40)
assert !Faker::Okinawa::Odic::Entry.new('あ' * 40, 'い' * 63, 'う', nil).valid?
# length(word: 64)
assert !Faker::Okinawa::Odic::Entry.new('あ' * 39, 'い' * 64, 'う', nil).valid?

# character type(:phonate)
assert !Faker::Okinawa::Odic::Entry.new('亜', 'い', 'う', nil).valid?
# character type(:word)
" \t\",#".each_char do |char|
assert !Faker::Okinawa::Odic::Entry.new('あ', char, 'う', nil).valid?
end
end

private

def dic_path(dic_name)
File.expand_path("../../fixtures/" + dic_name, __dir__)
end
end
11 changes: 11 additions & 0 deletions test/faker/okinawa/school_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class SchoolTest < Faker::Okinawa::TestCase
def setup
@tester = Faker::Okinawa::School
end

def test_name
assert word?(@tester.name)
end
end
7 changes: 7 additions & 0 deletions test/faker/okinawa_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class FakerOkinawaTest < Faker::Okinawa::TestCase
def test_that_it_has_a_version_number
refute_nil Faker::Okinawa::VERSION
end
end
23 changes: 23 additions & 0 deletions test/fixtures/comment.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This sample dic file describes a blank line, a comment line and a tail
# comment
#
# A blank line is below. ... very void. :-)

# A comment line is me. It starts '#' or space.
So I am a comment line too.
# These blank and comment lines are ignored.

# A tail comment is below. You can write a comment at tail of entry. a tail
# comment starts with/without '#'. The former is picked up. The latter is
# ignored.
あ ア 亜 # picked up
あ ア 亜 ignored

### Trivial rules for a tail comment. It depend on spaces around '#'.

# valid entry: word_class: "亜", comment: "コメント1"
あ ア 亜 #コメント1
# valid entry: word_class: "亜#", comment: nil
あ ア 亜# コメント2
# valid entry: word_class: "亜#コメント3", comment: nil
あ ア 亜#コメント3
Empty file added test/fixtures/empty.dic
Empty file.
2 changes: 2 additions & 0 deletions test/fixtures/normal_entries.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#phonate word word_class comment
まちかじ 松風 普通名詞 # 菓子
13 changes: 13 additions & 0 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# coding: utf-8
require "test_helper"

class HelperTest < Faker::Okinawa::TestCase
def test_word?
assert word?("English")
assert word?("日本語")

assert !word?(""), "should at least one character"
assert !word?("Boy meets girl"), "should not contain any spaces"
assert !word?(" "), "should not spaces"
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "faker/okinawa"
require "minitest/autorun"

class Faker::Okinawa::TestCase < MiniTest::Test
def word?(str)
str.class == String && str.match(/^[^ \t\n]+$/)
end
end