Class: Unparser::Validation
- Inherits:
-
Object
- Object
- Unparser::Validation
- Includes:
- Adamantium
- Defined in:
- lib/unparser/validation.rb
Overview
Validation of unparser results
Direct Known Subclasses
Defined Under Namespace
Classes: Literal
Class Method Summary collapse
-
.from_node(original_node) ⇒ Validator
Create validator from node.
-
.from_path(path) ⇒ Validator
Create validator from file.
-
.from_string(original_source) ⇒ Validator
Create validator from string.
Instance Method Summary collapse
-
#report ⇒ String
private
Return error report.
-
#success? ⇒ Boolean
private
Test if source could be unparsed successfully.
Class Method Details
.from_node(original_node) ⇒ Validator
Create validator from node
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/unparser/validation.rb', line 81 def self.from_node(original_node) generated_source = Unparser.unparse_either(original_node) generated_node = generated_source .lmap(&method(:const_unit)) .bind(&Unparser.public_method(:parse_either)) new( identification: '(string)', original_source: generated_source, original_node: Either::Right.new(original_node), generated_source: generated_source, generated_node: generated_node ) end |
.from_path(path) ⇒ Validator
Create validator from file
102 103 104 |
# File 'lib/unparser/validation.rb', line 102 def self.from_path(path) from_string(path.read).with(identification: path.to_s) end |
.from_string(original_source) ⇒ Validator
Create validator from string
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/unparser/validation.rb', line 55 def self.from_string(original_source) original_node = Unparser .parse_either(original_source) generated_source = original_node .lmap(&method(:const_unit)) .bind(&Unparser.method(:unparse_either)) generated_node = generated_source .lmap(&method(:const_unit)) .bind(&Unparser.method(:parse_either)) new( identification: '(string)', original_source: Either::Right.new(original_source), original_node: original_node, generated_source: generated_source, generated_node: generated_node ) end |
Instance Method Details
#report ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return error report
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/unparser/validation.rb', line 37 def report = [identification] .concat(make_report('Original-Source', :original_source)) .concat(make_report('Generated-Source', :generated_source)) .concat(make_report('Original-Node', :original_node)) .concat(make_report('Generated-Node', :generated_node)) .concat(node_diff_report) .join("\n") end |
#success? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test if source could be unparsed successfully
rubocop:disable Style/OperatorMethodCall
21 22 23 24 25 26 27 28 |
# File 'lib/unparser/validation.rb', line 21 def success? [ original_source, original_node, generated_source, generated_node ].all?(&:right?) && generated_node.from_right.==(original_node.from_right) end |