-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from lucasmenezesds/grammar-unit-tests
Moved Grammar unit tests
- Loading branch information
Showing
4 changed files
with
87 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
RSpec.describe Lrama::Grammar::Code do | ||
let(:token_class) { Lrama::Lexer::Token } | ||
let(:user_code_token) { token_class.new(type: T::User_code, s_value: "{ code 1 }") } | ||
let(:initial_act_token) { token_class.new(type: T::P_initial_action, s_value: "%initial-action") } | ||
|
||
describe "#translated_code" do | ||
context "when the code type is :user_code" do | ||
it "calls #translated_user_code" do | ||
code = described_class.new(type: :user_code, token_code: user_code_token) | ||
|
||
expect(code).to receive(:translated_user_code) | ||
|
||
code.translated_code | ||
end | ||
end | ||
|
||
context "when the code type is :initial_action" do | ||
it "calls #translated_initial_action_code" do | ||
code = described_class.new(type: :initial_action, token_code: initial_act_token) | ||
|
||
expect(code).to receive(:translated_initial_action_code) | ||
|
||
code.translated_code | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
RSpec.describe Lrama::Grammar::Symbol do | ||
let(:token_class) { Lrama::Lexer::Token } | ||
|
||
describe "#enum_name" do | ||
describe "symbol is accept_symbol" do | ||
it "returns 'YYSYMBOL_YYACCEPT'" do | ||
sym = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "$accept")) | ||
sym.accept_symbol = true | ||
|
||
expect(sym.enum_name).to eq("YYSYMBOL_YYACCEPT") | ||
end | ||
end | ||
|
||
describe "symbol is eof_symbol" do | ||
it "returns 'YYSYMBOL_YYEOF'" do | ||
sym = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "YYEOF"), alias_name: "\"end of file\"", token_id: 0) | ||
sym.number = 0 | ||
sym.eof_symbol = true | ||
|
||
expect(sym.enum_name).to eq("YYSYMBOL_YYEOF") | ||
end | ||
end | ||
|
||
describe "symbol's token_id is less than 128" do | ||
it "returns 'YYSYMBOL_number_[alias_name_]'" do | ||
sym1 = described_class.new(id: token_class.new(type: token_class::Char, s_value: "'\\\\'"), alias_name: "\"backslash\"", token_id: 92, number: 70, term: true) | ||
sym2 = described_class.new(id: token_class.new(type: token_class::Char, s_value: "'.'"), alias_name: nil, token_id: 46, number: 69, term: true) | ||
sym3 = described_class.new(id: token_class.new(type: token_class::Char, s_value: "'\\n'"), alias_name: nil, token_id: 10, number: 162, term: true) | ||
|
||
expect(sym1.enum_name).to eq("YYSYMBOL_70_backslash_") | ||
expect(sym2.enum_name).to eq("YYSYMBOL_69_") | ||
expect(sym3.enum_name).to eq("YYSYMBOL_162_n_") | ||
end | ||
end | ||
|
||
describe "symbol includes $ or @" do | ||
it "returns 'YYSYMBOL_number_ref" do | ||
sym1 = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "$@1"), token_id: -1, number: 165, term: false) | ||
sym2 = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "@2"), token_id: -1, number: 166, term: false) | ||
|
||
expect(sym1.enum_name).to eq("YYSYMBOL_165_1") | ||
expect(sym2.enum_name).to eq("YYSYMBOL_166_2") | ||
end | ||
end | ||
|
||
describe "symbol's token_id is greater than 127" do | ||
it "returns 'YYSYMBOL_number_ref" do | ||
sym1 = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "keyword_class"), alias_name: "\"`class'\"", token_id: 258, number: 3, term: true) | ||
sym2 = described_class.new(id: token_class.new(type: token_class::Ident, s_value: "top_compstmt"), token_id: 166, number: -1, term: false) | ||
|
||
expect(sym1.enum_name).to eq("YYSYMBOL_keyword_class") | ||
expect(sym2.enum_name).to eq("YYSYMBOL_top_compstmt") | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters