• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

type-ruby / t-ruby / 20555908277

28 Dec 2025 03:36PM UTC coverage: 76.821% (+0.7%) from 76.168%
20555908277

Pull #27

github

web-flow
Merge 4641bd176 into ecaa30526
Pull Request #27: feat: implement keyword arguments syntax

181 of 185 new or added lines in 5 files covered. (97.84%)

5263 of 6851 relevant lines covered (76.82%)

1185.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.37
/lib/t_ruby/string_utils.rb
1
# frozen_string_literal: true
2

3
module TRuby
1✔
4
  # 문자열 파싱을 위한 공통 유틸리티 모듈
5
  # 파서와 컴파일러에서 공유하는 중첩 괄호 처리 로직
6
  module StringUtils
1✔
7
    module_function
1✔
8

9
    # 중첩된 괄호를 고려하여 콤마로 문자열 분리
10
    # @param content [String] 분리할 문자열
11
    # @return [Array<String>] 분리된 문자열 배열
12
    def split_by_comma(content)
1✔
13
      result = []
20✔
14
      current = ""
20✔
15
      depth = 0
20✔
16

17
      content.each_char do |char|
20✔
18
        case char
538✔
19
        when "<", "[", "(", "{"
20
          depth += 1
4✔
21
          current += char
4✔
22
        when ">", "]", ")", "}"
23
          depth -= 1
4✔
24
          current += char
4✔
25
        when ","
26
          if depth.zero?
14✔
27
            result << current.strip
14✔
28
            current = ""
14✔
29
          else
NEW
30
            current += char
×
31
          end
32
        else
33
          current += char
516✔
34
        end
35
      end
36

37
      result << current.strip unless current.empty?
20✔
38
      result
20✔
39
    end
40

41
    # 타입과 기본값 분리: "String = 0" -> ["String", "0"]
42
    # 중첩된 괄호 내부의 = 는 무시
43
    # @param type_and_default [String] "Type = default" 형태의 문자열
44
    # @return [Array] [type_str, default_value] 또는 [type_str, nil]
45
    def split_type_and_default(type_and_default)
1✔
46
      depth = 0
3,620✔
47
      equals_pos = nil
3,620✔
48

49
      type_and_default.each_char.with_index do |char, i|
3,620✔
50
        case char
21,854✔
51
        when "<", "[", "(", "{"
52
          depth += 1
3✔
53
        when ">", "]", ")", "}"
54
          depth -= 1
3✔
55
        when "="
56
          if depth.zero?
13✔
57
            equals_pos = i
13✔
58
            break
13✔
59
          end
60
        end
61
      end
62

63
      if equals_pos
3,620✔
64
        type_str = type_and_default[0...equals_pos].strip
13✔
65
        default_value = type_and_default[(equals_pos + 1)..].strip
13✔
66
        [type_str, default_value]
13✔
67
      else
68
        [type_and_default, nil]
3,607✔
69
      end
70
    end
71

72
    # 기본값만 추출 (타입은 버림)
73
    # @param type_and_default [String] "Type = default" 형태의 문자열
74
    # @return [String, nil] 기본값 또는 nil
75
    def extract_default_value(type_and_default)
1✔
76
      _, default_value = split_type_and_default(type_and_default)
12✔
77
      default_value
12✔
78
    end
79
  end
80
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc