File: table_tests.rb

package info (click to toggle)
ruby-formatador 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: ruby: 477; sh: 4; makefile: 2
file content (174 lines) | stat: -rw-r--r-- 4,266 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# coding: utf-8
Shindo.tests("Formatador: tables") do

output = <<-OUTPUT
    +---+
    | [bold]a[/] |
    +---+
    | 1 |
    +---+
    | 2 |
    +---+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{:a => 1}, {:a => 2}])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1}, {:a => 2}])
    end
  end

output = <<-OUTPUT
    +--------+
    | [bold]header[/] |
    +--------+
    +--------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([], [:header])").returns(output) do
    capture_stdout do
      Formatador.display_table([], [:header])
    end
  end

output = <<-OUTPUT
    +--------+
    | [bold]header[/] |
    +--------+
    |        |
    +--------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{:a => 1}], [:header])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1}], [:header])
    end
  end



output = <<-OUTPUT
    +---+------------+
    | [bold]a[/] | [bold]nested.key[/] |
    +---+------------+
    | 1 | value      |
    +---+------------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{:a => 1, :nested => {:key => 'value'}}], [:header, :'nested.key'])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1, :nested => {:key => 'value'}}], [:a, :'nested.key'])
    end
  end


if (RUBY_VERSION.split('.').map(&:to_i) <=> [3, 4, 0]).positive?
output = <<-OUTPUT
    +---+----------------+
    | [bold]a[/] | [bold]nested[/]         |
    +---+----------------+
    | 1 | {key: "value"} |
    +---+----------------+
OUTPUT
else
output = <<-OUTPUT
    +---+-----------------+
    | [bold]a[/] | [bold]nested[/]          |
    +---+-----------------+
    | 1 | {:key=>"value"} |
    +---+-----------------+
OUTPUT
end
output = Formatador.parse(output)

  tests("#display_table([{:a => 1, :nested => {:key => 'value'}}])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1, :nested => {:key => 'value'}}])
    end
  end

output = <<-OUTPUT
    +---+--------------+
    | [bold]a[/] | [bold]just.pointed[/] |
    +---+--------------+
    | 1 | value        |
    +---+--------------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{:a => 1, 'just.pointed' => :value}])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1, 'just.pointed' => :value}])
    end
  end

output = <<-OUTPUT
    +-------------------------+----------------+
    | [bold]right-justify a numeric[/] | [bold]standard value[/] |
    +-------------------------+----------------+
    |                   12345 | value          |
    +-------------------------+----------------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{'right-justify a numeric' => 12345, 'standard value' => 'standard value'}], numeric_rjust: true)").returns(output) do
    capture_stdout do
      Formatador.display_table([{'right-justify a numeric' => 12345, 'standard value' => 'value'}], numeric_rjust: true)
    end
  end

output = <<-OUTPUT
    +--------+------------+
    | [bold]header[/] | [bold]nested.key[/] |
    +--------+------------+
    |  12345 | value      |
    +--------+------------+
OUTPUT
output = Formatador.parse(output)

  tests("#display_table([{:header => 12345, :nested => {:key => value}}], [:header, :'nested.key'], numeric_rjust: true)").returns(output) do
    capture_stdout do
      Formatador.display_table([{:header => 12345, :nested => {:key => 'value'}}], [:header, :'nested.key'], numeric_rjust: true)
    end
  end


output = <<-OUTPUT
    +------+
    | [bold]a[/]    |
    +------+
    | 1    |
    +------+
    | 震度 |
    +------+
OUTPUT
  output = Formatador.parse(output)

  tests("#display_table([{:a => 1}, {:a => '震度'}])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1}, {:a => "震度"}])
    end
  end

output = <<-OUTPUT
    +----+
    | [bold]a[/]  |
    +----+
    | 1  |
    +----+
    | 🤷 |
    +----+
OUTPUT
  output = Formatador.parse(output)

  tests("#display_table([{:a => 1}, {:a => '🤷'}])").returns(output) do
    capture_stdout do
      Formatador.display_table([{:a => 1}, {:a => '🤷'}])
    end
  end


end