scripref 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01a6a4eaf04a5db4c42caa6e28c39e4e024e6383
4
- data.tar.gz: aaaf18868275f9e5c6e7c3cccfc139e9efe18dcb
3
+ metadata.gz: c0fc95082d6f8f815ac4125c0eef8b6e1c28abc9
4
+ data.tar.gz: e08bde6417a5fa005412d1125ea7fa23c327af24
5
5
  SHA512:
6
- metadata.gz: 60f0173166dae8e8b133935eabbe99bfc624f819ab31a0b016876ec47104744bcaee0541e334eaab24e7129744c41c91e07c6e17164f809343208a418d6ca866
7
- data.tar.gz: 954ee188ad98491e959db439801899dac9ae07af01072fb8fc1502065c5804e27537e452a965d65e67f46fd78aa4d0ffe804cc0ae0e82438e8edeaeb2aee0374
6
+ metadata.gz: f89c7410072844ed4d09ecf4137a6168496bcfb888002219b74f864de0811c0f3a166b5f37a7513160d79266d9578832a10196b9408e8cfa3731731c5b58a6a1
7
+ data.tar.gz: cf33c35be9080ba70ac85259cdd56273405eed57508cdaf75d59f2f1d444e63fe93ab0bd9c2ccfb2d6af62f909d319b641891ec11928d0449d0e27f7c95d44a8
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 0.6.0
2
+ Use explicit classes for separators: PassSep and VerseSep.
3
+ Refactoring: Rename class Parser::Error -> ParserError.
4
+ Parser raises ParserError instead of an empty array if correct parsing fails.
5
+ Make Passage comparable and add method Passage#to_a.
6
+ Some internal refactorings and better samples for regtest.
7
+
1
8
  0.5.0
2
9
  Rename Formatter#fullref -> #format.
3
10
  Implementing pipelining with >>.
@@ -18,60 +18,102 @@ module Scripref
18
18
 
19
19
  # Formats a reference (array of passages)
20
20
  def format *reference
21
- last_b = last_c = last_v = nil
22
- pass_texts = reference.flatten.map do |pass|
23
- changed = false
24
- s = ''
25
- if changed || last_b != pass.b1
26
- s << book_names[pass.b1 - 1]
27
- last_b = pass.b1
28
- changed = true
21
+ @last_b = @last_c = @last_v = :undefined
22
+ @result = ''
23
+ reference.flatten.each do |pass|
24
+ @pass = pass
25
+ format_passage
26
+ end
27
+ @result
28
+ end
29
+
30
+ def format_passage
31
+ @changed = false
32
+ format_b1
33
+ end
34
+
35
+ def format_b1
36
+ b1 = @pass.b1
37
+ if @last_b != b1
38
+ @result << book_names[b1 - 1]
39
+ @last_b = b1
40
+ @changed = true
41
+ end
42
+ format_c1
43
+ end
44
+
45
+ def format_c1
46
+ c1 = @pass.c1
47
+ if c1 && (@changed || @last_c != c1)
48
+ @result << ' '
49
+ if ! Scripref.book_has_only_one_chapter?(@pass.b1)
50
+ @result << c1.to_s
29
51
  end
30
- if changed || last_c != pass.c1
31
- s << ' '
32
- if ! Scripref.book_has_only_one_chapter?(pass.b1)
33
- s << pass.c1.to_s
34
- end
35
- last_c = pass.c1
36
- changed = true
52
+ @last_c = c1
53
+ @changed = true
54
+ end
55
+ format_v1
56
+ end
57
+
58
+ def format_v1
59
+ v1 = @pass.v1
60
+ if v1 && (@changed || @last_v != v1)
61
+ if ! Scripref.book_has_only_one_chapter?(@pass.b1)
62
+ @result << cv_separator
37
63
  end
38
- if changed || last_v != pass.v1
39
- if ! Scripref.book_has_only_one_chapter?(pass.b1)
40
- s << cv_separator
41
- end
42
- s << pass.v1.to_s
43
- last_v = pass.v1
44
- changed = true
64
+ @result << v1.to_s
65
+ @last_v = v1
66
+ end
67
+ format_b2
68
+ end
69
+
70
+ def format_b2
71
+ @changed = false
72
+ @hyphen = false
73
+ b2 = @pass.b2
74
+ if b2 && (@changed || @last_b != b2)
75
+ @result << hyphen_separator
76
+ @result << book_names[b2 - 1]
77
+ @last_b = b2
78
+ @changed = true
79
+ @hyphen = true
80
+ end
81
+ format_c2
82
+ end
83
+
84
+ def format_c2
85
+ c2 = @pass.c2
86
+ if c2 && (@changed || @last_c != c2)
87
+ if @hyphen
88
+ @result << ' '
89
+ else
90
+ @result << hyphen_separator
91
+ @hyphen = true
45
92
  end
46
- # second part
47
- changed = false
48
- a2 = []
49
- if changed || last_b != pass.b2
50
- a2 << book_names[pass.b2 - 1]
51
- last_b = pass.b2
52
- changed = true
93
+ if ! Scripref.book_has_only_one_chapter?(@pass.b2)
94
+ @result << c2.to_s
53
95
  end
54
- if changed || last_c != pass.c2
55
- a2 << ' ' if pass.b1 != pass.b2
56
- if ! Scripref.book_has_only_one_chapter?(pass.b2)
57
- a2 << pass.c2.to_s
58
- a2 << cv_separator
96
+ @last_c = c2
97
+ @changed = true
98
+ end
99
+ format_v2
100
+ end
101
+
102
+ def format_v2
103
+ v2 = @pass.v2
104
+ if v2 && (@changed || @last_v != v2)
105
+ if @hyphen
106
+ if ! Scripref.book_has_only_one_chapter?(@pass.b2)
107
+ @result << cv_separator
59
108
  end
60
- last_c = pass.c2
61
- changed = true
62
- end
63
- if changed || last_v != pass.v2
64
- a2 << pass.v2.to_s
65
- last_v = pass.v2
66
- changed = true
67
- end
68
- if ! a2.empty?
69
- s << hyphen_separator
70
- s << a2.join('')
109
+ else
110
+ @result << hyphen_separator
111
+ @hyphen = true
71
112
  end
72
- s
113
+ @result << v2.to_s
114
+ @last_v = @v2
115
+ @changed = true
73
116
  end
74
- pass_texts.join(pass_separator)
75
117
  end
76
118
 
77
119
  alias << format
@@ -5,6 +5,8 @@ module Scripref
5
5
 
6
6
  class Parser < StringScanner
7
7
 
8
+ attr_reader :error
9
+
8
10
  NUMBER_RE = /\d+\s*/
9
11
 
10
12
  # @param mods one or more modules to include
@@ -24,13 +26,14 @@ module Scripref
24
26
  def parse str
25
27
  self.string = str
26
28
  @result = []
29
+ @error = nil
27
30
  start
28
31
  end
29
32
 
30
33
  # start of parsing grammer
31
34
  def start
32
35
  @text = ''
33
- b1 or []
36
+ b1 or give_up 'Book expected!'
34
37
  end
35
38
 
36
39
  # try to parse first book
@@ -46,11 +49,11 @@ module Scripref
46
49
  else
47
50
  if Scripref.book_has_only_one_chapter?(@b1)
48
51
  @c1 = @c2 = 1
49
- epsilon or (hyphen and b2) or v1 or nil
52
+ epsilon or (hyphen and b2) or v1 or give_up 'EOS or hyphen and book or verse expected!'
50
53
  else
51
54
  @c1 = @v1 = nil
52
55
  @c2 = @v2 = nil
53
- epsilon or (hyphen and b2) or c1 or nil
56
+ epsilon or (hyphen and b2) or c1 or give_up 'EOS or hyphen and book or chapter expected!'
54
57
  end
55
58
  end
56
59
  end
@@ -62,13 +65,13 @@ module Scripref
62
65
  @c1 = @c2 = s.to_i
63
66
 
64
67
  if cv_sep
65
- v1 or nil
68
+ v1 or give_up 'Verse expected!'
66
69
  elsif hyphen
67
- b2 or c2 or nil
70
+ b2 or c2 or give_up 'Book or chapter expected!'
68
71
  elsif pass_sep
69
- b1 or c1
72
+ b1 or c1 or give_up 'Book or chapter expected!'
70
73
  else
71
- epsilon or nil
74
+ epsilon or give_up 'EOS or chapter verse separator or hyphen and book or hyphen and chapter or passage separator and book or passage separator and chapter expected!'
72
75
  end
73
76
  end
74
77
 
@@ -92,14 +95,14 @@ module Scripref
92
95
  if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
93
96
  c2
94
97
  else
95
- v2 or nil
98
+ v2 or give_up 'Chapter or verse expected!'
96
99
  end)
97
100
  elsif pass_sep
98
- b1 or c1
101
+ b1 or c1 or give_up 'Book or chapter expected!'
99
102
  elsif verse_sep
100
- v1
103
+ v1 or give_up 'Verse expected!'
101
104
  else
102
- epsilon or nil
105
+ epsilon or give_up 'EOS or passage separator or verse separator or hyphen expected!'
103
106
  end
104
107
  end
105
108
 
@@ -115,9 +118,9 @@ module Scripref
115
118
  else
116
119
  if Scripref.book_has_only_one_chapter?(@b2)
117
120
  @c2 = 1
118
- epsilon or v2 or nil
121
+ epsilon or v2 or give_up 'EOS or chapter or verse expected!'
119
122
  else
120
- epsilon or c2 or nil
123
+ epsilon or c2 or ('EOS or chapter expected')
121
124
  end
122
125
  end
123
126
  end
@@ -129,9 +132,9 @@ module Scripref
129
132
  @c2 = s.to_i
130
133
 
131
134
  if cv_sep
132
- v2 or nil
135
+ v2 or give_up 'Verse expected!'
133
136
  else
134
- epsilon or nil
137
+ epsilon or give_up 'EOS or chapter verse separator expected!'
135
138
  end
136
139
  end
137
140
 
@@ -149,11 +152,11 @@ module Scripref
149
152
  end
150
153
 
151
154
  if verse_sep
152
- v1
155
+ v1 or give_up 'Verse expected!'
153
156
  elsif pass_sep
154
- b1 or c1
157
+ b1 or c1 or give_up 'Book or chapter expected!'
155
158
  else
156
- epsilon or nil
159
+ epsilon or give_up 'EOS or verse separator or passage separator expected!'
157
160
  end
158
161
  end
159
162
 
@@ -190,7 +193,7 @@ module Scripref
190
193
  def pass_sep
191
194
  if s = scan(pass_sep_re)
192
195
  push_passage
193
- @result << s
196
+ @result << PassSep.new(s)
194
197
  s
195
198
  else
196
199
  nil
@@ -201,7 +204,7 @@ module Scripref
201
204
  def verse_sep
202
205
  if s = scan(verse_sep_re)
203
206
  push_passage
204
- @result << s
207
+ @result << VerseSep.new(s)
205
208
  s
206
209
  else
207
210
  nil
@@ -233,7 +236,7 @@ module Scripref
233
236
  pattern = str.strip.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
234
237
  re = /(?<=#)#{pattern}(?=#)/
235
238
  names = @books_str.scan(re)
236
- fail Error, format("Abbreviation %s is ambiguous it matches %s!", str, names.join(', ')) unless names.size == 1
239
+ give_up format("Abbreviation %s is ambiguous it matches %s!", str, names.join(', ')) unless names.size == 1
237
240
  names.first
238
241
  end
239
242
 
@@ -249,10 +252,23 @@ module Scripref
249
252
  "#<#{self.class} #{@mods.inspect}>"
250
253
  end
251
254
 
252
- alias << parse
255
+ def give_up msg
256
+ @error = msg
257
+ fail ParserError, format_error
258
+ end
253
259
 
254
- class Error < RuntimeError; end
260
+ def format_error
261
+ if error
262
+ format("%s\n%s^\n%s", string, ' ' * pointer, error)
263
+ else
264
+ ''
265
+ end
266
+ end
267
+
268
+ alias << parse
255
269
 
256
270
  end
257
271
 
272
+ class ParserError < RuntimeError; end
273
+
258
274
  end
data/lib/scripref.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # - encoding: utf-8 -
2
+ require 'delegate'
2
3
  require 'scripref/parser'
3
4
  require 'scripref/processor'
4
5
  require 'scripref/formatter'
@@ -7,17 +8,37 @@ require 'scripref/german'
7
8
 
8
9
  module Scripref
9
10
 
10
- VERSION = '0.5.0'
11
+ VERSION = '0.6.0'
11
12
 
12
13
  Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2) do
13
14
 
15
+ include Comparable
16
+
14
17
  def initialize text, b1, c1, v1, b2, c2, v2, opts={}
15
18
  super text, b1, c1, v1, b2, c2, v2, opts[:a1], opts[:a2]
16
19
  end
17
20
 
21
+ def to_a
22
+ [b1, c1, v1, b2, c2, v2]
23
+ end
24
+
25
+ def <=> o
26
+ a1 = self.to_a.map {|e| e.nil? ? 0 : e}
27
+ a2 = o.to_a.map {|e| e.nil? ? 0 : e}
28
+ a1 <=> a2
29
+ end
30
+
18
31
  alias to_s text
19
32
  end
20
33
 
34
+ class Sep < DelegateClass(String)
35
+ def initialize s
36
+ super s
37
+ end
38
+ end
39
+ class PassSep < Sep; end
40
+ class VerseSep < Sep; end
41
+
21
42
  # check if the book has only one chapter
22
43
  def self.book_has_only_one_chapter? book
23
44
  [31, 63, 64, 65].include?(book)
data/regtest/parser.rb CHANGED
@@ -4,13 +4,22 @@ require 'scripref'
4
4
  include Regtest
5
5
  include Scripref
6
6
 
7
- $parser = Parser.new(German)
8
-
9
7
  def s text
10
8
  sample text do
11
- res = $parser.parse(text)
12
- res.map {|r| r.respond_to?(:to_h) ? r.to_h : r}
9
+ res = Parser.new(German).parse(text)
10
+ res.map {|r| r.respond_to?(:to_h) ? r.to_h : r.to_s}
13
11
  end
14
12
  end
15
13
 
16
- s 'Ruth 2,1a-11.15a; 3,7b.9-12b; Markus 4; 5,3a.18b-21a'
14
+ text = 'Ruth 2,1a-11.15a; 3,7b.9-12b; Markus 4; 5,3a.18b-21a'
15
+
16
+ s text
17
+
18
+ a = text.split(/\b/)
19
+ a.each_with_index do |e, i|
20
+ next if e =~ /^\s+$/
21
+ a2 = a.clone
22
+ a2.delete_at(i)
23
+ t = a2.join
24
+ s t
25
+ end
@@ -17,12 +17,36 @@ class TestFormatter < Test::Unit::TestCase
17
17
  @english_formatter = Scripref::Formatter.new(Scripref::English)
18
18
  end
19
19
 
20
+ def test_only_book
21
+ @german = 'Römer'
22
+ @english = 'Romans'
23
+ check_formatting
24
+ end
25
+
26
+ def test_book_and_chapter
27
+ @german = 'Römer 8'
28
+ @english = 'Romans 8'
29
+ check_formatting
30
+ end
31
+
20
32
  def test_one_verse
21
33
  @german = 'Römer 6,23'
22
34
  @english = 'Romans 6:23'
23
35
  check_formatting
24
36
  end
25
37
 
38
+ def test_book_range
39
+ @german = 'Römer-Hebräer'
40
+ @english = 'Romans-Hebrews'
41
+ check_formatting
42
+ end
43
+
44
+ def test_chapter_range
45
+ @german = 'Römer 1-8'
46
+ @english = 'Romans 1-8'
47
+ check_formatting
48
+ end
49
+
26
50
  def test_simple_passage
27
51
  @german = 'Römer 8,1-10'
28
52
  @english = 'Romans 8:1-10'
@@ -65,7 +89,6 @@ class TestFormatter < Test::Unit::TestCase
65
89
  check_formatting
66
90
  end
67
91
 
68
-
69
92
  def test_changed_hyphen_separator
70
93
  @german = '1. Korinther 1,1 - 2. Korinther 13,13'
71
94
  @english = '1 Corinthians 1:1 - 2 Corinthians 13:13'
data/test/test_helper.rb CHANGED
@@ -4,6 +4,14 @@ module Test::Helper
4
4
  Scripref::Passage.new(*args)
5
5
  end
6
6
 
7
+ def semi
8
+ Scripref::PassSep.new('; ')
9
+ end
10
+
11
+ def dot
12
+ Scripref::VerseSep.new('.')
13
+ end
14
+
7
15
  def assert_equal_passage expected, actual
8
16
  assert_equal expected.text, actual.text, 'Parsed text'
9
17
  assert_equal expected.b1, actual.b1, 'First book'
@@ -20,7 +28,7 @@ module Test::Helper
20
28
  res = @parser.parse(text)
21
29
  assert_equal expected_ast.size, res.size, 'Array size of AST'
22
30
  expected_ast.zip(res) do |expected_elem, actual_elem|
23
- if !expected_elem.kind_of?(String)
31
+ if expected_elem.kind_of?(Scripref::Passage)
24
32
  assert_equal_passage expected_elem, actual_elem
25
33
  else
26
34
  assert_equal expected_elem, actual_elem
@@ -28,4 +36,11 @@ module Test::Helper
28
36
  end
29
37
  end
30
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
+
31
46
  end
data/test/test_parser.rb CHANGED
@@ -17,13 +17,9 @@ class TestParser < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_ambiguous_book
20
- assert_raises Scripref::Parser::Error do
21
- begin
22
- @parser.parse 'Jo'
23
- rescue RuntimeError => e
24
- assert_equal 'Abbreviation Jo is ambiguous it matches Josua, Joel, Jona, Johannes, Jakobus!', e.message
25
- raise e
26
- end
20
+ msg = 'Abbreviation Jo is ambiguous it matches Josua, Joel, Jona, Johannes, Jakobus!'
21
+ assert_parser_error msg do
22
+ @parser.parse 'Jo'
27
23
  end
28
24
  end
29
25
 
@@ -137,32 +133,32 @@ class TestParser < Test::Unit::TestCase
137
133
 
138
134
  def test_two_complete_refs
139
135
  text = 'Ruth 2,1; Markus 4,8'
140
- t1, t2 = text.split('; ')
141
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), '; ', pass(t2, 41, 4, 8, 41, 4, 8)], text
136
+ t1, t2 = text.split(semi)
137
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), semi, pass(t2, 41, 4, 8, 41, 4, 8)], text
142
138
  end
143
139
 
144
140
  def test_two_refs_same_book
145
141
  text = 'Ruth 2,1; 5,4'
146
- t1, t2 = text.split('; ')
147
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), '; ', pass(t2, 8, 5, 4, 8, 5, 4)], text
142
+ t1, t2 = text.split(semi)
143
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), semi, pass(t2, 8, 5, 4, 8, 5, 4)], text
148
144
  end
149
145
 
150
146
  def test_two_chapters_same_book
151
147
  text = 'Ruth 2; 5'
152
- t1, t2 = text.split('; ')
153
- assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), '; ', pass(t2, 8, 5, nil, 8, 5, nil)], text
148
+ t1, t2 = text.split(semi)
149
+ assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), semi, pass(t2, 8, 5, nil, 8, 5, nil)], text
154
150
  end
155
151
 
156
152
  def test_two_chapters_different_book
157
153
  text = 'Ruth 2; Markus 4'
158
- t1, t2 = text.split('; ')
159
- assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), '; ', pass(t2, 41, 4, nil, 41, 4, nil)], text
154
+ t1, t2 = text.split(semi)
155
+ assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), semi, pass(t2, 41, 4, nil, 41, 4, nil)], text
160
156
  end
161
157
 
162
158
  def test_two_verses
163
159
  text = 'Ruth 2,5.11'
164
- t1, t2 = text.split('.')
165
- assert_parsed_ast_for_text [pass(t1, 8, 2, 5, 8, 2, 5), '.', pass(t2, 8, 2, 11, 8, 2, 11)], text
160
+ t1, t2 = text.split(dot)
161
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 5, 8, 2, 5), dot, pass(t2, 8, 2, 11, 8, 2, 11)], text
166
162
  end
167
163
 
168
164
  ######################################################################
@@ -171,32 +167,32 @@ class TestParser < Test::Unit::TestCase
171
167
 
172
168
  def test_verse_range_and_separated_verse
173
169
  text = 'Ruth 2,1-3.11'
174
- t1, t2 = text.split('.')
175
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 3), '.', pass(t2, 8, 2, 11, 8, 2, 11)], text
170
+ t1, t2 = text.split(dot)
171
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 3), dot, pass(t2, 8, 2, 11, 8, 2, 11)], text
176
172
  end
177
173
 
178
174
  def test_separate_verse_and_verse_range
179
175
  text = 'Ruth 2,1.3-11'
180
- t1, t2 = text.split('.')
181
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), '.', pass(t2, 8, 2, 3, 8, 2, 11)], text
176
+ t1, t2 = text.split(dot)
177
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 1), dot, pass(t2, 8, 2, 3, 8, 2, 11)], text
182
178
  end
183
179
 
184
180
  def test_two_verse_ranges
185
181
  text = 'Ruth 2,1-3.7-11'
186
- t1, t2 = text.split('.')
187
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 3), '.', pass(t2, 8, 2, 7, 8, 2, 11)], text
182
+ t1, t2 = text.split(dot)
183
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 3), dot, pass(t2, 8, 2, 7, 8, 2, 11)], text
188
184
  end
189
185
 
190
186
  def test_two_verse_range_different_books
191
187
  text = 'Ruth 2,1-11; Markus 4,3-7'
192
- t1, t2 = text.split('; ')
193
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 11), '; ', pass(t2, 41, 4, 3,41, 4, 7)], text
188
+ t1, t2 = text.split(semi)
189
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 11), semi, pass(t2, 41, 4, 3,41, 4, 7)], text
194
190
  end
195
191
 
196
192
  def test_two_verse_range_different_chapters
197
193
  text = 'Ruth 2,1-11; 3,10-19'
198
- t1, t2 = text.split('; ')
199
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 11), '; ', pass(t2, 8, 3, 10, 8, 3, 19)], text
194
+ t1, t2 = text.split(semi)
195
+ assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, 11), semi, pass(t2, 8, 3, 10, 8, 3, 19)], text
200
196
  end
201
197
 
202
198
  ######################################################################
@@ -207,15 +203,30 @@ class TestParser < Test::Unit::TestCase
207
203
  text = 'Ruth 2,1-11.15; 3,7.9-12; Markus 4; 5,3.18-21'
208
204
  t1, t2, t3, t4, t5, t6, t7 = text.split(/; |\./)
209
205
  ast = [
210
- pass(t1, 8, 2, 1, 8, 2, 11), '.',
211
- pass(t2, 8, 2, 15, 8, 2, 15), '; ',
212
- pass(t3, 8, 3, 7, 8, 3, 7), '.',
213
- pass(t4, 8, 3, 9, 8, 3, 12), '; ',
214
- pass(t5, 41, 4, nil, 41, 4, nil), '; ',
215
- pass(t6, 41, 5, 3, 41, 5, 3), '.',
206
+ pass(t1, 8, 2, 1, 8, 2, 11), dot,
207
+ pass(t2, 8, 2, 15, 8, 2, 15), semi,
208
+ pass(t3, 8, 3, 7, 8, 3, 7), dot,
209
+ pass(t4, 8, 3, 9, 8, 3, 12), semi,
210
+ pass(t5, 41, 4, nil, 41, 4, nil), semi,
211
+ pass(t6, 41, 5, 3, 41, 5, 3), dot,
216
212
  pass(t7, 41, 5, 18, 41, 5, 21)
217
213
  ]
218
214
  assert_parsed_ast_for_text ast, text
219
215
  end
220
216
 
217
+ ######################################################################
218
+ # malformed references
219
+ ######################################################################
220
+
221
+ def test_error_message
222
+ text = 'Ruth 2,x'
223
+ begin
224
+ @parser.parse text
225
+ rescue Scripref::ParserError
226
+ end
227
+ assert_equal 'Verse expected!', @parser.error
228
+ formated_error = "Ruth 2,x\n ^\nVerse expected!"
229
+ assert_equal formated_error, @parser.format_error
230
+ end
231
+
221
232
  end
@@ -0,0 +1,23 @@
1
+ # - encoding: utf-8 -
2
+ require 'test/unit'
3
+ require 'test_helper'
4
+ require 'scripref'
5
+
6
+ class TestPassage < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @parser = Scripref::Parser.new(Scripref::German)
10
+ end
11
+
12
+ def test_to_a
13
+ pass = @parser.parse('Mr 1,2-Luk 3,4').first
14
+ assert_equal [41, 1, 2, 42, 3, 4], pass.to_a
15
+ end
16
+
17
+ def test_ordering
18
+ ast = @parser.parse('Joh 8,1-9,11; 8,2-9,12; 8,2-9,11; 8,1-9,12; Joh 8')
19
+ passages = ast.select {|e| Scripref::Passage === e}
20
+ assert_equal ["Joh 8", "Joh 8,1-9,11", "8,1-9,12", "8,2-9,11", "8,2-9,12"], passages.sort.map(&:text)
21
+ end
22
+
23
+ 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.5.0
4
+ version: 0.6.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: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2016-01-04 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.5'
19
+ version: '2.6'
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.5'
26
+ version: '2.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: regtest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,6 +62,7 @@ files:
62
62
  - test/test_german.rb
63
63
  - test/test_helper.rb
64
64
  - test/test_parser.rb
65
+ - test/test_passage.rb
65
66
  - test/test_pipelining.rb
66
67
  - test/test_processor.rb
67
68
  homepage: http://gitorious.org/scripref
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubyforge_project:
86
- rubygems_version: 2.4.5
87
+ rubygems_version: 2.5.1
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Library for parsing scripture references in real texts.