File indexing completed on 2024-05-05 04:36:54
0001 ## 0002 # This file is part of KDevelop 0003 # Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 # 0005 # This program is free software: you can redistribute it and/or modify 0006 # it under the terms of the GNU General Public License as published by 0007 # the Free Software Foundation, either version 3 of the License, or 0008 # (at your option) any later version. 0009 # 0010 # This program is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 # GNU General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU General Public License 0016 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 0018 0019 # Returns a String containing the absolute path to the ruby parser. 0020 def parser 0021 File.join(File.dirname(__FILE__), '../ruby-parser') 0022 end 0023 0024 describe 'Parser' do 0025 base = File.dirname(__FILE__) 0026 0027 # Regular tests 0028 files = Dir[File.join(base, 'tests/*.rb')] 0029 files.each do |file| 0030 name = file.match(/.*\/(.+)+\.rb$/)[1] 0031 0032 it "test: `#{name}'" do 0033 expected = File.read "#{base}/tests/#{name}.txt" 0034 expect(`#{parser} #{base}/tests/#{name}.rb`).to eq(expected) 0035 end 0036 end 0037 0038 # Testing that the comments are stored properly. 0039 it 'test: `comments\'' do 0040 expected = File.read "#{base}/tests/comments/expected.txt" 0041 expect(`#{parser} #{base}/tests/comments/test.rb 2`).to eq(expected) 0042 end 0043 0044 # Testing the warnings on incompatible Ruby versions. 0045 context 'Ruby versions:' do 0046 it '1.8.x -> 1.9.x transition' do 0047 output = `#{parser} #{base}/tests/errors/from18to19.rb 0` 0048 expect(output).to eq(<<-HEREDOC.gsub(/^\s+/, '') 0049 Line: 1, Column: 16; This syntax is only available in Ruby 1.9.x or higher. 0050 Line: 2, Column: 4; "->" syntax is only available in Ruby 1.9.x or higher. 0051 Line: 3, Column: 15; Block local variables are only available in Ruby 1.9.x or higher. 0052 HEREDOC 0053 ) 0054 end 0055 0056 it '1.9.x -> 2.0.x transition' do 0057 output = `#{parser} #{base}/tests/errors/from19to20.rb 0` 0058 expect(output).to eq(<<-HEREDOC.gsub(/^\s+/, '') 0059 Line: 1, Column: 22; Keyword arguments are only available in Ruby 2.0.x or higher. 0060 Line: 4, Column: 21; Keyword arguments are only available in Ruby 2.0.x or higher. 0061 Line: 9, Column: 9; This syntax is only available in Ruby 1.9.x or higher. 0062 Line: 9, Column: 15; This syntax is only available in Ruby 1.9.x or higher. 0063 Line: 11, Column: 25; Keyword arguments are only available in Ruby 2.0.x or higher. 0064 Line: 14, Column: 46; Keyword arguments are only available in Ruby 2.0.x or higher. 0065 Line: 17, Column: 2; This shortcut is only available in Ruby 2.0.x or higher. 0066 HEREDOC 0067 ) 0068 end 0069 0070 it '2.0.x -> 2.1.x transition' do 0071 output = `#{parser} #{base}/tests/errors/from20to21.rb 0` 0072 expect(output).to eq(<<-HEREDOC.gsub(/^\s+/, '') 0073 Line: 2, Column: 8; Imaginary literals are only available in Ruby 2.1.x or higher. 0074 Line: 3, Column: 8; Rational literals are only available in Ruby 2.1.x or higher. 0075 HEREDOC 0076 ) 0077 end 0078 end 0079 end