spec/lexer/regular_expressions_spec.rb in qlang-0.0.27180000 vs spec/lexer/regular_expressions_spec.rb in qlang-0.0.27182000
- old
+ new
@@ -1,12 +1,39 @@
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