marktable 0.0.2 → 0.0.3
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 +4 -4
- data/lib/marktable.rb +4 -0
- data/spec/support/matchers/markdown_matchers.rb +75 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5511339f01122f8adb6afe93a836eb2f5278786ab11d289682eca258f044567c
|
4
|
+
data.tar.gz: bb4ea8e3fd5e9bdbdf4b119c77da6907e225d4bdcae91281c3aab0514a665b7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95d08a37b3e158597fc8c7b8d492aa618437010a4c72381b166952ba7fca5aeb9b4d55f993da2caec41524e1122fe162cb6cb2c2ba7cae5c818aa6038c2ae832
|
7
|
+
data.tar.gz: 55ccc61117f6e9d11097996716d76b0825f6e07329610e6b7fc6f063261cc0b1a482a5af92f787a830568c1533de02e5135bef97c448b65a7390dbb142b002cc
|
data/lib/marktable.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
require_relative 'marktable/row'
|
4
4
|
require_relative 'marktable/table'
|
5
5
|
|
6
|
+
if defined?(RSpec)
|
7
|
+
require_relative '../spec/support/matchers/markdown_matchers'
|
8
|
+
end
|
9
|
+
|
6
10
|
module Marktable
|
7
11
|
# Parse a markdown table string into an array of rows
|
8
12
|
def self.parse(markdown_table, headers: true)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec::Matchers.define :match_markdown do |expected_markdown|
|
4
|
+
match do |actual|
|
5
|
+
# Handle markdown string, array of hashes, and Marktable::Table objects
|
6
|
+
actual_data = case actual
|
7
|
+
when String
|
8
|
+
Marktable.parse(actual)
|
9
|
+
when Marktable::Table
|
10
|
+
actual.to_a
|
11
|
+
else
|
12
|
+
actual
|
13
|
+
end
|
14
|
+
|
15
|
+
expected_data = Marktable.parse(expected_markdown)
|
16
|
+
|
17
|
+
# Normalize data by trimming whitespace in cell values
|
18
|
+
normalize = ->(data) {
|
19
|
+
data.map do |row|
|
20
|
+
if row.is_a?(Hash)
|
21
|
+
row.transform_values { |v| v.to_s.strip }
|
22
|
+
else
|
23
|
+
row.map { |v| v.to_s.strip }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
actual_data = normalize.call(actual_data)
|
29
|
+
expected_data = normalize.call(expected_data)
|
30
|
+
|
31
|
+
# Compare the parsed data structures
|
32
|
+
actual_data == expected_data
|
33
|
+
end
|
34
|
+
|
35
|
+
failure_message do |actual|
|
36
|
+
# Parse data for comparison output
|
37
|
+
actual_data = case actual
|
38
|
+
when String
|
39
|
+
Marktable.parse(actual)
|
40
|
+
when Marktable::Table
|
41
|
+
actual.to_a
|
42
|
+
else
|
43
|
+
actual
|
44
|
+
end
|
45
|
+
expected_data = Marktable.parse(expected_markdown)
|
46
|
+
|
47
|
+
# Format both tables properly for display
|
48
|
+
actual_formatted = Marktable.table(actual_data).to_s
|
49
|
+
expected_formatted = Marktable.table(expected_data).to_s
|
50
|
+
|
51
|
+
"Expected markdown table to match:\n\n" \
|
52
|
+
"Expected:\n#{expected_formatted}\n\n" \
|
53
|
+
"Actual:\n#{actual_formatted}\n\n" \
|
54
|
+
"Parsed expected data: #{expected_data.inspect}\n" \
|
55
|
+
"Parsed actual data: #{actual_data.inspect}"
|
56
|
+
end
|
57
|
+
|
58
|
+
failure_message_when_negated do |actual|
|
59
|
+
# Parse data for comparison output
|
60
|
+
actual_data = case actual
|
61
|
+
when String
|
62
|
+
Marktable.parse(actual)
|
63
|
+
when Marktable::Table
|
64
|
+
actual.to_a
|
65
|
+
else
|
66
|
+
actual
|
67
|
+
end
|
68
|
+
|
69
|
+
# Generate properly formatted markdown for display
|
70
|
+
actual_formatted = Marktable.table(actual_data).to_s
|
71
|
+
|
72
|
+
"Expected markdown tables to differ, but they match:\n\n" \
|
73
|
+
"#{actual_formatted}"
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marktable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francois Gaspard
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/marktable.rb
|
37
37
|
- lib/marktable/row.rb
|
38
38
|
- lib/marktable/table.rb
|
39
|
+
- spec/support/matchers/markdown_matchers.rb
|
39
40
|
homepage: https://github.com/Francois-gaspard/marktable
|
40
41
|
licenses:
|
41
42
|
- MIT
|