Skip to content

Commit

Permalink
initial tests for document with several scores and with document header
Browse files Browse the repository at this point in the history
  • Loading branch information
igneus committed Dec 10, 2015
1 parent e649513 commit 3e3440d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
32 changes: 13 additions & 19 deletions tests/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

require_relative 'test_helper'

def gly_process(s)
# for now do nothing
parsed = Gly::Parser.new.parse(s).first
Gly::GabcConvertor.new.convert(parsed)
end

def create_gly_test_case(given_file, expected_file)
# filename without extension
case_name = File.basename(given_file).sub(/\.[^\.]*\Z/, '')
# Each test case is defined by a pair of files
# in directories examples/given and examples/expected
# which define what is an expected gabc result of a single-score
# gly file.
class TestExamples < GlyTest
def self.example_test_case(given_file, expected_file)
# filename without extension
case_name = File.basename(given_file).sub(/\.[^\.]*\Z/, '')

test_case = Class.new(MiniTest::Test) do |klass|
define_method "test_#{case_name}" do
expected = File.read expected_file
File.open given_file do |fr|
Expand All @@ -21,13 +19,9 @@ def create_gly_test_case(given_file, expected_file)
end
end

# make CamelCase
class_name = case_name.gsub(/(^|_)(\w)/) {|m| m[-1].upcase }
Object.const_set class_name, test_case
end

here = File.dirname __FILE__
Dir.glob(File.join(here, 'examples/gly/**/*.gly')).each do |given|
expected = given.sub('/given', '/expected').sub('.gly', '.gabc')
create_gly_test_case given, expected
here = File.dirname __FILE__
Dir.glob(File.join(here, 'examples/gly/given/*.gly')).each do |given|
expected = given.sub('/given', '/expected').sub('.gly', '.gabc')
example_test_case given, expected
end
end
9 changes: 9 additions & 0 deletions tests/examples/gly/no_crash/document_header.gly
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\header
title: Testing document with document header
author: the author of gly

\score
mode: 8
description: Basic alleluia
c4 g gh g g
A -- lle -- lu -- ia
10 changes: 10 additions & 0 deletions tests/examples/gly/no_crash/multiple_scores.gly
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\score
mode: 8
description: Basic alleluia
c4 g gh g g
A -- lle -- lu -- ia

\score
description: Another simple alleluia
c4 g gj hig h
A -- lle -- lu -- ia
20 changes: 20 additions & 0 deletions tests/no_crash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative 'test_helper'

# tests of cases that cannot be easily described by a pair
# of single gly file and resulting gabc file
class TestNoCrash < GlyTest
def self.nocrash_test_case(filename)
case_name = File.basename(filename).sub(/\.[^\.]*\Z/, '')
define_method "test_#{case_name}" do
File.open filename do |fr|
# simply let it convert to test that it does not crash
gly_process(fr).string
end
end
end

here = File.dirname __FILE__
Dir.glob(File.join(here, 'examples/gly/no_crash/*.gly')).each do |f|
nocrash_test_case f
end
end
1 change: 1 addition & 0 deletions tests/run.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require_relative 'examples'
require_relative 'no_crash'
10 changes: 10 additions & 0 deletions tests/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@

require 'minitest/reporters'
Minitest::Reporters.use!

# parent of all gly test classes
class GlyTest < MiniTest::Test
# shortcut performing gly->gabc conversion and returning
# it's results
def gly_process(gly_io)
parsed = Gly::Parser.new.parse(gly_io).first
Gly::GabcConvertor.new.convert(parsed)
end
end

0 comments on commit 3e3440d

Please sign in to comment.