File: var_test.rb

package info (click to toggle)
ruby-byebug 11.1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,252 kB
  • sloc: ruby: 8,835; ansic: 1,662; sh: 6; makefile: 4
file content (111 lines) | stat: -rw-r--r-- 2,923 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests variable evaluation.
  #
  class VarTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  module Byebug
         2:    #
         3:    # Toy class to test variable evaluation.
         4:    #
         5:    class #{example_class}
         6:      SOMECONST = "foo" unless defined?(SOMECONST)
         7:
         8:      def initialize
         9:        @instance_variable = "1" * 20
        10:        byebug
        11:      end
        12:
        13:      def run(level)
        14:        [1, 2, 3].map do |i|
        15:          level * i
        16:        end
        17:      end
        18:    end
        19:
        20:    v = #{example_class}.new
        21:    v.run(2)
        22:  end
      RUBY
    end

    def test_var_args_shows_information_about_current_frame_arguments
      enter "break 14", "cont", "var args"
      debug_code(program)

      check_output_includes "level = 2"
    end

    def test_var_const_shows_constants_in_class_or_module
      enter "var const Byebug::#{example_class}"
      debug_code(program)

      check_output_includes "SOMECONST = foo"
    end

    def test_var_const_shows_constants_in_current_scope_when_without_argument
      enter "var const"
      debug_code(program)

      check_output_includes "SOMECONST = foo"
    end

    def test_var_const_shows_error_if_given_object_is_not_a_class_or_module
      enter "break 21", "cont", "var const v"
      debug_code(program)

      check_error_includes "Should be Class/Module: v"
    end

    def test_var_instance_shows_instance_vars_of_an_object
      enter "break 21", "cont", "var instance v"
      debug_code(program)

      check_output_includes '@instance_variable = "11111111111111111111"'
    end

    def test_var_global_shows_global_variables
      enter "var global"
      debug_code(program)

      check_output_includes "$ERROR_INFO = nil"
    end

    def test_var_instance_shows_instance_variables_of_self_if_no_object_given
      enter "var instance"
      debug_code(program)

      check_output_includes '@instance_variable = "11111111111111111111"'
    end

    def test_var_instance_cuts_long_variable_values_according_to_width_setting
      with_setting :width, 40 do
        enter "var instance"
        debug_code(program)

        check_output_includes '@instance_variable = "111111111111111...'
      end
    end

    def test_var_local_shows_local_variables
      enter "break 15", "cont", "var local"
      debug_code(program)

      check_output_includes "i = 1", "level = 2"
    end

    def test_var_all_shows_all_variables
      enter "break 15", "cont", "var all"
      debug_code(program)

      check_output_includes "$ERROR_INFO = nil",
                            '@instance_variable = "11111111111111111111"',
                            "level = 2"
    end
  end
end