diff --git a/README.md b/README.md index 0644bea..46fb34b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile index 43022f7..d433a1e 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/faker-okinawa.gemspec b/faker-okinawa.gemspec index b80a007..c409727 100644 --- a/faker-okinawa.gemspec +++ b/faker-okinawa.gemspec @@ -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 diff --git a/test/faker/okinawa/address_test.rb b/test/faker/okinawa/address_test.rb new file mode 100644 index 0000000..d9727f0 --- /dev/null +++ b/test/faker/okinawa/address_test.rb @@ -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 diff --git a/test/faker/okinawa/awamori_test.rb b/test/faker/okinawa/awamori_test.rb new file mode 100644 index 0000000..5d2c50b --- /dev/null +++ b/test/faker/okinawa/awamori_test.rb @@ -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 diff --git a/test/faker/okinawa/base_test.rb b/test/faker/okinawa/base_test.rb new file mode 100644 index 0000000..1b1d5aa --- /dev/null +++ b/test/faker/okinawa/base_test.rb @@ -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 diff --git a/test/faker/okinawa/fish_test.rb b/test/faker/okinawa/fish_test.rb new file mode 100644 index 0000000..75c24a5 --- /dev/null +++ b/test/faker/okinawa/fish_test.rb @@ -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 diff --git a/test/faker/okinawa/food_test.rb b/test/faker/okinawa/food_test.rb new file mode 100644 index 0000000..f8039f2 --- /dev/null +++ b/test/faker/okinawa/food_test.rb @@ -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 diff --git a/test/faker/okinawa/name_test.rb b/test/faker/okinawa/name_test.rb new file mode 100644 index 0000000..16a6a6a --- /dev/null +++ b/test/faker/okinawa/name_test.rb @@ -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 diff --git a/test/faker/okinawa/odic_test.rb b/test/faker/okinawa/odic_test.rb new file mode 100644 index 0000000..175e76e --- /dev/null +++ b/test/faker/okinawa/odic_test.rb @@ -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 diff --git a/test/faker/okinawa/school_test.rb b/test/faker/okinawa/school_test.rb new file mode 100644 index 0000000..1ccde65 --- /dev/null +++ b/test/faker/okinawa/school_test.rb @@ -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 diff --git a/test/faker/okinawa_test.rb b/test/faker/okinawa_test.rb new file mode 100644 index 0000000..f9fc968 --- /dev/null +++ b/test/faker/okinawa_test.rb @@ -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 diff --git a/test/fixtures/comment.dic b/test/fixtures/comment.dic new file mode 100644 index 0000000..12a081d --- /dev/null +++ b/test/fixtures/comment.dic @@ -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 diff --git a/test/fixtures/empty.dic b/test/fixtures/empty.dic new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/normal_entries.dic b/test/fixtures/normal_entries.dic new file mode 100644 index 0000000..681060b --- /dev/null +++ b/test/fixtures/normal_entries.dic @@ -0,0 +1,2 @@ +#phonate word word_class comment +まちかじ 松風 普通名詞 # 菓子 diff --git a/test/helper_test.rb b/test/helper_test.rb new file mode 100644 index 0000000..51a5c82 --- /dev/null +++ b/test/helper_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..a92bc55 --- /dev/null +++ b/test/test_helper.rb @@ -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