scripref 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ # - encoding: utf-8 -
2
+ require 'test_helper'
3
+
4
+ class TestBookname < Test::Unit::TestCase
5
+
6
+ include Scripref
7
+
8
+ def setup
9
+ @zef = Bookname.new(%w(Zefanja Zephanja), %w(Zef Zefan Zeph Zephan))
10
+ end
11
+
12
+ def test_name
13
+ assert_equal 'Zefanja', @zef.name
14
+ end
15
+
16
+ def test_abbrev
17
+ assert_equal 'Zef', @zef.abbrev
18
+ end
19
+
20
+ end
data/test/test_english.rb CHANGED
@@ -1,24 +1,26 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref/english'
5
3
 
6
4
  class TestEnglish < Test::Unit::TestCase
7
5
 
8
- include Test::Helper
9
6
  include Scripref
7
+ include Test::Helper
10
8
 
11
9
  def setup
12
10
  @parser = Parser.new(English)
13
11
  end
14
12
 
13
+ def test_size_of_book_array
14
+ assert_equal 66, English::BOOK_NAMES.size
15
+ end
16
+
15
17
  def test_book_re
16
18
  book_re = @parser.book_re
17
19
  assert_match book_re, 'Genesis'
18
20
  assert_match book_re, 'Exodus'
19
21
  assert_match book_re, 'Matthew'
20
22
  assert_match book_re, '2 Timothy'
21
- assert_not_match book_re, '2 2 Timothy'
23
+ assert_not_match book_re, 'x2 Timothy'
22
24
  assert_match book_re, 'Revelation'
23
25
  assert_not_match book_re, 'something'
24
26
  assert_match book_re, 'Gen'
@@ -1,20 +1,14 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref'
5
- require 'scripref/english'
6
- require 'scripref/formatter'
7
- require 'scripref/german'
8
- require 'scripref/parser'
9
3
 
10
4
  class TestFormatter < Test::Unit::TestCase
11
5
 
6
+ include Scripref
12
7
  include Test::Helper
13
8
 
14
9
  def setup
15
- @parser = Scripref::Parser.new(Scripref::German)
16
- @german_formatter = Scripref::Formatter.new(Scripref::German)
17
- @english_formatter = Scripref::Formatter.new(Scripref::English)
10
+ @german_formatter = Formatter.new(German)
11
+ @english_formatter = Formatter.new(English)
18
12
  end
19
13
 
20
14
  def test_only_book
@@ -88,7 +82,6 @@ class TestFormatter < Test::Unit::TestCase
88
82
  end
89
83
 
90
84
  def test_reset_addons
91
- @parser.parse 'Ruth 2,5b-7a'
92
85
  text = 'Ruth'
93
86
  assert_formated_text_for_ast text, [pass(text, 8, nil, nil, 8, nil, nil)]
94
87
  end
@@ -256,6 +249,23 @@ class TestFormatter < Test::Unit::TestCase
256
249
  assert_formated_text_for_ast text, ast
257
250
  end
258
251
 
252
+ ######################################################################
253
+ # Formatting of books
254
+ ######################################################################
255
+
256
+ def test_formatting_with_book_abbrevs
257
+ @german_formatter.bookformat = :abbrev
258
+ text = 'Mat 3,4; Mar; Joh 3,16'
259
+ t1, t2, t3 = text.split(semi)
260
+ assert_formated_text_for_ast text, [pass(t1, 40, 3, 4, 40, 3, 4), semi, pass(t2, 41, nil, nil, 41, nil, nil), semi, pass(t3, 43, 3, 16, 43, 3, 16)]
261
+ end
262
+
263
+ def test_exception_for_unhandled_bookformat
264
+ assert_raise NoMethodError do
265
+ @german_formatter.bookformat = :unknown
266
+ @german_formatter.format [pass(1,2,3,4,5,6,7)]
267
+ end
268
+ end
259
269
  private
260
270
 
261
271
  def assert_formated_text_for_ast text, ast
data/test/test_german.rb CHANGED
@@ -1,24 +1,26 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref/german'
5
3
 
6
4
  class TestGerman < Test::Unit::TestCase
7
5
 
8
- include Test::Helper
9
6
  include Scripref
7
+ include Test::Helper
10
8
 
11
9
  def setup
12
10
  @parser = Parser.new(German)
13
11
  end
14
12
 
13
+ def test_size_of_book_array
14
+ assert_equal 66, German::BOOK_NAMES.size
15
+ end
16
+
15
17
  def test_book_re
16
18
  book_re = @parser.book_re
17
19
  assert_match book_re, '1. Mose'
18
20
  assert_match book_re, '2. Mose'
19
21
  assert_match book_re, 'Matthäus'
20
22
  assert_match book_re, '2. Timotheus'
21
- assert_not_match book_re, '2. 2. Timotheus'
23
+ assert_not_match book_re, 'x2. Timotheus'
22
24
  assert_match book_re, 'Offenbarung'
23
25
  assert_not_match book_re, 'something'
24
26
  assert_match book_re, '1. Mo'
data/test/test_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # - encoding: utf-8 -
2
+ require 'scripref'
3
+ require 'test/unit'
4
+
1
5
  module Test::Helper
2
6
 
3
7
  def pass *args
@@ -12,35 +16,4 @@ module Test::Helper
12
16
  Scripref::VerseSep.new('.')
13
17
  end
14
18
 
15
- def assert_equal_passage expected, actual
16
- assert_equal expected.text, actual.text, 'Parsed text'
17
- assert_equal expected.b1, actual.b1, 'First book'
18
- assert_equal expected.c1, actual.c1, 'First chapter'
19
- assert_equal expected.v1, actual.v1, 'First verse'
20
- assert_equal expected.b2, actual.b2, 'Second book'
21
- assert_equal expected.c2, actual.c2, 'Second chapter'
22
- assert_equal expected.v2, actual.v2, 'Second verse'
23
- assert_equal expected.a1, actual.a1, 'First addon'
24
- assert_equal expected.a2, actual.a2, 'Second addon'
25
- end
26
-
27
- def assert_parsed_ast_for_text expected_ast, text
28
- res = @parser.parse(text)
29
- assert_equal expected_ast.size, res.size, 'Array size of AST'
30
- expected_ast.zip(res) do |expected_elem, actual_elem|
31
- if expected_elem.kind_of?(Scripref::Passage)
32
- assert_equal_passage expected_elem, actual_elem
33
- else
34
- assert_equal expected_elem, actual_elem
35
- end
36
- end
37
- end
38
-
39
- def assert_parser_error msg
40
- assert_raise Scripref::ParserError do
41
- yield
42
- end
43
- assert_equal msg, @parser.error
44
- end
45
-
46
19
  end
@@ -1,20 +1,14 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref'
5
- require 'scripref/english'
6
- require 'scripref/formatter'
7
- require 'scripref/german'
8
- require 'scripref/parser'
9
3
 
10
4
  class TestIntegration < Test::Unit::TestCase
11
5
 
12
- include Test::Helper
6
+ include Scripref
13
7
 
14
8
  def setup
15
- @parser = Scripref::Parser.new(Scripref::German)
16
- @german_formatter = Scripref::Formatter.new(Scripref::German)
17
- @english_formatter = Scripref::Formatter.new(Scripref::English)
9
+ @parser = Parser.new(German)
10
+ @german_formatter = Formatter.new(German)
11
+ @english_formatter = Formatter.new(English)
18
12
  end
19
13
 
20
14
  def test_only_book
data/test/test_parser.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref'
5
3
 
6
4
  class TestParser < Test::Unit::TestCase
7
5
 
6
+ include Scripref
8
7
  include Test::Helper
9
8
 
10
9
  def setup
11
- @parser = Scripref::Parser.new(Scripref::German)
10
+ @parser = Parser.new(German)
12
11
  end
13
12
 
14
13
  def test_only_book
@@ -279,7 +278,7 @@ class TestParser < Test::Unit::TestCase
279
278
  text = 'Ruth 2,x'
280
279
  begin
281
280
  @parser.parse text
282
- rescue Scripref::ParserError
281
+ rescue ParserError
283
282
  end
284
283
  assert_equal 'Verse expected!', @parser.error
285
284
  formated_error = "Verse expected!\nRuth 2,x\n ^"
@@ -290,7 +289,7 @@ class TestParser < Test::Unit::TestCase
290
289
  text = 'Ruth 2,4; M 3,8'
291
290
  begin
292
291
  @parser.parse text
293
- rescue Scripref::ParserError
292
+ rescue ParserError
294
293
  end
295
294
  assert_match /^Abbreviation M is ambiguous/, @parser.error
296
295
  formated_error = "Abbreviation M is ambiguous it matches Micha, Maleachi, Matthäus, Markus!\nRuth 2,4; M 3,8\n ^"
@@ -310,4 +309,37 @@ class TestParser < Test::Unit::TestCase
310
309
  assert_parsed_ast_for_text [pass(text, 50, 4, 4, 50, 4, 4)], text
311
310
  end
312
311
 
312
+ private
313
+
314
+ def assert_equal_passage expected, actual
315
+ assert_equal expected.text, actual.text, 'Parsed text'
316
+ assert_equal expected.b1, actual.b1, 'First book'
317
+ assert_equal expected.c1, actual.c1, 'First chapter'
318
+ assert_equal expected.v1, actual.v1, 'First verse'
319
+ assert_equal expected.b2, actual.b2, 'Second book'
320
+ assert_equal expected.c2, actual.c2, 'Second chapter'
321
+ assert_equal expected.v2, actual.v2, 'Second verse'
322
+ assert_equal expected.a1, actual.a1, 'First addon'
323
+ assert_equal expected.a2, actual.a2, 'Second addon'
324
+ end
325
+
326
+ def assert_parsed_ast_for_text expected_ast, text
327
+ res = @parser.parse(text)
328
+ assert_equal expected_ast.size, res.size, 'Array size of AST'
329
+ expected_ast.zip(res) do |expected_elem, actual_elem|
330
+ if expected_elem.kind_of?(Passage)
331
+ assert_equal_passage expected_elem, actual_elem
332
+ else
333
+ assert_equal expected_elem, actual_elem
334
+ end
335
+ end
336
+ end
337
+
338
+ def assert_parser_error msg
339
+ assert_raise ParserError do
340
+ yield
341
+ end
342
+ assert_equal msg, @parser.error
343
+ end
344
+
313
345
  end
data/test/test_passage.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref'
5
3
 
6
4
  class TestPassage < Test::Unit::TestCase
7
5
 
6
+ include Scripref
7
+ include Test::Helper
8
+
8
9
  def setup
9
- @parser = Scripref::Parser.new(Scripref::German)
10
+ @parser = Parser.new(German)
10
11
  end
11
12
 
12
13
  def test_to_a
@@ -26,7 +27,7 @@ class TestPassage < Test::Unit::TestCase
26
27
 
27
28
  def test_comparable_with_sort
28
29
  ast = @parser.parse('Joh 8,1-9,11; 8,2-9,12; 8,2-9,11; 8,1-9,12; Joh 8')
29
- passages = ast.grep(Scripref::Passage)
30
+ passages = ast.grep(Passage)
30
31
  expect = ['Joh 8',
31
32
  'Joh 8,1-9,11',
32
33
  '8,1-9,12',
@@ -35,8 +36,8 @@ class TestPassage < Test::Unit::TestCase
35
36
  assert_equal expect, passages.sort.map(&:text)
36
37
 
37
38
  ast = @parser.parse('Mar 1; 1,1; 1,1f; 1,1ff; 1,2; 1,1-2,2; Mar 1-2; Markus; Markus-Lukas; Mar 1-Luk 2; Mar 1,1-Luk 2,2')
38
- passages = ast.grep(Scripref::Passage)
39
- formatter = Scripref::Formatter.new(Scripref::German)
39
+ passages = ast.grep(Passage)
40
+ formatter = Formatter.new(German)
40
41
  expect = ['Markus 1,1',
41
42
  'Markus 1,1f',
42
43
  'Markus 1,1ff',
@@ -65,15 +66,27 @@ class TestPassage < Test::Unit::TestCase
65
66
  end
66
67
 
67
68
  def test_start
68
- p = Scripref::Passage.new('', 1, 2, 3, 4, 5, 6)
69
+ p = pass('', 1, 2, 3, 4, 5, 6)
69
70
  assert_equal [1, 2, 3], p.start
70
71
  end
71
72
 
72
73
  def test_end
73
- p = Scripref::Passage.new('', 1, 2, 3, 4, 5, 6)
74
+ p = pass('', 1, 2, 3, 4, 5, 6)
74
75
  assert_equal [4, 5, 6], p.end
75
76
  end
76
77
 
78
+ def test_sum
79
+ p1 = pass('', 1, 2, 3, 4, 5, 6)
80
+ p2 = pass('', 1, 1, 1, 1, 1, 1)
81
+ assert_equal [2, 3, 4, 5, 6, 7], p1 + p2
82
+ end
83
+
84
+ def test_differenz
85
+ p1 = pass('', 1, 2, 3, 4, 5, 6)
86
+ p2 = pass('', 1, 1, 1, 1, 1, 1)
87
+ assert_equal [0, 1, 2, 3, 4, 5], p2 - p1
88
+ end
89
+
77
90
  protected
78
91
 
79
92
  def assert_overlap a, b
@@ -1,12 +1,10 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
2
  require 'test_helper'
4
- require 'scripref'
5
3
 
6
4
  class TestPipelining < Test::Unit::TestCase
7
5
 
8
- include Test::Helper
9
6
  include Scripref
7
+ include Test::Helper
10
8
 
11
9
  def test_right_to_left
12
10
  text = 'Hebräer 13,8'
@@ -1,30 +1,35 @@
1
1
  # - encoding: utf-8 -
2
- require 'test/unit'
3
- require 'scripref'
2
+ require 'test_helper'
4
3
 
5
4
  class TestProcessor < Test::Unit::TestCase
6
5
 
7
- def setup
6
+ include Scripref
7
+ include Test::Helper
8
+
9
+ def setup1
8
10
  @text = 'Some text Mt 1,1 and Mr 2 and so on ...'
9
- @mt = [Scripref::Passage.new('Mt 1,1 ', 40, 1, 1, 40, 1, 1)]
10
- @mr = [Scripref::Passage.new('Mr 2 ', 41, 2, nil, 41, 2, nil)]
11
- @processor = Scripref::Processor.new(@text, Scripref::German)
11
+ @mt = [pass('Mt 1,1 ', 40, 1, 1, 40, 1, 1)]
12
+ @mr = [pass('Mr 2 ', 41, 2, nil, 41, 2, nil)]
13
+ @processor = Processor.new(@text, German)
12
14
  @chunks = ['Some text ', @mt, 'and ', @mr, 'and so on ...']
13
15
  end
14
16
 
15
17
  def test_each_with_block
18
+ setup1
16
19
  @processor.each do |chunk|
17
20
  assert_equal @chunks.shift, chunk
18
21
  end
19
22
  end
20
23
 
21
24
  def test_each_without_block
25
+ setup1
22
26
  enum = @processor.each
23
27
  assert_kind_of Enumerator, enum
24
28
  assert_equal @chunks, enum.to_a
25
29
  end
26
30
 
27
31
  def test_each_ref_with_block
32
+ setup1
28
33
  refs = @chunks.select {|c| c.kind_of? Array}
29
34
  @processor.each_ref do |ref|
30
35
  assert_equal refs.shift, ref
@@ -32,10 +37,79 @@ class TestProcessor < Test::Unit::TestCase
32
37
  end
33
38
 
34
39
  def test_each_ref_without_block
40
+ setup1
35
41
  enum = @processor.each_ref
36
42
  refs = @chunks.select {|c| c.kind_of? Array}
37
43
  assert_kind_of Enumerator, enum
38
44
  assert_equal refs, enum.to_a
39
45
  end
40
46
 
47
+ def test_reference_without_other_text
48
+ text = 'Mt 1,1'
49
+ ast = [[pass('Mt 1,1 ', 40, 1, 1, 40, 1, 1)]]
50
+ processor = Processor.new(text, German)
51
+ assert_equal ast, processor.each_ref.to_a
52
+ assert_equal ast, processor.each.to_a
53
+ end
54
+
55
+ def test_text_without_reference
56
+ text = 'some text'
57
+ processor = Processor.new(text, German)
58
+ assert_equal [], processor.each_ref.to_a
59
+ assert_equal [text], processor.each.to_a
60
+ end
61
+
62
+ def test_empty_text
63
+ text = ''
64
+ processor = Processor.new(text, German)
65
+ assert_equal [], processor.each_ref.to_a
66
+ assert_equal [], processor.each.to_a
67
+ end
68
+
69
+ def test_numerical_context
70
+ text = '1. Mt 1,1'
71
+ processor = Processor.new(text, German)
72
+ ast = [[pass(text, 40, 1, 1, 40, 1, 1)]]
73
+ assert_equal ast, processor.each_ref.to_a
74
+ ast = ['1. ', [pass(text, 40, 1, 1, 40, 1, 1)]]
75
+ assert_equal ast, processor.each.to_a
76
+ end
77
+
78
+ def test_verse_addon_or_postfix
79
+ text = 'Mt 1,1a'
80
+ processor = Processor.new(text, German)
81
+ ast = [[pass(text, 40, 1, 1, 40, 1, 1, a1: 'a')]]
82
+ assert_equal ast, processor.each.to_a
83
+ text = 'Mt 1,1f'
84
+ processor = Processor.new(text, German)
85
+ ast = [[pass(text, 40, 1, 1, 40, 1, :f)]]
86
+ assert_equal ast, processor.each.to_a
87
+ text = 'Mt 1,1ff'
88
+ processor = Processor.new(text, German)
89
+ ast = [[pass(text, 40, 1, 1, 40, 1, :ff)]]
90
+ assert_equal ast, processor.each.to_a
91
+ end
92
+
93
+ def test_verse_addon_or_postfix_for_books_with_only_one_chapter
94
+ text = '2. Joh 5b'
95
+ processor = Processor.new(text, German)
96
+ ast = [[pass(text, 63, 1, 5, 63, 1, 5, a1: 'b')]]
97
+ assert_equal ast, processor.each.to_a
98
+ text = '2. Joh 5f'
99
+ processor = Processor.new(text, German)
100
+ ast = [[pass(text, 63, 1, 5, 63, 1, :f)]]
101
+ assert_equal ast, processor.each.to_a
102
+ text = '2. Joh 5ff'
103
+ processor = Processor.new(text, German)
104
+ ast = [[pass(text, 63, 1, 5, 63, 1, :ff)]]
105
+ assert_equal ast, processor.each.to_a
106
+ end
107
+
108
+ def test_verse_sep
109
+ text = '2. Joh 5.8'
110
+ processor = Processor.new(text, German)
111
+ ast = [[pass(text, 63, 1, 5, 63, 1, 5), '.', pass(text, 63, 1, 8, 63, 1, 8)]]
112
+ assert_equal ast, processor.each.to_a
113
+ end
114
+
41
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scripref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '2.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.6'
26
+ version: '2.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: regtest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -49,10 +49,13 @@ files:
49
49
  - README.md
50
50
  - Rakefile
51
51
  - lib/scripref.rb
52
+ - lib/scripref/basic_methods.rb
53
+ - lib/scripref/bookname.rb
52
54
  - lib/scripref/const_reader.rb
53
55
  - lib/scripref/english.rb
54
56
  - lib/scripref/formatter.rb
55
57
  - lib/scripref/german.rb
58
+ - lib/scripref/include.rb
56
59
  - lib/scripref/parser.rb
57
60
  - lib/scripref/passage.rb
58
61
  - lib/scripref/pipelining.rb
@@ -61,6 +64,9 @@ files:
61
64
  - regtest/formatter.yml
62
65
  - regtest/parser.rb
63
66
  - regtest/parser.yml
67
+ - regtest/processor.rb
68
+ - regtest/processor.yml
69
+ - test/test_bookname.rb
64
70
  - test/test_english.rb
65
71
  - test/test_formatter.rb
66
72
  - test/test_german.rb
@@ -89,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
95
  version: '0'
90
96
  requirements: []
91
97
  rubyforge_project:
92
- rubygems_version: 2.6.3
98
+ rubygems_version: 2.6.10
93
99
  signing_key:
94
100
  specification_version: 4
95
101
  summary: Library for parsing scripture references in real texts.