File: test_runner_parse.rb

package info (click to toggle)
ruby-whitequark-parser 3.3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,848 kB
  • sloc: yacc: 40,706; ruby: 20,588; makefile: 12; sh: 8
file content (70 lines) | stat: -rw-r--r-- 1,724 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
# frozen_string_literal: true

require 'helper'
require 'open3'

class TestRunnerParse < Minitest::Test
  PATH_TO_RUBY_PARSE = File.expand_path('../bin/ruby-parse', __dir__).freeze

  def assert_prints(argv, expected_output)
    stdout, _stderr, status = Open3.capture3(PATH_TO_RUBY_PARSE, *argv)

    assert_equal 0, status.to_i
    assert_includes(stdout, expected_output)
  end

  def test_emit_ruby
    assert_prints ['--emit-ruby', '-e 123'],
                  's(:int, 123)'
  end

  def test_emit_modern_ruby
    assert_prints ['-e', '->{}'],
                  '(lambda)'
    assert_prints ['-e', 'self[1] = 2'],
                  'indexasgn'
  end

  def test_emit_legacy
    assert_prints ['--legacy', '-e', '->{}'],
                  '(send nil :lambda)'
    assert_prints ['--legacy', '-e', 'self[1] = 2'],
                  ':[]='
  end

  def test_emit_legacy_lambda
    assert_prints ['--legacy-lambda', '-e', '->{}'],
                  '(send nil :lambda)'
    assert_prints ['--legacy-lambda', '-e', 'self[1] = 2'],
                  'indexasgn'
  end

  def test_emit_json
    assert_prints ['--emit-json', '-e', '123'],
                  '["int",123]'
  end

  def test_emit_ruby_empty
    assert_prints ['--emit-ruby', '-e', ''],
                  "\n"
  end

  def test_emit_json_empty
    assert_prints ['--emit-json', '-e', ''],
                  "\n"
  end

  def test_stdin_input
    assert_prints ['--emit-ruby', '-', { stdin_data: '123' }],
                  's(:int, 123)'
  end

  def test_folder_with_rb_extension
    Dir.mktmpdir do |tmp_dir|
      Dir.mkdir("#{tmp_dir}/foo.rb")
      File.write("#{tmp_dir}/foo.rb/bar.rb", "123")

      assert_prints [tmp_dir], '(int 123)'
    end
  end
end