Start on test framework to compile and run generated parser

This commit is contained in:
Josh Holtrop 2021-06-26 16:17:24 -04:00
parent 93cb25df62
commit a716dedeb6
2 changed files with 36 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
/spec/reports/ /spec/reports/
/tmp/ /tmp/
/.rspec_status /.rspec_status
/spec/run/

35
spec/imbecile_spec.rb Normal file
View File

@ -0,0 +1,35 @@
require "fileutils"
def write_grammar(grammar)
File.write("spec/run/test.i", grammar)
end
def build_parser
result = system(*%w[./imbecile.sh spec/run/test.i spec/run/test.d])
expect(result).to be_truthy
end
def compile
result = system(*%w[gdc -o spec/run/test spec/run/test.d])
expect(result).to be_truthy
end
describe Imbecile do
before(:each) do
FileUtils.rm_rf("spec/run")
FileUtils.mkdir_p("spec/run")
end
it "generates a D lexer" do
write_grammar <<EOF
token int \\d+
token plus \\+
token times \\*
drop \\s+
rule Start [] <<
>>
EOF
build_parser
compile
end
end