zenlish 0.2.06 → 0.2.07
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/.rubocop.yml +48 -275
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +1 -1
- data/lib/zenlish/feature/feature_struct_def.rb +0 -2
- data/lib/zenlish/inflect/output_expression.rb +4 -0
- data/lib/zenlish/version.rb +1 -1
- data/lib/zenlish/wclasses/irregular_verb_extension.rb +0 -1
- data/lib/zenlish.rb +3 -3
- data/spec/zenlish/feature/boolean_domain_spec.rb +14 -14
- data/spec/zenlish/feature/boolean_value_spec.rb +6 -5
- data/spec/zenlish/feature/enumeration_domain_spec.rb +16 -16
- data/spec/zenlish/feature/feature_def_spec.rb +15 -14
- data/spec/zenlish/feature/feature_spec.rb +16 -16
- data/spec/zenlish/feature/feature_struct_def_bearer_spec.rb +16 -16
- data/spec/zenlish/feature/feature_struct_def_spec.rb +23 -23
- data/spec/zenlish/feature/identifier_domain_spec.rb +12 -12
- data/spec/zenlish/feature/identifier_value_spec.rb +6 -5
- data/spec/zenlish/feature/symbol_value_spec.rb +6 -5
- data/spec/zenlish/inflect/concatenation_spec.rb +8 -8
- data/spec/zenlish/inflect/equals_literal_spec.rb +17 -16
- data/spec/zenlish/inflect/feature_heading_spec.rb +14 -13
- data/spec/zenlish/inflect/formal_argument_spec.rb +5 -5
- data/spec/zenlish/inflect/function_call_spec.rb +8 -9
- data/spec/zenlish/inflect/inflection_rule_spec.rb +20 -20
- data/spec/zenlish/inflect/inflection_table_builder_spec.rb +37 -37
- data/spec/zenlish/inflect/inflection_table_spec.rb +33 -32
- data/spec/zenlish/inflect/input_asis_spec.rb +10 -9
- data/spec/zenlish/inflect/literal_asis_spec.rb +7 -7
- data/spec/zenlish/inflect/matches_pattern_spec.rb +15 -14
- data/spec/zenlish/inflect/membership_spec.rb +16 -15
- data/spec/zenlish/inflect/method_heading_spec.rb +12 -11
- data/spec/zenlish/inflect/not_equals_literal_spec.rb +17 -16
- data/spec/zenlish/inflect/substitution_spec.rb +9 -10
- data/spec/zenlish/inflect/unconditionally_true_spec.rb +7 -5
- data/spec/zenlish/lang/dictionary_spec.rb +17 -19
- data/spec/zenlish/lang/lemmatizer_spec.rb +23 -23
- data/spec/zenlish/lang/zenlish_grammar_spec.rb +3 -3
- data/spec/zenlish/lex/empty_lexicon_factory_spec.rb +8 -8
- data/spec/zenlish/lex/lexeme_spec.rb +18 -18
- data/spec/zenlish/lex/lexical_entry_spec.rb +14 -13
- data/spec/zenlish/lex/lexicon_spec.rb +44 -43
- data/spec/zenlish/lex/literal_spec.rb +6 -6
- data/spec/zenlish/lexer/lexer_spec.rb +10 -10
- data/spec/zenlish/parser/lesson1_spec.rb +79 -79
- data/spec/zenlish/parser/lesson2_spec.rb +102 -102
- data/spec/zenlish/parser/lesson3_spec.rb +89 -89
- data/spec/zenlish/parser/zparser_spec.rb +6 -6
- data/spec/zenlish/support/var2word.rb +0 -2
- data/spec/zenlish/trie/base_trie_node_spec.rb +11 -11
- data/spec/zenlish/trie/trie_spec.rb +46 -46
- data/spec/zenlish/wclasses/common_noun_spec.rb +9 -9
- data/spec/zenlish/wclasses/demonstrative_determiner_spec.rb +11 -11
- data/spec/zenlish/wclasses/irregular_verb_can_spec.rb +10 -10
- data/spec/zenlish/wclasses/irregular_verb_extension_spec.rb +10 -10
- data/spec/zenlish/wclasses/irregular_verb_spec.rb +19 -19
- data/spec/zenlish/wclasses/lexical_verb_spec.rb +7 -7
- data/spec/zenlish/wclasses/modal_verb_can_spec.rb +9 -9
- data/spec/zenlish/wclasses/noun_spec.rb +7 -7
- data/spec/zenlish/wclasses/personal_pronoun_spec.rb +15 -15
- data/spec/zenlish/wclasses/possessive_determiner_spec.rb +15 -15
- data/spec/zenlish/wclasses/preposition_spec.rb +5 -5
- data/spec/zenlish/wclasses/proper_noun_spec.rb +3 -3
- data/spec/zenlish/wclasses/regular_verb_spec.rb +12 -12
- data/spec/zenlish/wclasses/regular_verb_want_spec.rb +7 -7
- data/spec/zenlish/wclasses/verb_spec.rb +9 -9
- data/spec/zenlish_spec.rb +1 -1
- data/zenlish.gemspec +6 -5
- metadata +32 -16
@@ -14,36 +14,36 @@ module Zenlish
|
|
14
14
|
let(:feat_def) { FeatureDef.new(a_name, a_domain) }
|
15
15
|
let(:plural_value) { a_domain.build_value(:plural) }
|
16
16
|
|
17
|
-
subject {
|
17
|
+
subject(:a_feature) { described_class.new(feat_def) }
|
18
18
|
|
19
19
|
context 'Initialization:' do
|
20
|
-
it '
|
21
|
-
expect {
|
20
|
+
it 'is initialized with one definition argument' do
|
21
|
+
expect { described_class.new(feat_def) }.not_to raise_error
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
25
|
-
expect(
|
24
|
+
it 'knows its definition' do
|
25
|
+
expect(a_feature.definition).to eq(feat_def)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
29
|
-
expect(
|
30
|
-
expect(
|
28
|
+
it "isn't bound yet to a value" do
|
29
|
+
expect(a_feature.binding).to be_nil
|
30
|
+
expect(a_feature).not_to be_bound
|
31
31
|
end
|
32
32
|
end # context
|
33
33
|
|
34
34
|
context 'Provided services:' do
|
35
|
-
it "
|
36
|
-
expect(
|
35
|
+
it "knows the definition's name" do
|
36
|
+
expect(a_feature.name).to eq(feat_def.name)
|
37
37
|
end
|
38
38
|
|
39
|
-
it '
|
40
|
-
expect(
|
39
|
+
it 'knows the domain of its values' do
|
40
|
+
expect(a_feature.domain).to eq(a_domain)
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
44
|
-
expect {
|
45
|
-
expect(
|
46
|
-
expect(
|
43
|
+
it 'accepts a value binding' do
|
44
|
+
expect { a_feature.bind_to(plural_value) }.not_to raise_error
|
45
|
+
expect(a_feature).to be_bound
|
46
|
+
expect(a_feature.binding).to eq(plural_value)
|
47
47
|
end
|
48
48
|
end # context
|
49
49
|
end # describe
|
@@ -23,32 +23,32 @@ module Zenlish
|
|
23
23
|
end # class
|
24
24
|
# rubocop: enable Lint/ConstantDefinitionInBlock
|
25
25
|
|
26
|
-
subject { Dummy.new(nil) }
|
26
|
+
subject(:bearer) { Dummy.new(nil) }
|
27
27
|
|
28
28
|
context 'Mix-in initialization' do
|
29
|
-
it '
|
29
|
+
it 'has initialized properly the injected data' do
|
30
30
|
expect { Dummy.new(nil) }.not_to raise_error
|
31
|
-
expect(
|
31
|
+
expect(bearer.struct).to be_a(FeatureStructDef)
|
32
32
|
end
|
33
33
|
|
34
|
-
it '
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
ft =
|
34
|
+
it 'has the feature definitions created' do
|
35
|
+
expect(bearer['NUMBER']).not_to be_nil
|
36
|
+
expect(bearer['NUMBER']).to be_a(FeatureDef)
|
37
|
+
ft = bearer['NUMBER']
|
38
38
|
expect(ft.domain.enum).to eq(%i[singular plural])
|
39
39
|
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
43
|
-
expect(
|
44
|
-
expect(
|
40
|
+
expect(bearer['COUNTABILITY']).to be_a(FeatureDef)
|
41
|
+
expect(bearer['COUNTABILITY'].domain).to be_a(BooleanDomain)
|
42
|
+
expect(bearer['PARADIGM']).to be_a(FeatureDef)
|
43
|
+
expect(bearer['PARADIGM'].domain).to be_a(IdentifierDomain)
|
44
|
+
expect(bearer['PARADIGM'].default).to be_a(IdentifierValue)
|
45
45
|
end
|
46
46
|
|
47
|
-
it '
|
48
|
-
|
47
|
+
it 'supports the addition of feature def' do
|
48
|
+
bearer.feature_def_dsl { feature_def 'CASE' => boolean }
|
49
49
|
|
50
|
-
expect(
|
51
|
-
expect(
|
50
|
+
expect(bearer['CASE']).to be_a(FeatureDef)
|
51
|
+
expect(bearer['CASE'].domain).to be_a(BooleanDomain)
|
52
52
|
end
|
53
53
|
end # context
|
54
54
|
end # describe
|
@@ -14,55 +14,55 @@ module Zenlish
|
|
14
14
|
let(:ft_number) { FeatureDef.new('NUMBER', enum_number) }
|
15
15
|
let(:countable_domain) { BooleanDomain.instance }
|
16
16
|
let(:ft_countability) { FeatureDef.new('COUNTABILITY', countable_domain) }
|
17
|
-
let(:sample_parent) {
|
17
|
+
let(:sample_parent) { described_class.new }
|
18
18
|
let(:case_domain) { EnumerationDomain.new(:common, :genitive) }
|
19
19
|
let(:ft_case) { FeatureDef.new('CASE', case_domain) }
|
20
20
|
|
21
|
-
subject {
|
21
|
+
subject(:struct_def) { described_class.new(sample_parent) }
|
22
22
|
|
23
23
|
context 'Initialization:' do
|
24
|
-
it '
|
25
|
-
expect {
|
24
|
+
it 'can be initialized without argument' do
|
25
|
+
expect { described_class.new }.not_to raise_error
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
29
|
-
expect {
|
28
|
+
it 'can be initialized with a parent struct' do
|
29
|
+
expect { described_class.new(sample_parent) }.not_to raise_error
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
33
|
-
expect(
|
32
|
+
it 'has an empty structure at initialization' do
|
33
|
+
expect(struct_def.struct).to be_empty
|
34
34
|
end
|
35
35
|
|
36
|
-
it '
|
37
|
-
expect(
|
38
|
-
instance =
|
36
|
+
it 'knows its parent (if any)' do
|
37
|
+
expect(struct_def.parent).to eq(sample_parent)
|
38
|
+
instance = described_class.new
|
39
39
|
expect(instance.parent).to be_nil
|
40
40
|
end
|
41
41
|
end # context
|
42
42
|
|
43
43
|
context 'Provided services:' do
|
44
|
-
it '
|
45
|
-
expect {
|
46
|
-
expect(
|
47
|
-
expect(
|
44
|
+
it 'accepts the addition of a feature definition' do
|
45
|
+
expect { struct_def.add_feature_def(ft_number) }.not_to raise_error
|
46
|
+
expect(struct_def.struct.size).to eq(1)
|
47
|
+
expect(struct_def['NUMBER']).to eq(ft_number)
|
48
48
|
|
49
|
-
expect {
|
50
|
-
expect(
|
51
|
-
expect(
|
49
|
+
expect { struct_def.add_feature_def(ft_countability) }.not_to raise_error
|
50
|
+
expect(struct_def.struct.size).to eq(2)
|
51
|
+
expect(struct_def['COUNTABILITY']).to eq(ft_countability)
|
52
52
|
end
|
53
53
|
|
54
|
-
it '
|
54
|
+
it 'inherits the feature definition of its parent' do
|
55
55
|
sample_parent.add_feature_def(ft_case)
|
56
|
-
expect(
|
56
|
+
expect(struct_def['CASE']).to eq(ft_case)
|
57
57
|
end
|
58
58
|
|
59
|
-
it "
|
59
|
+
it "is able to override parent's feature def" do
|
60
60
|
sample_parent.add_feature_def(ft_case)
|
61
61
|
|
62
62
|
other_case_domain = BooleanDomain.instance
|
63
63
|
other_ft_case = FeatureDef.new('CASE', other_case_domain)
|
64
|
-
|
65
|
-
expect(
|
64
|
+
struct_def.add_feature_def(other_ft_case)
|
65
|
+
expect(struct_def['CASE']).to eq(other_ft_case)
|
66
66
|
end
|
67
67
|
end # context
|
68
68
|
end # describe
|
@@ -5,30 +5,30 @@ require_relative '../../../lib/zenlish/feature/identifier_domain' # Load the cla
|
|
5
5
|
module Zenlish
|
6
6
|
module Feature
|
7
7
|
describe IdentifierDomain do
|
8
|
-
subject {
|
8
|
+
subject(:domain) { described_class.instance }
|
9
9
|
|
10
10
|
context 'Initialization:' do
|
11
|
-
it '
|
12
|
-
expect {
|
11
|
+
it 'is instantiated without argument' do
|
12
|
+
expect { described_class.instance }.not_to raise_error
|
13
13
|
end
|
14
14
|
end # context
|
15
15
|
|
16
16
|
context 'Provided services:' do
|
17
|
-
it '
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
17
|
+
it 'knows whether a value is in domain' do
|
18
|
+
expect(domain).to include('CommonForm')
|
19
|
+
expect(domain).not_to include('Common Form')
|
20
|
+
expect(domain).not_to include('+123')
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
24
|
-
expect(
|
25
|
-
expect(
|
23
|
+
it 'provides a factory method for identifier values' do
|
24
|
+
expect(domain.build_value('CommonForm')).to be_a(IdentifierValue)
|
25
|
+
expect(domain.build_value('Common_Form')).to be_a(IdentifierValue)
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
28
|
+
it 'complains when asked to build an invalid identifier' do
|
29
29
|
err = StandardError
|
30
30
|
err_msg = "?1234 isn't a valid identifier."
|
31
|
-
expect {
|
31
|
+
expect { domain.build_value('?1234') }.to raise_error(err, err_msg)
|
32
32
|
end
|
33
33
|
end # context
|
34
34
|
end # describe
|
@@ -7,15 +7,16 @@ module Zenlish
|
|
7
7
|
module Feature
|
8
8
|
describe IdentifierValue do
|
9
9
|
let(:its_value) { 'CommonForm' }
|
10
|
-
|
10
|
+
|
11
|
+
subject(:identifier) { described_class.new(its_value) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
14
|
+
it 'is initialized with a value argument' do
|
15
|
+
expect { described_class.new(its_value) }.not_to raise_error
|
15
16
|
end
|
16
17
|
|
17
|
-
it '
|
18
|
-
expect(
|
18
|
+
it 'knows its internal value' do
|
19
|
+
expect(identifier.val).to eq(its_value)
|
19
20
|
end
|
20
21
|
end # context
|
21
22
|
|
@@ -8,15 +8,16 @@ module Zenlish
|
|
8
8
|
module Feature
|
9
9
|
describe SymbolValue do
|
10
10
|
let(:its_value) { :plural }
|
11
|
-
|
11
|
+
|
12
|
+
subject(:symbolic) { described_class.new(its_value) }
|
12
13
|
|
13
14
|
context 'Initialization:' do
|
14
|
-
it '
|
15
|
-
expect {
|
15
|
+
it 'is initialized with a value argument' do
|
16
|
+
expect { described_class.new(its_value) }.not_to raise_error
|
16
17
|
end
|
17
18
|
|
18
|
-
it '
|
19
|
-
expect(
|
19
|
+
it 'knows its internal value' do
|
20
|
+
expect(symbolic.val).to eq(its_value)
|
20
21
|
end
|
21
22
|
end # context
|
22
23
|
|
@@ -12,27 +12,27 @@ module Zenlish
|
|
12
12
|
let(:sample_argument) { FormalArgument.new(2) }
|
13
13
|
let(:base_form) { InputAsIs.new(sample_argument) }
|
14
14
|
|
15
|
-
subject {
|
15
|
+
subject(:concatenation) { described_class.new(base_form, suffix) }
|
16
16
|
|
17
17
|
context 'Initialization:' do
|
18
|
-
it '
|
19
|
-
expect {
|
18
|
+
it 'is initialized with two arguments' do
|
19
|
+
expect { described_class.new(base_form, suffix) }.not_to raise_error
|
20
20
|
end
|
21
21
|
|
22
|
-
it '
|
23
|
-
expect(
|
24
|
-
expect(
|
22
|
+
it 'knows its arguments' do
|
23
|
+
expect(concatenation.children.first).to eq(base_form)
|
24
|
+
expect(concatenation.children.last).to eq(suffix)
|
25
25
|
end
|
26
26
|
end # context
|
27
27
|
|
28
28
|
context 'Provided services:' do
|
29
29
|
let(:sample_values) { [nil, nil, 'place', nil] }
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'concatenates children results' do
|
32
32
|
headings = double('fake-headings')
|
33
33
|
lexeme = double('fake-lexeme')
|
34
34
|
|
35
|
-
expect(
|
35
|
+
expect(concatenation.generate(headings, lexeme, sample_values)).to eq('places')
|
36
36
|
end
|
37
37
|
end # context
|
38
38
|
end # describe
|
@@ -13,44 +13,45 @@ module Zenlish
|
|
13
13
|
describe EqualsLiteral do
|
14
14
|
let(:an_argument) { FormalArgument.new(1) }
|
15
15
|
let(:feat_val) { :plural }
|
16
|
-
|
16
|
+
|
17
|
+
subject(:literal) { described_class.new(an_argument, feat_val) }
|
17
18
|
|
18
19
|
context 'Initialization:' do
|
19
|
-
it '
|
20
|
-
expect {
|
20
|
+
it 'is initialized with a formal argument and a literal' do
|
21
|
+
expect { described_class.new(an_argument, feat_val) }.not_to raise_error
|
21
22
|
end
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(
|
24
|
+
it 'knows its argument' do
|
25
|
+
expect(literal.argument).to eq(an_argument)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
28
|
+
it 'knows the literal' do
|
29
|
+
expect(literal.literal).to eq(feat_val)
|
29
30
|
end
|
30
31
|
end # context
|
31
32
|
|
32
33
|
context 'Provided services:' do
|
33
|
-
it '
|
34
|
+
it 'tests the actual argument' do
|
34
35
|
lexeme = double('dummy-lexeme')
|
35
36
|
headings = double('fake-headings')
|
36
37
|
actual_args = [nil, :plural, nil]
|
37
|
-
expect(
|
38
|
+
expect(literal).to be_success(headings, lexeme, actual_args)
|
38
39
|
actual_args[1] = :singular
|
39
|
-
expect(
|
40
|
+
expect(literal).not_to be_success(headings, lexeme, actual_args)
|
40
41
|
end
|
41
42
|
|
42
|
-
it '
|
43
|
+
it 'tests the lexeme' do
|
43
44
|
c_noun = WClasses::CommonNoun.new
|
44
45
|
entry = Lex::LexicalEntry.new('animal')
|
45
46
|
lexeme = Lex::Lexeme.new(c_noun, entry)
|
46
47
|
headings = [nil, FeatureHeading.new('NUMBER'), nil]
|
47
|
-
expect(
|
48
|
+
expect(literal).to be_success(headings, lexeme, [])
|
48
49
|
|
49
|
-
instance =
|
50
|
-
expect(instance.
|
50
|
+
instance = described_class.new(an_argument, :singular)
|
51
|
+
expect(instance).to be_success(headings, lexeme, [])
|
51
52
|
|
52
|
-
instance =
|
53
|
-
expect(instance.
|
53
|
+
instance = described_class.new(an_argument, :irregular)
|
54
|
+
expect(instance).not_to be_success(headings, lexeme, [])
|
54
55
|
end
|
55
56
|
end # context
|
56
57
|
end # describe
|
@@ -7,15 +7,16 @@ module Zenlish
|
|
7
7
|
module Inflect
|
8
8
|
describe FeatureHeading do
|
9
9
|
let(:feature_name) { 'NUMBER' }
|
10
|
-
|
10
|
+
|
11
|
+
subject(:ft_heading) { described_class.new(feature_name) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
14
|
+
it 'is initialized with a feature name' do
|
15
|
+
expect { described_class.new(feature_name) }.not_to raise_error
|
15
16
|
end
|
16
17
|
|
17
|
-
it '
|
18
|
-
expect(
|
18
|
+
it 'knows its label' do
|
19
|
+
expect(ft_heading.label).to eq(feature_name)
|
19
20
|
end
|
20
21
|
end # context
|
21
22
|
|
@@ -25,24 +26,24 @@ module Zenlish
|
|
25
26
|
let(:b_domain) { Feature::BooleanDomain.instance }
|
26
27
|
let(:bool_def) { Feature::FeatureDef.new(feature_name, b_domain) }
|
27
28
|
|
28
|
-
it '
|
29
|
+
it 'obtains the value of a feature' do
|
29
30
|
mocked = { 'NUMBER' => :plural }
|
30
|
-
expect(
|
31
|
+
expect(ft_heading.evaluate_for(mocked)).to eq(:plural)
|
31
32
|
end
|
32
33
|
|
33
|
-
it '
|
34
|
+
it 'obtains all possible values of a feature' do
|
34
35
|
mocked = { 'NUMBER' => :plural }
|
35
|
-
expect(
|
36
|
+
expect(ft_heading.all_matches(mocked)).to eq([:plural])
|
36
37
|
end
|
37
38
|
|
38
|
-
it '
|
39
|
+
it 'obtains all possible values of a enumeration domain' do
|
39
40
|
mocked = { 'NUMBER' => enum_def }
|
40
|
-
expect(
|
41
|
+
expect(ft_heading.all_matches(mocked)).to eq(%i[singular plural])
|
41
42
|
end
|
42
43
|
|
43
|
-
it '
|
44
|
+
it 'obtains all possible values of a enumeration domain' do
|
44
45
|
mocked = { 'NUMBER' => bool_def }
|
45
|
-
expect(
|
46
|
+
expect(ft_heading.all_matches(mocked)).to eq([false, true])
|
46
47
|
end
|
47
48
|
end # context
|
48
49
|
end # describe
|
@@ -6,15 +6,15 @@ require_relative '../../../lib/zenlish/inflect/formal_argument'
|
|
6
6
|
module Zenlish
|
7
7
|
module Inflect
|
8
8
|
describe FormalArgument do
|
9
|
-
subject {
|
9
|
+
subject(:arg) { described_class.new(3) }
|
10
10
|
|
11
11
|
context 'Initialization:' do
|
12
|
-
it '
|
13
|
-
expect {
|
12
|
+
it 'is initialized with a text literal' do
|
13
|
+
expect { described_class.new(1) }.not_to raise_error
|
14
14
|
end
|
15
15
|
|
16
|
-
it '
|
17
|
-
expect(
|
16
|
+
it 'knows its index value' do
|
17
|
+
expect(arg.index).to eq(3)
|
18
18
|
end
|
19
19
|
end # context
|
20
20
|
|
@@ -1,30 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ostruct'
|
4
3
|
# Load the class under test
|
5
4
|
require_relative '../../../lib/zenlish/inflect/function_call'
|
6
5
|
|
7
6
|
module Zenlish
|
8
7
|
module Inflect
|
9
8
|
describe FunctionCall do
|
10
|
-
subject {
|
9
|
+
subject(:func_call) { described_class.new('greet') }
|
11
10
|
|
12
11
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
12
|
+
it 'is initialized with a text literal' do
|
13
|
+
expect { described_class.new('greet') }.not_to raise_error
|
15
14
|
end
|
16
15
|
|
17
|
-
it '
|
18
|
-
expect(
|
16
|
+
it 'knows its method name' do
|
17
|
+
expect(func_call.mth_name).to eq('greet')
|
19
18
|
end
|
20
19
|
end # context
|
21
20
|
|
22
21
|
context 'Provided services:' do
|
23
|
-
it '
|
22
|
+
it 'returns the affix during word form generation' do
|
24
23
|
headings = double('fake-headings')
|
25
|
-
lexeme =
|
24
|
+
lexeme = double('fake-lexeme', greet: 'Hello, world')
|
26
25
|
values = double('fake-values')
|
27
|
-
expect(
|
26
|
+
expect(func_call.generate(headings, lexeme, values)).to eq('Hello, world')
|
28
27
|
end
|
29
28
|
end # context
|
30
29
|
end # describe
|
@@ -44,21 +44,21 @@ module Zenlish
|
|
44
44
|
let(:pattern) { /y$/ }
|
45
45
|
let(:consequent) { Substitution.new(base, pattern, suffix) }
|
46
46
|
|
47
|
-
subject {
|
47
|
+
subject(:i_rule) { described_class.new(conditions, consequent) }
|
48
48
|
|
49
49
|
context 'Initialization:' do
|
50
|
-
it '
|
50
|
+
it 'is initialized with condition and consequent parts' do
|
51
51
|
expect do
|
52
|
-
|
52
|
+
described_class.new(conditions, consequent)
|
53
53
|
end.not_to raise_error
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
57
|
-
expect(
|
56
|
+
it 'knows its condition part' do
|
57
|
+
expect(i_rule.conditions).to eq(conditions)
|
58
58
|
end
|
59
59
|
|
60
|
-
it '
|
61
|
-
expect(
|
60
|
+
it 'knows its consequent part' do
|
61
|
+
expect(i_rule.consequent).to eq(consequent)
|
62
62
|
end
|
63
63
|
end # context
|
64
64
|
|
@@ -68,36 +68,36 @@ module Zenlish
|
|
68
68
|
let(:an_entry) { Lex::LexicalEntry.new('cherry') }
|
69
69
|
let(:lexeme) { Lex::Lexeme.new(c_noun, an_entry) }
|
70
70
|
|
71
|
-
it '
|
71
|
+
it 'succeeds when all conditions succeed with actuals' do
|
72
72
|
actuals = [:plural, 'cherry']
|
73
|
-
expect(
|
73
|
+
expect(i_rule).to be_success(headings, fake_lexeme, actuals)
|
74
74
|
end
|
75
75
|
|
76
|
-
it '
|
76
|
+
it 'fails when one condition fails with actuals' do
|
77
77
|
actuals = [:singular, 'cherry']
|
78
|
-
expect(
|
78
|
+
expect(i_rule).not_to be_success(headings, fake_lexeme, actuals)
|
79
79
|
|
80
80
|
actuals = [:plural, 'girl']
|
81
|
-
expect(
|
81
|
+
expect(i_rule).not_to be_success(headings, fake_lexeme, actuals)
|
82
82
|
end
|
83
83
|
|
84
|
-
it '
|
84
|
+
it 'generates inflected form when rule iworks for actuals' do
|
85
85
|
actuals = [:plural, 'cherry']
|
86
|
-
expect(
|
86
|
+
expect(i_rule.apply(headings, fake_lexeme, actuals)).to eq('cherries')
|
87
87
|
end
|
88
88
|
|
89
|
-
it '
|
90
|
-
expect(
|
89
|
+
it 'succeeds when all conditions succeed for given lexeme' do
|
90
|
+
expect(i_rule).to be_success(headings, lexeme, [])
|
91
91
|
end
|
92
92
|
|
93
|
-
it '
|
93
|
+
it 'fails when one condition fails with given lexeme' do
|
94
94
|
entry_2 = Lex::LexicalEntry.new('animal')
|
95
95
|
lex_m2 = Lex::Lexeme.new(c_noun, entry_2)
|
96
|
-
expect(
|
96
|
+
expect(i_rule).not_to be_success(headings, lex_m2, [])
|
97
97
|
end
|
98
98
|
|
99
|
-
it '
|
100
|
-
expect(
|
99
|
+
it 'generates inflected form when rule works for given lexeme' do
|
100
|
+
expect(i_rule.apply(headings, lexeme, [])).to eq('cherries')
|
101
101
|
end
|
102
102
|
end # context
|
103
103
|
end # describe
|