test_bench-output 2.0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/test_bench/output/controls/data.rb +42 -0
- data/lib/test_bench/output/controls/detail.rb +22 -0
- data/lib/test_bench/output/controls/device.rb +27 -0
- data/lib/test_bench/output/controls/events.rb +7 -0
- data/lib/test_bench/output/controls/output.rb +45 -0
- data/lib/test_bench/output/controls/random.rb +7 -0
- data/lib/test_bench/output/controls/result.rb +7 -0
- data/lib/test_bench/output/controls/style.rb +31 -0
- data/lib/test_bench/output/controls/styling.rb +22 -0
- data/lib/test_bench/output/controls/text.rb +32 -0
- data/lib/test_bench/output/controls.rb +12 -0
- data/lib/test_bench/output/device/null.rb +19 -0
- data/lib/test_bench/output/device/substitute.rb +61 -0
- data/lib/test_bench/output/digest.rb +91 -0
- data/lib/test_bench/output/output.rb +335 -0
- data/lib/test_bench/output/writer/buffer/console.rb +184 -0
- data/lib/test_bench/output/writer/buffer.rb +48 -0
- data/lib/test_bench/output/writer/defaults.rb +11 -0
- data/lib/test_bench/output/writer/style.rb +50 -0
- data/lib/test_bench/output/writer/substitute.rb +28 -0
- data/lib/test_bench/output/writer.rb +266 -0
- data/lib/test_bench/output.rb +17 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fb58227223c8abb68522bff5b4af2946eb2fb6c47e6f6fbc133ee1da18b8fa9d
|
4
|
+
data.tar.gz: 465d3286eae938f746daa2aa27563a0228ae75072698cae85bf34e44b5cb0470
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cbb111e63fb42e142442c64de35668ceb32b14478ccc7016543be1dab5ce0060b236e6df7c7df2946311aa7eb78d423899eedc269f0fe8f20e8335e3472e129
|
7
|
+
data.tar.gz: 5c99c2ce3f0c926b92b631b99664ff41a7271ee5b78e6a5c685e1644bb94737ca86dfa77496042ea2f7c597f57a54c1f66a29a4dc2d6c09c99293ec639681a7d
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Data
|
5
|
+
def self.example(suffix=nil)
|
6
|
+
suffix = "-#{suffix}" if not suffix.nil?
|
7
|
+
|
8
|
+
"some-data#{suffix}"
|
9
|
+
end
|
10
|
+
def self.random = example(Random.string)
|
11
|
+
|
12
|
+
module Digest
|
13
|
+
def self.example
|
14
|
+
'0123456789:;<=>'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.digest
|
18
|
+
0x3031323334353637 + 0x0038393A3B3C3D3E
|
19
|
+
end
|
20
|
+
|
21
|
+
module Equivalent
|
22
|
+
module SameLength
|
23
|
+
def self.example
|
24
|
+
'0123456789:;<=>'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.digest = Digest.digest
|
28
|
+
end
|
29
|
+
|
30
|
+
module DifferentLength
|
31
|
+
def self.example
|
32
|
+
[Digest.digest].pack('Q>')
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.digest = Digest.digest
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Detail
|
5
|
+
def self.example = TestBench::Output::Detail.on
|
6
|
+
def self.other_example = TestBench::Output::Detail.off
|
7
|
+
|
8
|
+
def self.random
|
9
|
+
details = [
|
10
|
+
TestBench::Output::Detail.on,
|
11
|
+
TestBench::Output::Detail.off,
|
12
|
+
TestBench::Output::Detail.failure
|
13
|
+
]
|
14
|
+
|
15
|
+
index = Random.integer % details.count
|
16
|
+
|
17
|
+
details[index]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Device
|
5
|
+
def self.example
|
6
|
+
TestBench::Output::Device::Substitute.build
|
7
|
+
end
|
8
|
+
|
9
|
+
module TTY
|
10
|
+
def self.example(tty: nil)
|
11
|
+
tty = true if tty.nil?
|
12
|
+
|
13
|
+
device = Device.example
|
14
|
+
device.tty! if tty
|
15
|
+
device
|
16
|
+
end
|
17
|
+
|
18
|
+
module Non
|
19
|
+
def self.example
|
20
|
+
TTY.example(tty: false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Output
|
5
|
+
def self.example(details: nil, styling: nil, mode: nil)
|
6
|
+
styling ||= false
|
7
|
+
|
8
|
+
output = TestBench::Output.new
|
9
|
+
|
10
|
+
if details == true
|
11
|
+
output.detail_policy = TestBench::Output::Detail.on
|
12
|
+
elsif details == false
|
13
|
+
output.detail_policy = TestBench::Output::Detail.off
|
14
|
+
else
|
15
|
+
output.detail_policy = TestBench::Output::Detail.failure
|
16
|
+
end
|
17
|
+
|
18
|
+
if styling
|
19
|
+
output.writer.styling!
|
20
|
+
end
|
21
|
+
|
22
|
+
if not mode.nil?
|
23
|
+
output.mode = mode
|
24
|
+
end
|
25
|
+
|
26
|
+
output
|
27
|
+
end
|
28
|
+
|
29
|
+
module Styling
|
30
|
+
def self.example
|
31
|
+
Output.example(styling: true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Pending
|
36
|
+
def self.example
|
37
|
+
output = Styling.example
|
38
|
+
output.pending_writer.buffer.limit = nil
|
39
|
+
output
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Style
|
5
|
+
def self.example
|
6
|
+
:bold
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.other_example
|
10
|
+
:italic
|
11
|
+
end
|
12
|
+
|
13
|
+
module Unknown
|
14
|
+
def self.example
|
15
|
+
:unknown
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Code
|
20
|
+
def self.example
|
21
|
+
'1'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.other_example
|
25
|
+
'3'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Styling
|
5
|
+
def self.example = Writer::Styling.on
|
6
|
+
def self.other_example = Writer::Styling.off
|
7
|
+
|
8
|
+
def self.random
|
9
|
+
stylings = [
|
10
|
+
Writer::Styling.on,
|
11
|
+
Writer::Styling.off,
|
12
|
+
Writer::Styling.detect
|
13
|
+
]
|
14
|
+
|
15
|
+
index = Random.integer % stylings.count
|
16
|
+
|
17
|
+
stylings[index]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Controls
|
4
|
+
module Text
|
5
|
+
def self.example(suffix=nil)
|
6
|
+
suffix = " #{suffix}" if not suffix.nil?
|
7
|
+
|
8
|
+
"Some text#{suffix}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.random = example(Random.string)
|
12
|
+
|
13
|
+
module NonPrintableCharacters
|
14
|
+
def self.example
|
15
|
+
characters.map(&:chr).join
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.characters
|
19
|
+
(0..0x20).to_a + (0x7F..0xFF).to_a
|
20
|
+
end
|
21
|
+
|
22
|
+
module Escaped
|
23
|
+
def self.example
|
24
|
+
unescaped = NonPrintableCharacters.example
|
25
|
+
unescaped.dump[1...-1]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_bench/session/controls'
|
2
|
+
|
3
|
+
require 'test_bench/output/controls/random'
|
4
|
+
require 'test_bench/output/controls/data'
|
5
|
+
require 'test_bench/output/controls/device'
|
6
|
+
require 'test_bench/output/controls/text'
|
7
|
+
require 'test_bench/output/controls/styling'
|
8
|
+
require 'test_bench/output/controls/style'
|
9
|
+
require 'test_bench/output/controls/result'
|
10
|
+
require 'test_bench/output/controls/detail'
|
11
|
+
require 'test_bench/output/controls/events'
|
12
|
+
require 'test_bench/output/controls/output'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
module Device
|
4
|
+
module Substitute
|
5
|
+
def self.build
|
6
|
+
Device.new
|
7
|
+
end
|
8
|
+
|
9
|
+
class Device
|
10
|
+
def written_data
|
11
|
+
@written_data ||= String.new
|
12
|
+
end
|
13
|
+
attr_writer :written_data
|
14
|
+
|
15
|
+
def flushed_data
|
16
|
+
@flushed_data ||= String.new
|
17
|
+
end
|
18
|
+
attr_writer :flushed_data
|
19
|
+
|
20
|
+
def tty
|
21
|
+
@tty ||= false
|
22
|
+
end
|
23
|
+
alias :tty? :tty
|
24
|
+
attr_writer :tty
|
25
|
+
|
26
|
+
def write(data)
|
27
|
+
bytes_written = data.bytesize
|
28
|
+
|
29
|
+
written_data << data
|
30
|
+
|
31
|
+
bytes_written
|
32
|
+
end
|
33
|
+
|
34
|
+
def flush
|
35
|
+
flushed_data << written_data
|
36
|
+
end
|
37
|
+
|
38
|
+
def written?(data=nil)
|
39
|
+
if data.nil?
|
40
|
+
!written_data.empty?
|
41
|
+
else
|
42
|
+
written_data == data
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def flushed?(data=nil)
|
47
|
+
if data.nil?
|
48
|
+
!flushed_data.empty?
|
49
|
+
else
|
50
|
+
flushed_data == data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def tty!
|
55
|
+
self.tty = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Output
|
3
|
+
class Digest
|
4
|
+
def last_digest
|
5
|
+
@last_digest ||= 0
|
6
|
+
end
|
7
|
+
attr_writer :last_digest
|
8
|
+
|
9
|
+
def buffer
|
10
|
+
@buffer ||= String.new(encoding: 'BINARY', capacity: Defaults.size_bytes * 2)
|
11
|
+
end
|
12
|
+
attr_writer :buffer
|
13
|
+
|
14
|
+
def self.digest(data)
|
15
|
+
instance = new
|
16
|
+
instance.update(data)
|
17
|
+
instance.digest
|
18
|
+
end
|
19
|
+
|
20
|
+
def clone
|
21
|
+
cloned_digest = Digest.new
|
22
|
+
cloned_digest.last_digest = last_digest
|
23
|
+
cloned_digest.buffer << buffer
|
24
|
+
cloned_digest
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(data)
|
28
|
+
digest_size_bytes = Defaults.size_bytes
|
29
|
+
|
30
|
+
(0..data.bytesize).step(digest_size_bytes).each do |position|
|
31
|
+
next_bytes = data.byteslice(position, digest_size_bytes)
|
32
|
+
next_bytes.force_encoding('BINARY')
|
33
|
+
|
34
|
+
buffer << next_bytes
|
35
|
+
|
36
|
+
if buffer.length >= digest_size_bytes
|
37
|
+
self.last_digest = digest
|
38
|
+
|
39
|
+
buffer.slice!(0, 8)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
digest
|
44
|
+
end
|
45
|
+
|
46
|
+
def digest
|
47
|
+
buffer_bytes = buffer.unpack('C*')[0...8]
|
48
|
+
|
49
|
+
buffer_int64 = buffer_bytes.reduce(0) do |int64, byte|
|
50
|
+
(int64 << 8) | byte
|
51
|
+
end
|
52
|
+
|
53
|
+
(last_digest + buffer_int64) % (256 ** Defaults.size_bytes - 1)
|
54
|
+
end
|
55
|
+
alias :value :digest
|
56
|
+
alias :to_i :digest
|
57
|
+
|
58
|
+
def digest?(data)
|
59
|
+
other_digest = self.class.digest(data)
|
60
|
+
|
61
|
+
digest == other_digest
|
62
|
+
end
|
63
|
+
|
64
|
+
def format
|
65
|
+
self.class.format(value)
|
66
|
+
end
|
67
|
+
alias :to_s :format
|
68
|
+
|
69
|
+
def self.format(digest)
|
70
|
+
if digest < 0
|
71
|
+
# 0x8000...
|
72
|
+
sign_mask = 0x1 << (8 * Defaults.size_bytes - 1)
|
73
|
+
# 0x7FFF...
|
74
|
+
mask = (256 ** Defaults.size_bytes - 1) ^ sign_mask
|
75
|
+
|
76
|
+
digest_uint64 = ~digest & mask | sign_mask
|
77
|
+
else
|
78
|
+
digest_uint64 = digest
|
79
|
+
end
|
80
|
+
|
81
|
+
"0x%016X" % digest_uint64
|
82
|
+
end
|
83
|
+
|
84
|
+
module Defaults
|
85
|
+
def self.size_bytes
|
86
|
+
8
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|