File: spec_helper.rb

package info (click to toggle)
ruby-regexp-parser 2.11.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,092 kB
  • sloc: ruby: 6,891; makefile: 6; sh: 3
file content (79 lines) | stat: -rw-r--r-- 1,591 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
79
# frozen_string_literal: true

$VERBOSE = true

require 'regexp_property_values'
require_relative 'support/capturing_stderr'
require_relative 'support/shared_examples'

req_warn = capturing_stderr { @required_now = require('regexp_parser') }
req_warn.empty? || fail("requiring parser generated warnings:\n#{req_warn}")
@required_now || fail("regexp_parser was required earlier than expected")

RS = Regexp::Scanner
RL = Regexp::Lexer
RP = Regexp::Parser
RE = Regexp::Expression
T = Regexp::Syntax::Token

include Regexp::Expression

def ruby_version_at_least(version)
  Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new(version)
end

RSpec.configure do |config|
  config.around(:example) do |example|
    # treat unexpected warnings as failures
    expect { example.run }.not_to output.to_stderr
  end
end

def s(klass, text = '', *children)
  exp = klass.construct(text: text.to_s)
  children.each { |child| exp.expressions << child }
  exp
end

def regexp_with_all_features
  return /dummy/ unless ruby_version_at_least('2.4.1')

  Regexp.new(<<-'REGEXP', Regexp::EXTENDED)
    \A
    a++
    (?:
      \b {2}
      (?>
        c ??
        πŸ˜€πŸ˜€πŸ˜€
        # πŸ˜„πŸ˜„πŸ˜„
        (?# πŸ˜ƒπŸ˜ƒπŸ˜ƒ )
        (
          \d *+
          (
            ALT1
            |
            ALT2
          )
        ) {004}
        |
        [Γ€-ΓΌ&&ΓΆ[:ascii:]\p{thai}] {6}
        |
        \z
      )
      (?=lm{8}) ?+
      \K
      (?~
        \1
        \g<-1> {10}
        \uFFFF
        \012
      )
      (?(1)
        BRANCH1
        |
        BRANCH2
      )
    )
  REGEXP
end