-
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.
- Loading branch information
Showing
5 changed files
with
259 additions
and
64 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
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
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
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,144 @@ | ||
RSpec.describe Lrama::Grammar::ParserState do | ||
let(:location) { Lrama::Lexer::Location.new(first_line: 1, first_column: 0, last_line: 1, last_column: 0) } | ||
let(:state_id) { Lrama::Lexer::Token::Ident.new(s_value: "in_rescue", location: location) } | ||
let(:state_list) do | ||
[ | ||
Lrama::Lexer::Token::Ident.new(s_value: "before_rescue", location: location), | ||
Lrama::Lexer::Token::Ident.new(s_value: "after_rescue", location: location), | ||
Lrama::Lexer::Token::Ident.new(s_value: "after_else", location: location), | ||
Lrama::Lexer::Token::Ident.new(s_value: "after_ensure", location: location) | ||
] | ||
end | ||
let(:parser_state) { Lrama::Grammar::ParserState.new(state_id: state_id, state_list: state_list) } | ||
|
||
describe "#enum_definition" do | ||
it "returns enum definition" do | ||
expect(parser_state.enum_definition).to eq <<~ENUM | ||
enum yyparser_state_in_rescue | ||
{ | ||
before_rescue, | ||
after_rescue, | ||
after_else, | ||
after_ensure | ||
}; | ||
typedef enum yyparser_state_in_rescue yyparser_state_in_rescue_t; | ||
static const char *const yyparser_state_in_rescue_names[] = { | ||
"before_rescue", "after_rescue", "after_else", "after_ensure", YY_NULLPTR | ||
}; | ||
YY_ATTRIBUTE_UNUSED | ||
static const char * | ||
yyparser_state_in_rescue_name (yyparser_state_in_rescue_t num) | ||
{ | ||
return yyparser_state_in_rescue_names[num]; | ||
} | ||
# define YY_STATE_IN_RESCUE_NAME yyparser_state_in_rescue_name (*yyparser_state_in_rescue_p) | ||
ENUM | ||
end | ||
end | ||
|
||
describe "#states_functions" do | ||
it "returns states functions" do | ||
expect(parser_state.states_functions).to eq <<~FUNC | ||
# define YYPUSH_STATE_IN_RESCUE(value) \\ | ||
do \\ | ||
{ \\ | ||
YYDPRINTF ((stderr, "Push in_rescue\\n")); \\ | ||
*++yyparser_state_in_rescue_p = value; \\ | ||
} \\ | ||
while (0) | ||
# define YYPOP_STATE_IN_RESCUE() \\ | ||
do \\ | ||
{ \\ | ||
YYDPRINTF ((stderr, "Pop in_rescue\\n")); \\ | ||
if (yyparser_state_in_rescue_p != yyparser_state_in_rescue) \\ | ||
{ \\ | ||
yyparser_state_in_rescue_p -= 1; \\ | ||
} \\ | ||
else \\ | ||
{ \\ | ||
YYDPRINTF ((stderr, "Try to pop empty in_rescue stack\\n")); \\ | ||
} \\ | ||
} \\ | ||
while (0) | ||
# define YYSET_STATE_IN_RESCUE(value) \\ | ||
do \\ | ||
{ \\ | ||
YYDPRINTF ((stderr, "Set in_rescue\\n")); \\ | ||
*yyparser_state_in_rescue_p = value; \\ | ||
} \\ | ||
while (0) | ||
# define YY_STATE_IN_RESCUE yyparser_state_in_rescue_p | ||
FUNC | ||
end | ||
end | ||
|
||
describe "#states_stacks" do | ||
it "returns states stacks" do | ||
expect(parser_state.states_stacks).to eq <<~STACKS | ||
/* The parser state stack (yyparser_state_in_rescue): array, bottom, top. */ | ||
int yyparser_state_in_rescue_a[YYINITDEPTH]; | ||
int *yyparser_state_in_rescue = yyparser_state_in_rescue_a; | ||
int *yyparser_state_in_rescue_p = yyparser_state_in_rescue; | ||
STACKS | ||
end | ||
end | ||
|
||
describe "#state_name" do | ||
it "returns state name" do | ||
expect(parser_state.state_name).to eq "in_rescue" | ||
end | ||
end | ||
|
||
describe "#enum_name" do | ||
it "returns enum name" do | ||
expect(parser_state.enum_name).to eq "yyparser_state_in_rescue" | ||
end | ||
end | ||
|
||
describe "#enum_type" do | ||
it "returns enum type" do | ||
expect(parser_state.enum_type).to eq "yyparser_state_in_rescue_t" | ||
end | ||
end | ||
|
||
describe "#enum_body" do | ||
it "returns enum body" do | ||
expect(parser_state.enum_body).to eq <<~BODY.chomp | ||
before_rescue, | ||
after_rescue, | ||
after_else, | ||
after_ensure | ||
BODY | ||
end | ||
end | ||
|
||
describe "#int_to_name" do | ||
it "returns int to name table" do | ||
expect(parser_state.int_to_name).to eq [ | ||
"\"before_rescue\"", | ||
"\"after_rescue\"", | ||
"\"after_else\"", | ||
"\"after_ensure\"", | ||
"YY_NULLPTR" | ||
] | ||
end | ||
end | ||
|
||
describe "#enum_name_table_name" do | ||
it "returns table name" do | ||
expect(parser_state.enum_name_table_name).to eq "yyparser_state_in_rescue_names" | ||
end | ||
end | ||
|
||
describe "#stack_prefix" do | ||
it "returns prefix" do | ||
expect(parser_state.stack_prefix).to eq "yyparser_state_in_rescue" | ||
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