Sha256: 93a902c5e73def6972bd5e2a1d6dbf8b4ab842914df4bc286d8013ed86af9c78

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

include Lexer::Tokens

describe 'Regular expressions' do
  def self.should_match(num, rgx, str)
    it 'ex' + num.to_s do
      expect(rgx =~ str).to eq(0)
      expect($&).to eq(str)
    end
  end

  def self.should_not_match(num, rgx, str)
    it 'ex' + num.to_s do
      expect(rgx =~ str).not_to eq(0)
    end
  end

  describe 'tokens' do
    describe 'nums' do
      should_match(1, NUM, '1')
      should_match(2, NUM, '234987423')
      should_match(3, NUM, '23423948.298743')
      should_match(4, NUM, 'e')
      should_match(5, NUM, 'pi')
      should_not_match(6, NUM, 'a')
    end
    describe 'vars' do
      # should_match(1, VAR_MUL, 'ab')
      # should_not_match(2, VAR_MUL, 'pi')
      # should_not_match(3, VAR_MUL, 'sin')
    end
  end


  describe 'function' do
    should_match(1, /[fgh]\(\w( ?, ?\w)*\) ?= ?[^\r\n]+/, 'f(x) = xy')
  end

  describe 'differentiate' do
    rgx = /d\/d[a-zA-Z] .*/
    should_match(1, rgx, 'd/dx sin(x)')
    should_match(2, rgx, 'd/dz z^2')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qlang-0.0.27182000 spec/lexer/regular_expressions_spec.rb