-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.rb
48 lines (42 loc) · 1.4 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require_relative 'test_helper'
# Examples are medium-level tests (not unittests, not end-to-end tests)
# testing parser and convertor at the same time.
# Each test case is defined by a pair of a gly and gabc file
# in directories examples/*/given and examples/*/expected.
class TestExamples < GlyTest
def self.example_test_case(given_file, expected_file)
# filename without extension
case_name = File.basename(given_file).sub(/\.[^\.]*\Z/, '')
define_method "test_#{case_name}" do
expected = File.read expected_file
File.open given_file do |fr|
# the method transform is 'deferred'
# for implementation in subclasses
given = transform fr
assert_equal expected, given
end
end
end
end
# conversion gly -> gabc
class TestGlyExamples < TestExamples
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
def transform(fr)
gly_process(fr).string
end
end
# conversion gabc -> gly
class TestGlyfyExamples < TestExamples
here = File.dirname __FILE__
Dir.glob(File.join(here, 'examples/glyfy/given/*.gabc')).each do |given|
expected = given.sub('/given', '/expected').sub('.gabc', '.gly')
example_test_case given, expected
end
def transform(fr)
glyfy_process(fr).string
end
end