Skip to content

Commit

Permalink
Add: Taiwan and Thailand to CONTINUOUS_LANGUAGES_LOCALES
Browse files Browse the repository at this point in the history
  • Loading branch information
sota-horiuchi committed Mar 26, 2024
1 parent 1516428 commit ce01093
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/ingreedy/continuous_language_locale.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Ingreedy
module ContinuousLanguageLocale
CONTINUOUS_LANGUAGES_LOCALES = [:ja].freeze
CONTINUOUS_LANGUAGES_LOCALES = %i(ja th zh-TW)

def use_whitespace?(locale)
!CONTINUOUS_LANGUAGES_LOCALES.include?(locale)
Expand Down
23 changes: 23 additions & 0 deletions spec/ingreedy/continuouse_language_locale_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'ingreedy/continuous_language_locale'

RSpec.describe Ingreedy::ContinuousLanguageLocale do
include Ingreedy::ContinuousLanguageLocale

describe '#use_whitespace?' do
context 'when the locale is a continuous language' do
it 'returns false' do
expect(use_whitespace?(:ja)).to be_falsey
expect(use_whitespace?(:th)).to be_falsey
expect(use_whitespace?(:'zh-TW')).to be_falsey
end
end

context 'when the locale is not a continuous language' do
it 'returns true' do
expect(use_whitespace?(:en)).to be_truthy
expect(use_whitespace?(:fr)).to be_truthy
expect(use_whitespace?(:'zh-CN')).to be_truthy
end
end
end
end
91 changes: 66 additions & 25 deletions spec/ingreedy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,39 +448,80 @@
end

describe Ingreedy, "continuous language" do
before(:all) do
Ingreedy.dictionaries[:ja] = {
units: { gram: ["g"] },
numbers: { "一" => 1 },
}
Ingreedy.locale = :ja
end
context "Japanese" do
before do
Ingreedy.dictionaries[:ja] = {
units: { gram: ["g"], other: ["個"] },
numbers: { "一" => 1 },
}
Ingreedy.locale = :ja
end

after(:all) do
Ingreedy.locale = nil
end
after do
Ingreedy.locale = nil
end

it "parses correctly" do
result = Ingreedy.parse "200g砂糖"
it "parses correctly" do
result = Ingreedy.parse "200g砂糖"

expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
end
expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
end

it "parses correctly with reverse format" do
result = Ingreedy.parse "砂糖200g"
it "parses correctly with reverse format" do
result = Ingreedy.parse "砂糖200g"

expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
end

it "parses correctly with numbers" do
result = Ingreedy.parse "卵一個"

expect(result.amount).to eq(1)
expect(result.unit).to eq(:other)
expect(result.ingredient).to eq("卵")
end
end

it "parses correctly with numbers" do
result = Ingreedy.parse "卵一g"
context "Taiwanese" do
before do
Ingreedy.dictionaries[:"zh-TW"] = {
units: { gram: ["g"], other: ["个"] },
numbers: { "一" => 1 },
}
Ingreedy.locale = :"zh-TW"
end

expect(result.amount).to eq(1)
expect(result.ingredient).to eq("卵")
after do
Ingreedy.locale = nil
end

it "parses correctly" do
result = Ingreedy.parse "200g砂糖"

expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
end

it "parses correctly with reverse format" do
result = Ingreedy.parse "砂糖200g"

expect(result.amount).to eq(200)
expect(result.unit).to eq(:gram)
expect(result.ingredient).to eq("砂糖")
end

it "parses correctly with numbers" do
result = Ingreedy.parse "一个鸡蛋"

expect(result.amount).to eq(1)
expect(result.unit).to eq(:other)
expect(result.ingredient).to eq("鸡蛋")
end
end
end

Expand Down

0 comments on commit ce01093

Please sign in to comment.