Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 57 lines (47 sloc) 1.208 kb
51cc887 @mjackson Improved support for multibyte characters
authored
1 # encoding: UTF-8
2
994c5ce @mjackson Implemented StringScanner for scanning input strings.
authored
3 require File.expand_path('../helper', __FILE__)
4
5 class ParseErrorTest < Test::Unit::TestCase
6 Sentence = Grammar.new do
7 include Words
8
9 rule :sentence do
10 all(:capital_word, one_or_more([ :space, :word ]), :period)
11 end
12
13 rule :capital_word do
14 all(/[A-Z]/, zero_or_more(:alpha))
15 end
16
17 rule :space do
18 one_or_more(any(" ", "\n", "\r\n"))
19 end
20
21 rule :period, '.'
22 end
23
24 def test_basic
25 begin
26 TestGrammar.parse('#')
27 rescue ParseError => e
28 assert_equal(0, e.offset)
29 assert_equal('#', e.line)
30 assert_equal(1, e.line_number)
31 assert_equal(0, e.line_offset)
32 end
33 end
34
35 def test_single_line
36 begin
51cc887 @mjackson Improved support for multibyte characters
authored
37 Sentence.parse('Once upon ä time.')
994c5ce @mjackson Implemented StringScanner for scanning input strings.
authored
38 rescue ParseError => e
39 assert_equal(10, e.offset)
51cc887 @mjackson Improved support for multibyte characters
authored
40 assert_equal('Once upon ä time.', e.line)
994c5ce @mjackson Implemented StringScanner for scanning input strings.
authored
41 assert_equal(1, e.line_number)
42 assert_equal(10, e.line_offset)
43 end
44 end
45
46 def test_multi_line
47 begin
48 Sentence.parse("Once\nupon a\r\ntim3.")
49 rescue ParseError => e
50 assert_equal(16, e.offset)
51 assert_equal('tim3.', e.line)
52 assert_equal(3, e.line_number)
53 assert_equal(3, e.line_offset)
54 end
55 end
456adbe @mjackson Introduced more lightweight parsing model
authored
56 end
Something went wrong with that request. Please try again.