File: conditional_spec.rb

package info (click to toggle)
ruby-regexp-parser 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 6,396; sh: 12; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 915 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
require 'spec_helper'

RSpec.describe(Regexp::Expression::Conditional) do
  specify('Conditional#condition, #branches') do
    conditional = RP.parse(/(?<A>a)(?(<A>)T|F)/)[1]
    expect(conditional.condition).to eq conditional[0]
    expect(conditional.branches).to eq conditional[1..2]
  end

  specify('Condition#referenced_expression') do
    root = RP.parse(/(?<A>a)(?(<A>)T|F)/)
    condition = root[1].condition
    expect(condition.referenced_expression).to eq root[0]
    expect(condition.referenced_expression.to_s).to eq '(?<A>a)'

    root = RP.parse(/(a)(?(1)T|F)/)
    condition = root[1].condition
    expect(condition.referenced_expression).to eq root[0]
    expect(condition.referenced_expression.to_s).to eq '(a)'
  end

  specify('parse conditional excessive branches') do
    regexp = '(?<A>a)(?(<A>)T|F|X)'

    expect { RP.parse(regexp) }.to raise_error(Conditional::TooManyBranches)
  end
end