File: free_space_spec.rb

package info (click to toggle)
ruby-regexp-parser 2.11.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,092 kB
  • sloc: ruby: 6,891; makefile: 6; sh: 3
file content (78 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe('FreeSpace parsing') do
  include_examples 'parse', /a b c/,
    [0] => [Literal, text: 'a b c']

  include_examples 'parse', /a b c/x,
    [0] => [Literal, text: 'a'],
    [1] => [WhiteSpace, text: ' '],
    [2] => [Literal, text: 'b'],
    [3] => [WhiteSpace, text: ' '],
    [4] => [Literal, text: 'c']

  include_examples 'parse', /a * b + c/x,
    [0] => [Literal, to_s: 'a*', quantified?: true],
    [1] => [WhiteSpace, text: ' '],
    [2] => [WhiteSpace, text: ' '],
    [3] => [Literal, to_s: 'b+', quantified?: true],
    [4] => [WhiteSpace, text: ' '],
    [5] => [WhiteSpace, text: ' '],
    [6] => [Literal, to_s: 'c']

  include_examples 'parse', /
      a   ?     # One letter
      b {2,5}   # Another one
      [c-g]  +  # A set
      (h|i|j)   # A group
    /x,
    [0]  => [WhiteSpace],
    [1]  => [Literal, to_s: 'a?', quantified?: true],
    [2]  => [WhiteSpace, text: '   '],
    [3]  => [WhiteSpace, text: '     '],
    [4]  => [Comment, to_s: "# One letter\n"],
    [5]  => [WhiteSpace],
    [6]  => [Literal, to_s: 'b{2,5}', quantified?: true],
    [7]  => [WhiteSpace, text: ' '],
    [8]  => [WhiteSpace, text: '   '],
    [9]  => [Comment, to_s: "# Another one\n"],
    [10] => [WhiteSpace],
    [11] => [CharacterSet, to_s: '[c-g]+', quantified?: true],
    [12] => [WhiteSpace],
    [13] => [WhiteSpace],
    [14] => [Comment, to_s: "# A set\n"],
    [15] => [WhiteSpace],
    [16] => [Group::Capture],
    [17] => [WhiteSpace],
    [18] => [Comment, to_s: "# A group\n",]

  include_examples 'parse', /
      a
      # comment 1
      ?
      (
       b # comment 2
       # comment 3
       +
      )
      # comment 4
      *
    /x,
    [0]    => [WhiteSpace],
    [1]    => [Literal, to_s: 'a?', quantified?: true],
    [2]    => [WhiteSpace],
    [3]    => [Comment],
    [4]    => [WhiteSpace],
    [5]    => [WhiteSpace],
    [6]    => [Group::Capture, quantified?: true],
    [6, 0] => [WhiteSpace],
    [6, 1] => [Literal, to_s: 'b+', quantified?: true],
    [6, 2] => [WhiteSpace],
    [6, 3] => [Comment, to_s: "# comment 2\n"],
    [6, 4] => [WhiteSpace],
    [6, 5] => [Comment, to_s: "# comment 3\n"],
    [6, 6] => [WhiteSpace],
    [6, 7] => [WhiteSpace]
end