From 94f317673f3750d10f017630115ce6429940ee3f Mon Sep 17 00:00:00 2001 From: Roguelearg Date: Wed, 13 Sep 2017 16:51:11 +0200 Subject: [PATCH] Add a spec and some minor corrections --- Rakefile | 28 ++++++++++++------------- exe/mm2ep-depend | 10 +++++---- lib/mm2ep_depend.rb | 1 + spec/mm2ep_depend/parser_spec.rb | 20 ++++++++++++++++++ spec/mm2ep_depend_test.rb | 11 ---------- spec/{test_helper.rb => spec_helper.rb} | 5 +++++ 6 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 spec/mm2ep_depend/parser_spec.rb delete mode 100644 spec/mm2ep_depend_test.rb rename spec/{test_helper.rb => spec_helper.rb} (53%) diff --git a/Rakefile b/Rakefile index 37fe42a..c9f6049 100644 --- a/Rakefile +++ b/Rakefile @@ -1,21 +1,21 @@ require "bundler/gem_tasks" require "rake/testtask" -require 'rubocop/rake_task' +# require 'rubocop/rake_task' # Add additional test suite definitions to the default test task here -namespace :spec do - desc 'Runs RuboCop on specified directories' - RuboCop::RakeTask.new(:rubocop) do |task| - # Dirs: app, lib, test - task.patterns = ['exe/**/*.rb', 'lib/**/*.rb', 'spec/**/*_spec.rb'] - - # Make it easier to disable cops. - task.options << "--display-cop-names" - - # Abort on failures (fix your code first) - task.fail_on_error = true - end -end +# namespace :spec do +# desc 'Runs RuboCop on specified directories' +# RuboCop::RakeTask.new(:rubocop) do |task| +# # Dirs: app, lib, test +# task.patterns = ['exe/**/*.rb', 'lib/**/*.rb', 'spec/**/*_spec.rb'] +# +# # Make it easier to disable cops. +# task.options << "--display-cop-names" +# +# # Abort on failures (fix your code first) +# task.fail_on_error = true +# end +# end Rake::TestTask.new(:spec) do |t| t.libs << "spec" diff --git a/exe/mm2ep-depend b/exe/mm2ep-depend index a3fcfe5..2d1c964 100755 --- a/exe/mm2ep-depend +++ b/exe/mm2ep-depend @@ -16,12 +16,14 @@ module Mm2ep def parse(infile, *vars) line = File.read(infile).gsub(/\n/,'') parser = Parser.new(Lexer.new) - vartruc = {} + tab_vars = {} vars.each do |var| - vartruc[var.split('=')[0]] = var.split('=')[1] + tab_vars[var.split('=')[0]] = var.split('=')[1] end - puts vartruc - parser.names(vartruc) + + # Give vars name and value from shell command to parser + parser.names(tab_vars) + token = parser.parse(line.chomp, true) pp token puts "RAW : #{line}" diff --git a/lib/mm2ep_depend.rb b/lib/mm2ep_depend.rb index c8c44d6..1230d3e 100644 --- a/lib/mm2ep_depend.rb +++ b/lib/mm2ep_depend.rb @@ -5,6 +5,7 @@ module Mm2epDepend # Your code goes here... end +require 'rly' require 'mm2ep_depend/lexer' require 'mm2ep_depend/parser' diff --git a/spec/mm2ep_depend/parser_spec.rb b/spec/mm2ep_depend/parser_spec.rb new file mode 100644 index 0000000..7306b15 --- /dev/null +++ b/spec/mm2ep_depend/parser_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' +require 'mm2ep_depend' + +describe Mm2ep::Depend::Parser do + + it 'has to evaluate expression and give right answer' do + line = File.read(testfile('test2.txt')).gsub(/\n/,'') + parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new) + parser.names({'truc_bidule' => 'true', + 'machin' => 'true', + 'truc' => 'false' + }) + token = parser.parse(line.chomp) + assert_equal(false, token.compute) + end + + # it 'has to be true' do + # + # end +end diff --git a/spec/mm2ep_depend_test.rb b/spec/mm2ep_depend_test.rb deleted file mode 100644 index fd54034..0000000 --- a/spec/mm2ep_depend_test.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "test_helper" - -class Mm2epDependTest < Minitest::Test - def test_that_it_has_a_version_number - refute_nil ::Mm2epDepend::VERSION - end - - def test_it_does_something_useful - assert false - end -end diff --git a/spec/test_helper.rb b/spec/spec_helper.rb similarity index 53% rename from spec/test_helper.rb rename to spec/spec_helper.rb index a7bcb72..684975b 100644 --- a/spec/test_helper.rb +++ b/spec/spec_helper.rb @@ -2,3 +2,8 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) require "mm2ep_depend" require "minitest/autorun" +require 'pathname' + +def testfile(name) + Pathname.new(__FILE__).dirname.join('files', name) +end