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
@@ -7,7 +7,7 @@ require_relative '../../../lib/zenlish/lang/dictionary' # Load the class under t
|
|
7
7
|
module Zenlish
|
8
8
|
module Lang
|
9
9
|
describe Dictionary do
|
10
|
-
subject {
|
10
|
+
subject(:dictionary) { described_class }
|
11
11
|
|
12
12
|
context 'Provided services:' do
|
13
13
|
let(:common_nouns) do
|
@@ -15,18 +15,6 @@ module Zenlish
|
|
15
15
|
%w(animal body container here kind machine moment now part people
|
16
16
|
person place side surface thing time word)
|
17
17
|
end
|
18
|
-
|
19
|
-
it 'should give the list of common nouns' do
|
20
|
-
lexemes = []
|
21
|
-
subject.entries.each do |ent|
|
22
|
-
lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
|
23
|
-
lexemes.concat(lexm) if lexm
|
24
|
-
end
|
25
|
-
lemmas = lexemes.map { |lx| lx.entry.lemma }
|
26
|
-
|
27
|
-
expect(common_nouns.all? { |c_n| lemmas.include?(c_n) }).to be_truthy
|
28
|
-
end
|
29
|
-
|
30
18
|
let(:present_1sg) { [:first, :singular, :present, nil] }
|
31
19
|
let(:present_2sg) { [:second, :singular, :present, nil] }
|
32
20
|
let(:present_3sg) { [:third, :singular, :present, nil] }
|
@@ -45,8 +33,18 @@ module Zenlish
|
|
45
33
|
end
|
46
34
|
end
|
47
35
|
|
48
|
-
it '
|
49
|
-
|
36
|
+
it 'gives the list of common nouns' do
|
37
|
+
lexemes = []
|
38
|
+
dictionary.entries.each do |ent|
|
39
|
+
lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
|
40
|
+
lexemes.concat(lexm) if lexm
|
41
|
+
end
|
42
|
+
lemmas = lexemes.map { |lx| lx.entry.lemma }
|
43
|
+
expect(common_nouns.all? { |c_n| lemmas.include?(c_n) }).to be_truthy
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'knows how to inflect an (irregular) verb' do
|
47
|
+
lexm = dictionary.get_lexeme('become')
|
50
48
|
expectations1 = [
|
51
49
|
[present_1sg, 'become'],
|
52
50
|
[present_3sg, 'becomes'],
|
@@ -57,7 +55,7 @@ module Zenlish
|
|
57
55
|
]
|
58
56
|
test_inflection_of(lexm, expectations1)
|
59
57
|
|
60
|
-
lexm =
|
58
|
+
lexm = dictionary.get_lexeme('do', WClasses::IrregularVerbDo)
|
61
59
|
expectations2 = [
|
62
60
|
[present_1sg, 'do'],
|
63
61
|
[present_3sg, 'does'],
|
@@ -68,7 +66,7 @@ module Zenlish
|
|
68
66
|
]
|
69
67
|
test_inflection_of(lexm, expectations2, true)
|
70
68
|
|
71
|
-
lexm =
|
69
|
+
lexm = dictionary.get_lexeme('have', WClasses::IrregularVerbHave)
|
72
70
|
expectations3 = [
|
73
71
|
[present_1sg, 'have'],
|
74
72
|
[present_3sg, 'has'],
|
@@ -80,9 +78,9 @@ module Zenlish
|
|
80
78
|
test_inflection_of(lexm, expectations3, true)
|
81
79
|
end
|
82
80
|
|
83
|
-
it '
|
81
|
+
it 'knows how to inflect the verb be' do
|
84
82
|
[WClasses::IrregularVerbBe, WClasses::AuxiliaryBe].each do |wclass|
|
85
|
-
lexm =
|
83
|
+
lexm = dictionary.get_lexeme('be', wclass)
|
86
84
|
expectations1 = [
|
87
85
|
[present_1sg, 'am'],
|
88
86
|
[present_2sg, 'are'],
|
@@ -9,34 +9,34 @@ require_relative '../../../lib/zenlish/lang/lemmatizer'
|
|
9
9
|
module Zenlish
|
10
10
|
module Lang
|
11
11
|
describe Lemmatizer do
|
12
|
-
subject {
|
12
|
+
subject { described_class.new(Dictionary) }
|
13
13
|
|
14
14
|
context 'Initialization:' do
|
15
|
-
it '
|
16
|
-
|
17
|
-
end
|
15
|
+
# it 'is initialized with a lexicon argument' do
|
16
|
+
# expect { described_class.new(Dictionary) }.not_to raise_error
|
17
|
+
# end
|
18
18
|
end # context
|
19
19
|
|
20
20
|
context 'Provided services:' do
|
21
|
-
it '
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
21
|
+
# it 'retrieves an unambiguous word form' do
|
22
|
+
# # Coordinator
|
23
|
+
# found = described_class.lemmatize('and')
|
24
|
+
# expect(found).to be_a(Lex::Lexeme)
|
25
|
+
# expect(found.lemma).to eq('and')
|
26
|
+
# expect(found.wclass).to be_a(WClasses::Coordinator)
|
27
|
+
#
|
28
|
+
# # Common noun
|
29
|
+
# found = described_class.lemmatize('surfaces')
|
30
|
+
# expect(found).to be_a(Lex::Lexeme)
|
31
|
+
# expect(found.lemma).to eq('surface')
|
32
|
+
# expect(found.wclass).to be_a(WClasses::CommonNoun)
|
33
|
+
#
|
34
|
+
# # Verb
|
35
|
+
# found = described_class.lemmatize('seeing')
|
36
|
+
# expect(found).to be_a(Lex::Lexeme)
|
37
|
+
# expect(found.lemma).to eq('see')
|
38
|
+
# expect(found.wclass).to be_a(WClasses::IrregularVerb)
|
39
|
+
# end
|
40
40
|
end # context
|
41
41
|
end # describe
|
42
42
|
end # module
|
@@ -6,11 +6,11 @@ require_relative '../../../lib/zenlish/lang/zenlish_grammar' # Load the class un
|
|
6
6
|
module Zenlish
|
7
7
|
module Lang
|
8
8
|
describe ZenlishGrammar do
|
9
|
-
subject {
|
9
|
+
subject(:grammar) { described_class }
|
10
10
|
|
11
11
|
context 'Initialization:' do
|
12
|
-
it '
|
13
|
-
expect {
|
12
|
+
it 'knows its terminal symbols' do
|
13
|
+
expect { grammar.name2symbol['CommonNoun'] }.not_to raise_error
|
14
14
|
end
|
15
15
|
end # context
|
16
16
|
|
@@ -8,24 +8,24 @@ require_relative '../../../lib/zenlish/lex/empty_lexicon_factory'
|
|
8
8
|
module Zenlish
|
9
9
|
module Lex
|
10
10
|
describe EmptyLexiconFactory do
|
11
|
-
subject do
|
11
|
+
subject(:factory) do
|
12
12
|
obj = Object.new
|
13
|
-
obj.extend(
|
13
|
+
obj.extend(described_class)
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'Mix-in integration:' do
|
17
|
-
it '
|
18
|
-
expect(
|
17
|
+
it 'acquires the methods of the mix-in module' do
|
18
|
+
expect(factory).to respond_to(:create_empty_lexicon)
|
19
19
|
end
|
20
20
|
end # context
|
21
21
|
|
22
22
|
context 'Created lexicon:' do
|
23
|
-
it '
|
24
|
-
expect(
|
23
|
+
it 'allows the creation of empty lexicon' do
|
24
|
+
expect(factory.create_empty_lexicon).to be_a(Lexicon)
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
28
|
-
lexicon =
|
27
|
+
it 'initializes lexicon with terminal symbols of the language' do
|
28
|
+
lexicon = factory.create_empty_lexicon
|
29
29
|
found = lexicon.terminals.find { |symb| symb.kind_of?(WClasses::CommonNoun) }
|
30
30
|
expect(found).to be_truthy
|
31
31
|
end
|
@@ -19,43 +19,43 @@ module Zenlish
|
|
19
19
|
'PARADIGM' => [identifier, 'Plural_only'] }
|
20
20
|
end
|
21
21
|
|
22
|
-
subject {
|
22
|
+
subject(:a_lexeme) { described_class.new(a_wclass, an_entry) }
|
23
23
|
|
24
24
|
context 'Initialization:' do
|
25
|
-
it '
|
26
|
-
expect {
|
25
|
+
it 'can be initialized with a word class and a lexical entry' do
|
26
|
+
expect { described_class.new(a_wclass, an_entry) }.not_to raise_error
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
30
|
-
expect {
|
29
|
+
it 'can be initialized with a w. class, lexical ent., feature hash' do
|
30
|
+
expect { described_class.new(a_wclass, an_entry, a_feat_struct_def) }.not_to raise_error
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
34
|
-
expect(
|
33
|
+
it 'knows its word class' do
|
34
|
+
expect(a_lexeme.wclass).to eq(a_wclass)
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
38
|
-
expect(
|
37
|
+
it 'knows its lexical entry' do
|
38
|
+
expect(a_lexeme.entry).to eq(an_entry)
|
39
39
|
end
|
40
40
|
end # context
|
41
41
|
|
42
42
|
context 'Provided services:' do
|
43
|
-
subject {
|
44
|
-
it '
|
45
|
-
expect(
|
43
|
+
subject(:a_lexeme) { described_class.new(a_wclass, an_entry, a_feat_struct_def) }
|
44
|
+
it 'knows its lemma' do
|
45
|
+
expect(a_lexeme.lemma).to eq(a_lemma)
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
49
|
-
instance =
|
48
|
+
it 'knows its own feature defs' do
|
49
|
+
instance = described_class.new(a_wclass, an_entry, a_feat_struct_def)
|
50
50
|
expect(instance['NUMBER'].default.val).to eq(:plural)
|
51
51
|
end
|
52
52
|
|
53
|
-
it '
|
54
|
-
expect(
|
53
|
+
it 'knows its inflection paradigm' do
|
54
|
+
expect(a_lexeme.paradigm).to be_a(Inflect::InflectionTable)
|
55
55
|
end
|
56
56
|
|
57
|
-
it '
|
58
|
-
expect(
|
57
|
+
it 'knows all its inflections' do
|
58
|
+
expect(a_lexeme.all_inflections).to eq(['people'])
|
59
59
|
end
|
60
60
|
end # context
|
61
61
|
end # describe
|
@@ -9,35 +9,36 @@ module Zenlish
|
|
9
9
|
let(:sample_lemma) { 'other' }
|
10
10
|
let(:sample_lexeme1) { double('other-as-adjective') }
|
11
11
|
let(:sample_lexeme2) { double('other-as-pronoun') }
|
12
|
-
|
12
|
+
|
13
|
+
subject(:lex_entry) { described_class.new(sample_lemma) }
|
13
14
|
|
14
15
|
context 'Initialization:' do
|
15
16
|
it 'can be initialized with a lemma only' do
|
16
|
-
expect {
|
17
|
+
expect { described_class.new(sample_lemma) }.not_to raise_error
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'can be initialized with a lemma and a word class' do
|
20
|
-
expect {
|
21
|
+
expect { described_class.new(sample_lemma, sample_lexeme1) }.not_to raise_error
|
21
22
|
end
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(
|
24
|
+
it 'knows its lemma' do
|
25
|
+
expect(lex_entry.lemma).to eq(sample_lemma)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
29
|
-
instance =
|
28
|
+
it 'knows its lexeme (if any)' do
|
29
|
+
expect(lex_entry.lexemes).to be_empty
|
30
|
+
instance = described_class.new(sample_lemma, sample_lexeme1)
|
30
31
|
expect(instance.lexemes).to eq([sample_lexeme1])
|
31
32
|
end
|
32
33
|
end # context
|
33
34
|
|
34
35
|
context 'Provided services:' do
|
35
|
-
it '
|
36
|
-
|
37
|
-
expect(
|
36
|
+
it 'accepts links with lexeme(s)' do
|
37
|
+
lex_entry.add_lexeme(sample_lexeme1)
|
38
|
+
expect(lex_entry.lexemes).to eq([sample_lexeme1])
|
38
39
|
|
39
|
-
|
40
|
-
expect(
|
40
|
+
lex_entry.add_lexeme(sample_lexeme2)
|
41
|
+
expect(lex_entry.lexemes).to eq([sample_lexeme1, sample_lexeme2])
|
41
42
|
end
|
42
43
|
end # context
|
43
44
|
end # describe
|
@@ -24,78 +24,79 @@ module Zenlish
|
|
24
24
|
let(:sample_entry) { create_entry('other', adjective) }
|
25
25
|
let(:similar_entry) { create_entry('other', pronoun) }
|
26
26
|
let(:distinct_entry) { create_entry('hope', irregular_verb) }
|
27
|
-
|
27
|
+
|
28
|
+
subject(:lexicon) { described_class.new }
|
28
29
|
|
29
30
|
context 'Initialization:' do
|
30
|
-
it '
|
31
|
-
expect {
|
31
|
+
it 'is initialized without parameter' do
|
32
|
+
expect { described_class.new }.not_to raise_error
|
32
33
|
end
|
33
34
|
|
34
|
-
it '
|
35
|
-
expect(
|
35
|
+
it 'has no registered terminals at initialization' do
|
36
|
+
expect(lexicon.terminals).to be_empty
|
36
37
|
end
|
37
38
|
|
38
|
-
it '
|
39
|
-
expect(
|
40
|
-
expect(
|
39
|
+
it 'has no entry at initialization' do
|
40
|
+
expect(lexicon.entries).to be_empty
|
41
|
+
expect(lexicon.lemma2entry).to be_empty
|
41
42
|
end
|
42
43
|
end # context
|
43
44
|
|
44
45
|
context 'Provided services:' do
|
45
|
-
it '
|
46
|
+
it 'accepts the addition of terminals' do
|
46
47
|
terminal1 = pronoun
|
47
48
|
terminal2 = irregular_verb
|
48
49
|
terminal3 = adjective
|
49
50
|
|
50
|
-
|
51
|
-
expect(
|
52
|
-
|
53
|
-
expect(
|
54
|
-
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
expect(
|
51
|
+
lexicon.add_terminal(terminal1)
|
52
|
+
expect(lexicon.terminals).to eq([terminal1])
|
53
|
+
lexicon.add_terminal(terminal2)
|
54
|
+
expect(lexicon.terminals).to eq([terminal1, terminal2])
|
55
|
+
lexicon.add_terminal(terminal3)
|
56
|
+
expect(lexicon.terminals).to eq([terminal1, terminal2, terminal3])
|
57
|
+
expect(lexicon.name2terminal['Pronoun']).to eq(terminal1)
|
58
|
+
expect(lexicon.name2terminal['IrregularVerb']).to eq(terminal2)
|
59
|
+
expect(lexicon.name2terminal['Adjective']).to eq(terminal3)
|
59
60
|
end
|
60
61
|
|
61
|
-
it '
|
62
|
-
|
63
|
-
expect(
|
64
|
-
expect(
|
62
|
+
it 'accepts the addition of entries' do
|
63
|
+
lexicon.add_entry(sample_entry)
|
64
|
+
expect(lexicon.entries).to eq([sample_entry])
|
65
|
+
expect(lexicon.lemma2entry['other']).to eq(sample_entry)
|
65
66
|
|
66
67
|
# Add dissimilar entry
|
67
|
-
|
68
|
-
expect(
|
69
|
-
expect(
|
68
|
+
lexicon.add_entry(distinct_entry)
|
69
|
+
expect(lexicon.entries).to eq([sample_entry, distinct_entry])
|
70
|
+
expect(lexicon.lemma2entry['hope']).to eq(distinct_entry)
|
70
71
|
|
71
72
|
# Add "homonym" entry
|
72
|
-
|
73
|
-
expect(
|
74
|
-
expect(
|
73
|
+
lexicon.add_entry(similar_entry)
|
74
|
+
expect(lexicon.entries).to eq([sample_entry, distinct_entry, similar_entry])
|
75
|
+
expect(lexicon.lemma2entry['other']).to eq([sample_entry, similar_entry])
|
75
76
|
end
|
76
77
|
|
77
|
-
it '
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
it 'retrieves the lexeme of an entry with unique lemma' do
|
79
|
+
lexicon.add_entry(sample_entry)
|
80
|
+
lexicon.add_entry(distinct_entry)
|
81
|
+
lexicon.add_entry(similar_entry)
|
81
82
|
|
82
|
-
lexeme =
|
83
|
-
expect(lexeme.wclass).to
|
83
|
+
lexeme = lexicon.get_lexeme('hope')
|
84
|
+
expect(lexeme.wclass).to be_a(Zenlish::WClasses::IrregularVerb)
|
84
85
|
end
|
85
86
|
|
86
|
-
it '
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
it 'retrieves the lexeme of an entry with duplicate lemma' do
|
88
|
+
lexicon.add_entry(sample_entry)
|
89
|
+
lexicon.add_entry(distinct_entry)
|
90
|
+
lexicon.add_entry(similar_entry)
|
90
91
|
|
91
|
-
lexeme =
|
92
|
-
expect(lexeme).to
|
92
|
+
lexeme = lexicon.get_lexeme('other', Zenlish::WClasses::Pronoun)
|
93
|
+
expect(lexeme).to be_a(Zenlish::Lex::Lexeme)
|
93
94
|
end
|
94
95
|
|
95
|
-
it '
|
96
|
-
|
96
|
+
it 'complains when retrieving an non-existing entry' do
|
97
|
+
lexicon.add_entry(sample_entry)
|
97
98
|
err_msg = 'key not found: "hapax"'
|
98
|
-
expect {
|
99
|
+
expect { lexicon.get_lexeme('hapax') }.to raise_error(KeyError, err_msg)
|
99
100
|
end
|
100
101
|
end # context
|
101
102
|
end # describe
|
@@ -12,20 +12,20 @@ module Zenlish
|
|
12
12
|
let(:sample_wclass) { WClasses::CommonNoun.new }
|
13
13
|
let(:sample_lemma) { 'thing' }
|
14
14
|
let(:sample_entry) { LexicalEntry.new(sample_lemma) }
|
15
|
-
let(:sample_position) {
|
15
|
+
let(:sample_position) { instance_double(Rley::Lexical::Position) }
|
16
16
|
let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
|
17
17
|
|
18
|
-
subject {
|
18
|
+
subject(:literal) { described_class.new('things', sample_lexeme, sample_position) }
|
19
19
|
|
20
20
|
context 'Initialization:' do
|
21
|
-
it '
|
22
|
-
expect {
|
21
|
+
it 'is initialized with a string, a lexeme and a position' do
|
22
|
+
expect { described_class.new('things', sample_lexeme, sample_position) }.not_to raise_error
|
23
23
|
end
|
24
24
|
end # context
|
25
25
|
|
26
26
|
context 'Provided services:' do
|
27
|
-
it '
|
28
|
-
expect(
|
27
|
+
it 'knows its lexeme' do
|
28
|
+
expect(literal.zlexeme).to eq(sample_lexeme)
|
29
29
|
end
|
30
30
|
end # context
|
31
31
|
end # describe
|
@@ -18,26 +18,26 @@ module Zenlish
|
|
18
18
|
# let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
|
19
19
|
let(:sample_sentence) { 'Tony sees Lisa.' }
|
20
20
|
|
21
|
-
subject {
|
21
|
+
subject(:lexer) { described_class.new(sample_sentence) }
|
22
22
|
|
23
23
|
context 'Initialization:' do
|
24
|
-
it '
|
25
|
-
expect {
|
24
|
+
it 'is initialized with Zenlish text' do
|
25
|
+
expect { described_class.new(sample_sentence) }.not_to raise_error
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
29
|
-
expect(
|
28
|
+
it 'knows its scanner object' do
|
29
|
+
expect(lexer.scanner).not_to be_nil
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
33
|
-
expect(
|
34
|
-
expect(
|
32
|
+
it 'has an initial position' do
|
33
|
+
expect(lexer.lineno).to eq(1)
|
34
|
+
expect(lexer.line_start).to eq(0)
|
35
35
|
end
|
36
36
|
end # context
|
37
37
|
|
38
38
|
context 'Provided services:' do
|
39
|
-
it '
|
40
|
-
tokens =
|
39
|
+
it 'returns a sequence of literals' do
|
40
|
+
tokens = lexer.tokens
|
41
41
|
expect(tokens.size).to eq(4)
|
42
42
|
expect(tokens[0].lexeme).to eq('Tony')
|
43
43
|
expect(tokens[0].terminal).to eq('WORD')
|