Project

General

Profile

Feature #18242 ยป driver.rb

Improved driver, more cases and error info - danh337 (Dan H), 10/09/2021 02:39 AM

 
1
#!/usr/bin/env ruby
2

    
3
lines = [
4
  "a = 2, 1     if 1 < 2",
5
  "a = [2, 1]   if 1 < 2",
6
  "(a = 2, 1)   if 1 < 2",
7
  "(a = [2, 1]) if 1 < 2",
8
  "a = 2, 1     unless 2 < 1",
9
  "a = [2, 1]   unless 2 < 1",
10
  "(a = 2, 1)   unless 2 < 1",
11
  "(a = [2, 1]) unless 2 < 1",
12
  "a, b = 2, 1     if 1 < 2",
13
  "a, b = [2, 1]   if 1 < 2",
14
  "(a, b) = 2, 1   if 1 < 2",
15
  "(a, b) = [2, 1] if 1 < 2",
16
  "(a, b = 2, 1)   if 1 < 2",
17
  "(a, b = [2, 1]) if 1 < 2",
18
  "a, b = 2, 1     unless 2 < 1",
19
  "a, b = [2, 1]   unless 2 < 1",
20
  "(a, b) = 2, 1   unless 2 < 1",
21
  "(a, b) = [2, 1] unless 2 < 1",
22
  "(a, b = 2, 1)   unless 2 < 1",
23
  "(a, b = [2, 1]) unless 2 < 1",
24
  "1 < 2   and a = 2, 1",
25
  "1 < 2   and a = [2, 1]",
26
  "1 < 2   and (a = 2, 1)",
27
  "1 < 2   and (a = [2, 1])",
28
  "(1 < 2) and a = 2, 1",
29
  "(1 < 2) and a = [2, 1]",
30
  "(1 < 2) and (a = 2, 1)",
31
  "(1 < 2) and (a = [2, 1])",
32
  "1 < 2   and a, b = 2, 1",
33
  "1 < 2   and a, b = [2, 1]",
34
  "1 < 2   and (a, b) = 2, 1",
35
  "1 < 2   and (a, b) = [2, 1]",
36
  "1 < 2   and (a, b = 2, 1)",
37
  "1 < 2   and (a, b = [2, 1])",
38
  "(1 < 2) and a, b = 2, 1",
39
  "(1 < 2) and a, b = [2, 1]",
40
  "(1 < 2) and (a, b) = 2, 1",
41
  "(1 < 2) and (a, b) = [2, 1]",
42
  "(1 < 2) and (a, b = 2, 1)",
43
  "(1 < 2) and (a, b = [2, 1])",
44
  "2 < 1   or a = 2, 1",
45
  "2 < 1   or a = [2, 1]",
46
  "2 < 1   or (a = 2, 1)",
47
  "2 < 1   or (a = [2, 1])",
48
  "(2 < 1) or a = 2, 1",
49
  "(2 < 1) or a = [2, 1]",
50
  "(2 < 1) or (a = 2, 1)",
51
  "(2 < 1) or (a = [2, 1])",
52
  "2 < 1   or a, b = 2, 1",
53
  "2 < 1   or a, b = [2, 1]",
54
  "2 < 1   or (a, b) = 2, 1",
55
  "2 < 1   or (a, b) = [2, 1]",
56
  "2 < 1   or (a, b = 2, 1)",
57
  "2 < 1   or (a, b = [2, 1])",
58
  "(2 < 1) or a, b = 2, 1",
59
  "(2 < 1) or a, b = [2, 1]",
60
  "(2 < 1) or (a, b) = 2, 1",
61
  "(2 < 1) or (a, b) = [2, 1]",
62
  "(2 < 1) or (a, b = 2, 1)",
63
  "(2 < 1) or (a, b = [2, 1])"
64
]
65

    
66
width = lines.map(&:size).max
67

    
68
for line in lines
69
  begin
70
    a = b = nil
71
    eval line
72
    raise "Value mismatched" unless [[2, 1], [[2, 1], nil]].member?([a, b])
73
    comment = "Works"
74
  rescue Exception => e
75
    comment = "#{e.class}: #{e.message.each_line.first&.chomp}"
76
  end
77
  puts "%-#{width}s # #{comment}" % line
78
end