Skip to content

Commit

Permalink
Change @define from hash to array and add tests for define option han…
Browse files Browse the repository at this point in the history
…dling

`@options.define` is expect to Array so default value is also Array not Hash.
  • Loading branch information
ydah committed Feb 4, 2025
1 parent 7fa74d8 commit ce4e0fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lrama/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Options

def initialize
@skeleton = "bison/yacc.c"
@define = {}
@define = []
@header = false
@header_file = nil
@report_file = nil
Expand Down
20 changes: 20 additions & 0 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,24 @@
end
end
end

describe "@define" do
context "when define option is not passed" do
it "returns empty array" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, [fixture_path("command/basic.y")])
options = option_parser.instance_variable_get(:@options)
expect(options.define).to eq([])
end
end

context "when define option is passed" do
it "returns array of define options" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["--define=YYDEBUG=1", fixture_path("command/basic.y")])
options = option_parser.instance_variable_get(:@options)
expect(options.define).to eq(["YYDEBUG=1"])
end
end
end
end

0 comments on commit ce4e0fc

Please sign in to comment.