psychgus 1.3.5 → 1.3.6
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/.yardopts +0 -1
- data/CHANGELOG.md +14 -4
- data/Gemfile +4 -5
- data/README.md +14 -14
- data/Rakefile +3 -23
- data/lib/psychgus/blueberry.rb +1 -1
- data/lib/psychgus/ext/core_ext.rb +1 -1
- data/lib/psychgus/ext/yaml_tree_ext.rb +1 -2
- data/lib/psychgus/stylables.rb +7 -7
- data/lib/psychgus/styled_document_stream.rb +1 -1
- data/lib/psychgus/styled_tree_builder.rb +2 -2
- data/lib/psychgus/version.rb +1 -1
- data/lib/psychgus.rb +9 -6
- data/psychgus.gemspec +10 -7
- data/test/blueberry_test.rb +57 -58
- data/test/psychgus_test.rb +33 -34
- data/test/sniffer_test.rb +6 -6
- data/test/styler_test.rb +32 -33
- data/test/stylers_test.rb +25 -25
- data/test/{psychgus_tester.rb → test_helper.rb} +8 -8
- metadata +6 -6
- data/yard/templates/default/layout/html/footer.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01544ac84a4c500d36c933328b920f43bbe878609d10f60c615d6ccccf7ca9da
|
4
|
+
data.tar.gz: 2856f8d12ebe3881513acfbb4ec8da5af40fd98a35a36b9ec227260643c2193e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e41a6e5b84bd23527583e6cbd46db820e8c53e67d241a85e08182770114ee1ee0e57d2b706ca87acd42367fe27001d1de61a67ae9e700211823948ff780c4f
|
7
|
+
data.tar.gz: 558601409148d719e718a4132f703ad46b06bbb7f19f0ce1d46befd3021051c714a4a6bc0613766ae7d05294f312764b4e1f6b82ba65c13da92a5990210ef136
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
# Changelog | Psychgus
|
2
2
|
|
3
|
-
|
3
|
+
- [Keep a Changelog v1.0.0](https://keepachangelog.com/en/1.0.0)
|
4
|
+
- [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html)
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
## [Unreleased]
|
7
|
+
- https://github.com/esotericpig/psychgus/compare/v1.3.6...HEAD
|
7
8
|
|
8
|
-
|
9
|
+
|
10
|
+
## [v1.3.6] - 2025-05-01
|
11
|
+
### Fixed
|
12
|
+
- Fixed deref aliases for Psych v5.2.0+.
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Renamed `master` branch to `main`.
|
16
|
+
- Applied RuboCop suggestions.
|
17
|
+
- Refactored tests.
|
18
|
+
- Removed `yard_ghurt` gem.
|
9
19
|
|
10
20
|
|
11
21
|
## [v1.3.5] - 2024-09-06
|
data/Gemfile
CHANGED
@@ -3,16 +3,15 @@
|
|
3
3
|
|
4
4
|
source 'https://rubygems.org'
|
5
5
|
|
6
|
-
group(:development) do
|
6
|
+
group(:development,:test) do
|
7
7
|
# Build.
|
8
|
-
gem 'bundler' ,'~> 2.
|
8
|
+
gem 'bundler' ,'~> 2.6'
|
9
9
|
gem 'rake' ,'~> 13.2'
|
10
10
|
|
11
11
|
# Doc.
|
12
|
-
gem 'rdoc' ,'~> 6.
|
13
|
-
gem 'redcarpet' ,'~> 3.6' # Markdown
|
12
|
+
gem 'rdoc' ,'~> 6.13' # RDoc (*.rb).
|
13
|
+
gem 'redcarpet' ,'~> 3.6' # Markdown (*.md).
|
14
14
|
gem 'yard' ,'~> 0.9' # Doc.
|
15
|
-
gem 'yard_ghurt','~> 1.2' # YARD GitHub rake tasks.
|
16
15
|
end
|
17
16
|
|
18
17
|
group(:test) do
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/psychgus)
|
4
4
|
[](https://github.com/esotericpig/psychgus/actions/workflows/ci.yml)
|
5
|
-
[](https://inch-ci.org/github/esotericpig/psychgus)
|
6
6
|
|
7
7
|
[](https://esotericpig.github.io/docs/psychgus/yardoc/index.html)
|
8
8
|
[](https://github.com/esotericpig/psychgus)
|
@@ -59,7 +59,7 @@ The Psychgus name comes from the well-styled character Gus from the TV show Psyc
|
|
59
59
|
- [Generating Doc](#generating-doc)
|
60
60
|
- [License](#license)
|
61
61
|
|
62
|
-
##
|
62
|
+
## Setup
|
63
63
|
|
64
64
|
Pick your poison...
|
65
65
|
|
@@ -93,7 +93,7 @@ $ bundle install
|
|
93
93
|
$ bundle exec rake install:local
|
94
94
|
```
|
95
95
|
|
96
|
-
##
|
96
|
+
## Using
|
97
97
|
|
98
98
|
Documentation (YARDoc) is available on my [GitHub Page](https://esotericpig.github.io/docs/psychgus/yardoc/index.html) and on [RubyDoc.info](https://www.rubydoc.info/gems/psychgus).
|
99
99
|
|
@@ -111,7 +111,7 @@ Instead of making your own styler, you can also use one of the [pre-defined styl
|
|
111
111
|
| [Advanced Usage](#advanced-usage)
|
112
112
|
| [Common Stylers](#common-stylers)
|
113
113
|
|
114
|
-
###
|
114
|
+
### Simple Example
|
115
115
|
|
116
116
|
```Ruby
|
117
117
|
require 'psychgus'
|
@@ -157,7 +157,7 @@ puts Coffee.new.to_yaml
|
|
157
157
|
# style: [Cappuccino, Espresso, Latte, Mocha]
|
158
158
|
```
|
159
159
|
|
160
|
-
###
|
160
|
+
### Hash Example
|
161
161
|
|
162
162
|
```Ruby
|
163
163
|
require 'psychgus'
|
@@ -252,7 +252,7 @@ puts burgers.to_yaml({:indent => 3,:stylers => BurgerStyler.new,:deref_aliases =
|
|
252
252
|
# Bun: Kaiser
|
253
253
|
```
|
254
254
|
|
255
|
-
###
|
255
|
+
### Class Example
|
256
256
|
|
257
257
|
```Ruby
|
258
258
|
require 'psychgus'
|
@@ -423,7 +423,7 @@ puts burgers.to_yaml({:indent => 3,:deref_aliases => true})
|
|
423
423
|
# Sauce: 'Honey BBQ'
|
424
424
|
```
|
425
425
|
|
426
|
-
###
|
426
|
+
### Advanced Usage
|
427
427
|
|
428
428
|
```Ruby
|
429
429
|
require 'psychgus'
|
@@ -514,7 +514,7 @@ puts parser.handler.root.to_ruby
|
|
514
514
|
puts
|
515
515
|
```
|
516
516
|
|
517
|
-
###
|
517
|
+
### Common Stylers
|
518
518
|
|
519
519
|
A collection of commonly-used [Stylers](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers.html) and [Stylables](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylables.html) are included with Psychgus.
|
520
520
|
|
@@ -527,7 +527,7 @@ A collection of commonly-used [Stylers](https://esotericpig.github.io/docs/psych
|
|
527
527
|
| [NoTagStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/NoTagStyler.html) | Tag remover for classes |
|
528
528
|
| [SeqFlowStyler](https://esotericpig.github.io/docs/psychgus/yardoc/Psychgus/Stylers/SeqFlowStyler.html) | FLOW style changer for Sequences only |
|
529
529
|
|
530
|
-
####
|
530
|
+
#### Stylers Example
|
531
531
|
|
532
532
|
```Ruby
|
533
533
|
require 'psychgus'
|
@@ -571,7 +571,7 @@ puts EggCarton.new.to_yaml
|
|
571
571
|
# - green
|
572
572
|
```
|
573
573
|
|
574
|
-
##
|
574
|
+
## Hacking
|
575
575
|
|
576
576
|
```
|
577
577
|
$ git clone 'https://github.com/esotericpig/psychgus.git'
|
@@ -580,13 +580,13 @@ $ bundle install
|
|
580
580
|
$ bundle exec rake -T
|
581
581
|
```
|
582
582
|
|
583
|
-
###
|
583
|
+
### Testing
|
584
584
|
|
585
585
|
Run tests:
|
586
586
|
|
587
587
|
`$ bundle exec rake test`
|
588
588
|
|
589
|
-
###
|
589
|
+
### Generating Doc
|
590
590
|
|
591
591
|
Generate doc:
|
592
592
|
|
@@ -596,12 +596,12 @@ Clean & generate pristine doc:
|
|
596
596
|
|
597
597
|
`$ bundle exec rake clobber doc`
|
598
598
|
|
599
|
-
##
|
599
|
+
## License
|
600
600
|
|
601
601
|
[GNU LGPL v3+](LICENSE.txt)
|
602
602
|
|
603
603
|
> Psychgus (<https://github.com/esotericpig/psychgus>)
|
604
|
-
> Copyright (c) 2017-
|
604
|
+
> Copyright (c) 2017-2025 Bradley Whited
|
605
605
|
>
|
606
606
|
> Psychgus is free software: you can redistribute it and/or modify
|
607
607
|
> it under the terms of the GNU Lesser General Public License as published by
|
data/Rakefile
CHANGED
@@ -4,29 +4,26 @@
|
|
4
4
|
require 'bundler/gem_tasks'
|
5
5
|
|
6
6
|
require 'yard'
|
7
|
-
require 'yard_ghurt'
|
8
7
|
|
9
8
|
require 'psychgus/version'
|
10
|
-
|
11
9
|
require 'rake/clean'
|
12
10
|
require 'rake/testtask'
|
13
11
|
|
14
|
-
task default: [
|
12
|
+
task default: %i[test]
|
15
13
|
|
16
14
|
CLEAN.exclude('.git/','stock/')
|
17
15
|
CLOBBER.include('doc/')
|
18
16
|
|
19
17
|
# Execute "rake clobber doc" for pristine docs.
|
20
18
|
desc 'Generate documentation (YARDoc)'
|
21
|
-
task doc: %i[yard
|
19
|
+
task doc: %i[yard]
|
22
20
|
|
23
21
|
# To test using different Gem versions:
|
24
22
|
# GST=1 bundle update && bundle exec rake test
|
25
23
|
Rake::TestTask.new do |task|
|
26
24
|
task.libs = ['lib','test']
|
27
25
|
task.pattern = File.join('test','**','*_test.rb')
|
28
|
-
task.
|
29
|
-
#task.options = '--verbose' # Execute "rake test TESTOPT=-v" instead.
|
26
|
+
# task.options = '--verbose' # Execute "rake test TESTOPT=-v" instead.
|
30
27
|
task.verbose = true
|
31
28
|
task.warning = true
|
32
29
|
end
|
@@ -34,20 +31,3 @@ end
|
|
34
31
|
YARD::Rake::YardocTask.new do |task|
|
35
32
|
task.files = [File.join('lib','**','*.rb')]
|
36
33
|
end
|
37
|
-
|
38
|
-
YardGhurt::GFMFixTask.new do |task|
|
39
|
-
task.description = 'Fix (find & replace) text in the YARD files for GitHub differences'
|
40
|
-
|
41
|
-
task.arg_names = [:dev]
|
42
|
-
task.dry_run = false
|
43
|
-
task.fix_code_langs = true
|
44
|
-
task.md_files = ['index.html']
|
45
|
-
|
46
|
-
task.before = proc do |t2,args|
|
47
|
-
# Delete this file as it's never used (index.html is an exact copy)
|
48
|
-
YardGhurt.rm_exist(File.join(t2.doc_dir,'file.README.html'))
|
49
|
-
|
50
|
-
t2.css_styles << '<link rel="stylesheet" type="text/css" href="/css/prism.css" />'
|
51
|
-
t2.js_scripts << '<script src="/js/prism.js"></script>)'
|
52
|
-
end
|
53
|
-
end
|
data/lib/psychgus/blueberry.rb
CHANGED
@@ -51,7 +51,7 @@ module Psychgus
|
|
51
51
|
# @return [String] the YAML generated from this Object
|
52
52
|
#
|
53
53
|
# @see Psychgus.dump
|
54
|
-
def to_yaml(options={})
|
54
|
+
def to_yaml(options = {})
|
55
55
|
# NOTE: This method signature must use old-style `options={}` instead of `**options`!
|
56
56
|
# Because some Gems, like `Moneta`, depend on this.
|
57
57
|
|
@@ -33,7 +33,6 @@ module Psychgus
|
|
33
33
|
else # 5.1.2+
|
34
34
|
return unless key?(target)
|
35
35
|
|
36
|
-
@targets.delete(target)
|
37
36
|
@obj_to_node.delete(target)
|
38
37
|
end
|
39
38
|
end
|
@@ -81,7 +80,7 @@ module Psychgus
|
|
81
80
|
@st.psychgus_unregister(target) if @emitter.deref_aliases?
|
82
81
|
end
|
83
82
|
|
84
|
-
result = super(target)
|
83
|
+
result = super(target) # rubocop:disable Style/SuperArguments
|
85
84
|
|
86
85
|
# Check styler_count because @emitter may not be a StyledTreeBuilder and target may not be a Blueberry
|
87
86
|
@emitter.pop_styler(styler_count) if styler_count > 0
|
data/lib/psychgus/stylables.rb
CHANGED
@@ -38,7 +38,7 @@ module Psychgus
|
|
38
38
|
# @param min_level [Integer] the minimum level (inclusive) to style
|
39
39
|
# @param new_style [Integer] the new style to set the nodes to
|
40
40
|
# @param kargs [Hash] capture extra keyword args, so no error for undefined args
|
41
|
-
def initialize(min_level=0,new_style: nil,**
|
41
|
+
def initialize(min_level = 0,new_style: nil,**_kargs)
|
42
42
|
@min_level = min_level
|
43
43
|
@new_style = new_style
|
44
44
|
end
|
@@ -67,7 +67,7 @@ module Psychgus
|
|
67
67
|
# @param new_delim [nil,String] the replacement for each +delim+ if not nil
|
68
68
|
# @param delim [String,Regexp] the delimiter to split on
|
69
69
|
# @param kargs [Hash] capture extra keyword args, so no error for undefined args
|
70
|
-
def initialize(each_word: true,new_delim: nil,delim: /[\s_\-]/,**
|
70
|
+
def initialize(each_word: true,new_delim: nil,delim: /[\s_\-]/,**_kargs)
|
71
71
|
delim = Regexp.quote(delim.to_s) unless delim.is_a?(Regexp)
|
72
72
|
|
73
73
|
@delim = Regexp.new("(#{delim})")
|
@@ -95,7 +95,7 @@ module Psychgus
|
|
95
95
|
#
|
96
96
|
# @see cap_word
|
97
97
|
# @see Styler#style_scalar
|
98
|
-
def style_scalar(
|
98
|
+
def style_scalar(_sniffer,node)
|
99
99
|
if !@each_word || node.value.nil? || node.value.empty?
|
100
100
|
node.value = cap_word(node.value)
|
101
101
|
return
|
@@ -128,7 +128,7 @@ module Psychgus
|
|
128
128
|
# @param io [IO] the IO to write to
|
129
129
|
# @param verbose [true,false] whether to be more verbose (e.g., write child info)
|
130
130
|
# @param kargs [Hash] capture extra keyword args, so no error for undefined args
|
131
|
-
def initialize(io: StringIO.new,verbose: false,**
|
131
|
+
def initialize(io: StringIO.new,verbose: false,**_kargs)
|
132
132
|
@io = io
|
133
133
|
@verbose = verbose
|
134
134
|
end
|
@@ -199,14 +199,14 @@ module Psychgus
|
|
199
199
|
|
200
200
|
# @param cap [true,false] whether to capitalize the symbol
|
201
201
|
# @param kargs [Hash] capture extra keyword args, so no error for undefined args
|
202
|
-
def initialize(cap: true,**
|
202
|
+
def initialize(cap: true,**_kargs)
|
203
203
|
@cap = cap
|
204
204
|
end
|
205
205
|
|
206
206
|
# If +node.value+ is a symbol, change it into a string and capitalize it.
|
207
207
|
#
|
208
208
|
# @see Styler#style_scalar
|
209
|
-
def style_scalar(
|
209
|
+
def style_scalar(_sniffer,node)
|
210
210
|
return if node.value.nil? || node.value.empty?
|
211
211
|
return if node.value[0] != ':'
|
212
212
|
|
@@ -224,7 +224,7 @@ module Psychgus
|
|
224
224
|
# If +node.tag+ is settable, set it to nil.
|
225
225
|
#
|
226
226
|
# @see Styler#style
|
227
|
-
def style(
|
227
|
+
def style(_sniffer,node)
|
228
228
|
node.tag = nil if node.respond_to?(:tag=)
|
229
229
|
end
|
230
230
|
end
|
@@ -35,7 +35,7 @@ module Psychgus
|
|
35
35
|
# This mimics the behavior of Psych::Handlers::DocumentStream#end_document.
|
36
36
|
#
|
37
37
|
# @see Psych::Handlers::DocumentStream#end_document
|
38
|
-
def end_document(implicit_end
|
38
|
+
def end_document(implicit_end = !streaming?)
|
39
39
|
@last.implicit_end = implicit_end
|
40
40
|
@block.call(pop)
|
41
41
|
end
|
@@ -37,7 +37,7 @@ module Psychgus
|
|
37
37
|
# @param stylers [Styler] {Styler}(s) to use for styling this TreeBuilder
|
38
38
|
# @param deref_aliases [true,false] whether to dereference aliases; output the actual value
|
39
39
|
# instead of the alias
|
40
|
-
def initialize(*stylers,deref_aliases: false,**
|
40
|
+
def initialize(*stylers,deref_aliases: false,**_options)
|
41
41
|
super()
|
42
42
|
|
43
43
|
@deref_aliases = deref_aliases
|
@@ -143,7 +143,7 @@ module Psychgus
|
|
143
143
|
# @param count [Integer] the optional amount of tail elements to pop
|
144
144
|
#
|
145
145
|
# @return [Styler,Array<Styler>,nil] the last {Styler}(s), or if empty or count==0, nil
|
146
|
-
def pop_styler(count=1)
|
146
|
+
def pop_styler(count = 1)
|
147
147
|
return nil if count == 0
|
148
148
|
return @stylers.pop if count == 1
|
149
149
|
|
data/lib/psychgus/version.rb
CHANGED
data/lib/psychgus.rb
CHANGED
@@ -332,7 +332,7 @@ module Psychgus
|
|
332
332
|
# @return [Integer,Object] the constant value from the class (usually an int)
|
333
333
|
#
|
334
334
|
# @see .node_class
|
335
|
-
def self.node_const(class_name,const_name,lenient
|
335
|
+
def self.node_const(class_name,const_name,lenient: true)
|
336
336
|
node_class = node_class(class_name)
|
337
337
|
const_name = const_name.to_sym.upcase
|
338
338
|
|
@@ -378,7 +378,7 @@ module Psychgus
|
|
378
378
|
#
|
379
379
|
# @see .dump_stream
|
380
380
|
# @see Psych.dump_stream
|
381
|
-
def self.dump(object,io=nil,**options)
|
381
|
+
def self.dump(object,io = nil,**options)
|
382
382
|
return dump_stream(object,io: io,**options)
|
383
383
|
end
|
384
384
|
|
@@ -467,8 +467,10 @@ module Psychgus
|
|
467
467
|
end
|
468
468
|
end
|
469
469
|
|
470
|
-
visitor = Psych::Visitors::YAMLTree.create(
|
471
|
-
|
470
|
+
visitor = Psych::Visitors::YAMLTree.create(
|
471
|
+
options,
|
472
|
+
StyledTreeBuilder.new(*stylers,deref_aliases: deref_aliases)
|
473
|
+
)
|
472
474
|
|
473
475
|
if objects.empty?
|
474
476
|
# Else, will throw a cryptic NoMethodError:
|
@@ -681,8 +683,9 @@ module Psychgus
|
|
681
683
|
# @see Psych::SyntaxError
|
682
684
|
def self.parse_stream(yaml,filename: nil,stylers: nil,deref_aliases: false,**options,&block)
|
683
685
|
if block_given?
|
684
|
-
parser = Psych::Parser.new(
|
685
|
-
|
686
|
+
parser = Psych::Parser.new(
|
687
|
+
StyledDocumentStream.new(*stylers,deref_aliases: deref_aliases,**options,&block)
|
688
|
+
)
|
686
689
|
|
687
690
|
return parser.parse(yaml,filename)
|
688
691
|
else
|
data/psychgus.gemspec
CHANGED
@@ -14,11 +14,12 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.description = 'Easily style YAML files using Psych, like Sequence/Mapping Flow style.'
|
15
15
|
|
16
16
|
spec.metadata = {
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
17
|
+
'rubygems_mfa_required' => 'true',
|
18
|
+
'homepage_uri' => 'https://github.com/esotericpig/psychgus',
|
19
|
+
'source_code_uri' => 'https://github.com/esotericpig/psychgus',
|
20
|
+
'bug_tracker_uri' => 'https://github.com/esotericpig/psychgus/issues',
|
21
|
+
'changelog_uri' => 'https://github.com/esotericpig/psychgus/blob/main/CHANGELOG.md',
|
22
|
+
'documentation_uri' => 'https://esotericpig.github.io/docs/psychgus/yardoc/index.html',
|
22
23
|
}
|
23
24
|
|
24
25
|
spec.required_ruby_version = '>= 2.2'
|
@@ -29,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
29
30
|
Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
|
30
31
|
Dir.glob(File.join(spec.bindir,'*')),
|
31
32
|
Dir.glob(File.join('{samples,test,yard}','**','*.{erb,rb}')),
|
32
|
-
%W[
|
33
|
-
%w[
|
33
|
+
%W[Gemfile #{spec.name}.gemspec Rakefile .yardopts],
|
34
|
+
%w[LICENSE.txt CHANGELOG.md README.md],
|
34
35
|
].flatten
|
35
36
|
|
36
37
|
# Test using different Gem versions:
|
@@ -41,6 +42,8 @@ Gem::Specification.new do |spec|
|
|
41
42
|
if !gemspec_test.empty?
|
42
43
|
case gemspec_test
|
43
44
|
when '1' then psych_gemv = '<= 5.1.1'
|
45
|
+
when '2' then psych_gemv = '5.1.2'
|
46
|
+
when '3' then psych_gemv = '5.2.0'
|
44
47
|
end
|
45
48
|
|
46
49
|
puts 'Using Gem versions:'
|
data/test/blueberry_test.rb
CHANGED
@@ -8,29 +8,39 @@
|
|
8
8
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
9
|
#++
|
10
10
|
|
11
|
-
require '
|
11
|
+
require 'test_helper'
|
12
12
|
|
13
|
-
class
|
14
|
-
|
15
|
-
|
16
|
-
attr_accessor :bun
|
17
|
-
attr_accessor :cheese
|
18
|
-
attr_accessor :sauce
|
19
|
-
|
20
|
-
def initialize(sauce,cheese,bun)
|
21
|
-
@bun = bun
|
22
|
-
@cheese = cheese
|
23
|
-
@sauce = sauce
|
13
|
+
class BlueberryTest < Minitest::Test
|
14
|
+
def setup
|
15
|
+
@burgers = Burgers.new
|
24
16
|
end
|
25
17
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
def test_blueberry
|
19
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
20
|
+
|--- !ruby/object:Burgers
|
21
|
+
|Burgers:
|
22
|
+
| Classic:
|
23
|
+
| 'Bun': 'Sesame Seed'
|
24
|
+
| 'Cheese': 'American'
|
25
|
+
| 'Sauce': ['Ketchup', 'Mustard']
|
26
|
+
| BBQ: {'Bun': 'Kaiser', 'Cheese': 'Cheddar', 'Sauce': 'Honey BBQ'}
|
27
|
+
| Fancy:
|
28
|
+
| 'Bun': 'Hawaiian'
|
29
|
+
| 'Cheese': 'Smoked Gouda'
|
30
|
+
| 'Sauce': 'Spicy Wasabi'
|
31
|
+
|Toppings:
|
32
|
+
|- Mushrooms
|
33
|
+
|- - Lettuce
|
34
|
+
| - Onions
|
35
|
+
| - Pickles
|
36
|
+
| - Tomatoes
|
37
|
+
|- - - Ketchup
|
38
|
+
| - Mustard
|
39
|
+
| - - Salt
|
40
|
+
| - Pepper
|
41
|
+
YAML
|
31
42
|
|
32
|
-
|
33
|
-
return BurgerStyler.new(sniffer)
|
43
|
+
assert_equal expected,@burgers.to_yaml
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
@@ -42,13 +52,13 @@ class Burgers
|
|
42
52
|
@burgers = {
|
43
53
|
'Classic' => Burger.new(['Ketchup','Mustard'],'American','Sesame Seed'),
|
44
54
|
'BBQ' => Burger.new('Honey BBQ','Cheddar','Kaiser'),
|
45
|
-
'Fancy' => Burger.new('Spicy Wasabi','Smoked Gouda','Hawaiian')
|
55
|
+
'Fancy' => Burger.new('Spicy Wasabi','Smoked Gouda','Hawaiian'),
|
46
56
|
}
|
47
57
|
|
48
58
|
@toppings = [
|
49
59
|
'Mushrooms',
|
50
60
|
%w[Lettuce Onions Pickles Tomatoes],
|
51
|
-
[%w[Ketchup Mustard],%w[Salt Pepper]]
|
61
|
+
[%w[Ketchup Mustard],%w[Salt Pepper]],
|
52
62
|
]
|
53
63
|
end
|
54
64
|
|
@@ -66,64 +76,53 @@ class BurgerStyler
|
|
66
76
|
@position = sniffer.position
|
67
77
|
end
|
68
78
|
|
69
|
-
def style(
|
70
|
-
# Remove ugly and unsafe
|
79
|
+
def style(_sniffer,node)
|
80
|
+
# Remove ugly and unsafe `!ruby/object:Burger`.
|
71
81
|
node.tag = nil if node.respond_to?(:tag)
|
72
82
|
end
|
73
83
|
|
74
84
|
def style_mapping(sniffer,node)
|
75
85
|
parent = sniffer.parent
|
76
86
|
|
77
|
-
if !parent.nil?
|
78
|
-
# BBQ
|
79
|
-
node.style = Psychgus::MAPPING_FLOW
|
87
|
+
if !parent.nil? && parent.respond_to?(:value) && parent.value.casecmp('BBQ') == 0
|
88
|
+
# BBQ.
|
89
|
+
node.style = Psychgus::MAPPING_FLOW
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
|
-
def style_scalar(
|
84
|
-
# Only for Burgers
|
93
|
+
def style_scalar(_sniffer,node)
|
94
|
+
# Only for Burgers.
|
85
95
|
node.style = Psychgus::SCALAR_SINGLE_QUOTED
|
86
96
|
end
|
87
97
|
|
88
98
|
def style_sequence(sniffer,node)
|
89
99
|
relative_level = (sniffer.level - @level) + 1
|
90
100
|
|
91
|
-
# [Ketchup, Mustard]
|
101
|
+
# [Ketchup, Mustard].
|
92
102
|
node.style = Psychgus::SEQUENCE_FLOW if relative_level == 3
|
93
103
|
end
|
94
104
|
end
|
95
105
|
|
96
|
-
class
|
97
|
-
|
98
|
-
|
106
|
+
class Burger
|
107
|
+
include Psychgus::Blueberry
|
108
|
+
|
109
|
+
attr_accessor :bun
|
110
|
+
attr_accessor :cheese
|
111
|
+
attr_accessor :sauce
|
112
|
+
|
113
|
+
def initialize(sauce,cheese,bun)
|
114
|
+
@bun = bun
|
115
|
+
@cheese = cheese
|
116
|
+
@sauce = sauce
|
99
117
|
end
|
100
118
|
|
101
|
-
def
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
| 'Bun': 'Sesame Seed'
|
107
|
-
| 'Cheese': 'American'
|
108
|
-
| 'Sauce': ['Ketchup', 'Mustard']
|
109
|
-
| BBQ: {'Bun': 'Kaiser', 'Cheese': 'Cheddar', 'Sauce': 'Honey BBQ'}
|
110
|
-
| Fancy:
|
111
|
-
| 'Bun': 'Hawaiian'
|
112
|
-
| 'Cheese': 'Smoked Gouda'
|
113
|
-
| 'Sauce': 'Spicy Wasabi'
|
114
|
-
|Toppings:
|
115
|
-
|- Mushrooms
|
116
|
-
|- - Lettuce
|
117
|
-
| - Onions
|
118
|
-
| - Pickles
|
119
|
-
| - Tomatoes
|
120
|
-
|- - - Ketchup
|
121
|
-
| - Mustard
|
122
|
-
| - - Salt
|
123
|
-
| - Pepper
|
124
|
-
YAML
|
125
|
-
expected = self.class.lstrip_pipe(expected)
|
119
|
+
def encode_with(coder)
|
120
|
+
coder['Bun'] = @bun
|
121
|
+
coder['Cheese'] = @cheese
|
122
|
+
coder['Sauce'] = @sauce
|
123
|
+
end
|
126
124
|
|
127
|
-
|
125
|
+
def psychgus_stylers(sniffer)
|
126
|
+
return BurgerStyler.new(sniffer)
|
128
127
|
end
|
129
128
|
end
|
data/test/psychgus_test.rb
CHANGED
@@ -8,23 +8,11 @@
|
|
8
8
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
9
|
#++
|
10
10
|
|
11
|
-
require '
|
11
|
+
require 'test_helper'
|
12
12
|
|
13
13
|
require 'tempfile'
|
14
14
|
|
15
|
-
class
|
16
|
-
include Psychgus::Styler
|
17
|
-
|
18
|
-
def style_mapping(sniffer,node)
|
19
|
-
node.style = Psychgus::MAPPING_FLOW if sniffer.level >= 4
|
20
|
-
end
|
21
|
-
|
22
|
-
def style_sequence(sniffer,node)
|
23
|
-
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class PsychgusTest < PsychgusTester
|
15
|
+
class PsychgusTest < Minitest::Test
|
28
16
|
EXPECTED_BURGERS = <<-YAML
|
29
17
|
---
|
30
18
|
Burgers:
|
@@ -42,7 +30,7 @@ Toppings:
|
|
42
30
|
end
|
43
31
|
|
44
32
|
def test_alias
|
45
|
-
expected = <<-YAML
|
33
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
46
34
|
|---
|
47
35
|
|Dolphins:
|
48
36
|
| Common: {Length: "~2.5m", Weight: "~235kg"}
|
@@ -53,25 +41,25 @@ Toppings:
|
|
53
41
|
|- {Length: "~4m", Weight: "~300kg"}
|
54
42
|
|- {Length: "~7m", Weight: "~3600kg"}
|
55
43
|
YAML
|
56
|
-
expected = self.class.lstrip_pipe(expected)
|
57
44
|
|
58
|
-
assert_equal expected,DOLPHINS_DATA.to_yaml(deref_aliases: true,stylers: @flow_styler)
|
45
|
+
assert_equal expected,TestHelper::DOLPHINS_DATA.to_yaml(deref_aliases: true,stylers: @flow_styler)
|
59
46
|
end
|
60
47
|
|
61
48
|
def test_dump
|
62
|
-
assert_equal EXPECTED_BURGERS,Psychgus.dump(BURGERS_DATA,stylers: @flow_styler)
|
63
|
-
assert_equal EXPECTED_BURGERS,Psychgus.dump_stream(BURGERS_DATA,stylers: @flow_styler)
|
64
|
-
assert_equal EXPECTED_BURGERS,BURGERS_DATA.to_yaml(stylers: @flow_styler)
|
49
|
+
assert_equal EXPECTED_BURGERS,Psychgus.dump(TestHelper::BURGERS_DATA,stylers: @flow_styler)
|
50
|
+
assert_equal EXPECTED_BURGERS,Psychgus.dump_stream(TestHelper::BURGERS_DATA,stylers: @flow_styler)
|
51
|
+
assert_equal EXPECTED_BURGERS,TestHelper::BURGERS_DATA.to_yaml(stylers: @flow_styler)
|
65
52
|
end
|
66
53
|
|
67
54
|
def test_file
|
68
55
|
Tempfile.create(['Psychgus','.yaml']) do |file|
|
69
|
-
#puts "Testing #{self.class.name} w/ temp file: #{file.path}"
|
56
|
+
# puts "Testing #{self.class.name} w/ temp file: #{file.path}"
|
70
57
|
|
71
|
-
Psychgus.dump_file(
|
58
|
+
Psychgus.dump_file(
|
59
|
+
file,TestHelper::BURGERS_DATA,
|
72
60
|
mode: File::CREAT | File::RDWR,
|
73
61
|
opt: {textmode: true},
|
74
|
-
#perm: 644, # Unix only
|
62
|
+
# perm: 644, # Unix only
|
75
63
|
stylers: @flow_styler,
|
76
64
|
)
|
77
65
|
|
@@ -94,8 +82,8 @@ Toppings:
|
|
94
82
|
end
|
95
83
|
|
96
84
|
def test_indent
|
97
|
-
# Indent of 3 spaces
|
98
|
-
expected = <<-YAML
|
85
|
+
# Indent of 3 spaces, like a crazy person.
|
86
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
99
87
|
|---
|
100
88
|
|Burgers:
|
101
89
|
| Classic: {Sauce: [Ketchup, Mustard], Cheese: American, Bun: Sesame Seed}
|
@@ -106,13 +94,12 @@ Toppings:
|
|
106
94
|
|- [Lettuce, Onions, Pickles, Tomatoes]
|
107
95
|
|- [[Ketchup, Mustard], [Salt, Pepper]]
|
108
96
|
YAML
|
109
|
-
expected = self.class.lstrip_pipe(expected)
|
110
97
|
|
111
98
|
# rubocop:disable Style/HashSyntax
|
112
|
-
assert_equal expected,BURGERS_DATA.to_yaml(indent: 3,stylers: @flow_styler)
|
113
|
-
assert_equal expected,BURGERS_DATA.to_yaml(**{:indent => 3,:stylers => @flow_styler})
|
114
|
-
assert_equal expected,BURGERS_DATA.to_yaml(indentation: 3,stylers: @flow_styler)
|
115
|
-
assert_equal expected,BURGERS_DATA.to_yaml(**{:indentation => 3,:stylers => @flow_styler})
|
99
|
+
assert_equal expected,TestHelper::BURGERS_DATA.to_yaml(indent: 3,stylers: @flow_styler)
|
100
|
+
assert_equal expected,TestHelper::BURGERS_DATA.to_yaml(**{:indent => 3,:stylers => @flow_styler})
|
101
|
+
assert_equal expected,TestHelper::BURGERS_DATA.to_yaml(indentation: 3,stylers: @flow_styler)
|
102
|
+
assert_equal expected,TestHelper::BURGERS_DATA.to_yaml(**{:indentation => 3,:stylers => @flow_styler})
|
116
103
|
# rubocop:enable all
|
117
104
|
end
|
118
105
|
|
@@ -140,15 +127,27 @@ Toppings:
|
|
140
127
|
|
141
128
|
def test_parse
|
142
129
|
parser = Psychgus.parser(stylers: @flow_styler)
|
143
|
-
parser.parse(BURGERS_YAML)
|
144
|
-
yaml = "---\n
|
130
|
+
parser.parse(TestHelper::BURGERS_YAML)
|
131
|
+
yaml = "---\n#{parser.handler.root.to_yaml}"
|
145
132
|
assert_equal EXPECTED_BURGERS,yaml
|
146
133
|
|
147
|
-
node = Psychgus.parse(BURGERS_YAML,stylers: @flow_styler)
|
134
|
+
node = Psychgus.parse(TestHelper::BURGERS_YAML,stylers: @flow_styler)
|
148
135
|
refute_equal false,node
|
149
136
|
|
150
|
-
yaml = Psychgus.parse_stream(BURGERS_YAML,stylers: @flow_styler).to_yaml
|
137
|
+
yaml = Psychgus.parse_stream(TestHelper::BURGERS_YAML,stylers: @flow_styler).to_yaml
|
151
138
|
yaml = "---\n#{yaml}"
|
152
139
|
assert_equal EXPECTED_BURGERS,yaml
|
153
140
|
end
|
154
141
|
end
|
142
|
+
|
143
|
+
class FlowStyler
|
144
|
+
include Psychgus::Styler
|
145
|
+
|
146
|
+
def style_mapping(sniffer,node)
|
147
|
+
node.style = Psychgus::MAPPING_FLOW if sniffer.level >= 4
|
148
|
+
end
|
149
|
+
|
150
|
+
def style_sequence(sniffer,node)
|
151
|
+
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
|
152
|
+
end
|
153
|
+
end
|
data/test/sniffer_test.rb
CHANGED
@@ -8,23 +8,23 @@
|
|
8
8
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
9
|
#++
|
10
10
|
|
11
|
-
require '
|
11
|
+
require 'test_helper'
|
12
12
|
|
13
13
|
require 'stringio'
|
14
14
|
|
15
|
-
class SnifferTest <
|
15
|
+
class SnifferTest < Minitest::Test
|
16
16
|
def setup
|
17
17
|
end
|
18
18
|
|
19
19
|
def assert_hierarchy(*data,expected)
|
20
|
-
expected =
|
20
|
+
expected = TestHelper.lstrip_pipe(expected)
|
21
21
|
hierarchy = Psychgus.hierarchy(*data,verbose: true)
|
22
22
|
|
23
23
|
assert_equal expected,hierarchy
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_multi_doc
|
27
|
-
assert_hierarchy(BURGERS_DATA,COURSES_DATA,DOLPHINS_DATA,<<-HIER)
|
27
|
+
assert_hierarchy(TestHelper::BURGERS_DATA,TestHelper::COURSES_DATA,TestHelper::DOLPHINS_DATA,<<-HIER)
|
28
28
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
29
29
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
30
30
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
@@ -145,7 +145,7 @@ class SnifferTest < PsychgusTester
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def test_single_docs
|
148
|
-
assert_hierarchy(BURGERS_DATA,<<-HIER)
|
148
|
+
assert_hierarchy(TestHelper::BURGERS_DATA,<<-HIER)
|
149
149
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
150
150
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
151
151
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
@@ -194,7 +194,7 @@ class SnifferTest < PsychgusTester
|
|
194
194
|
| (6:2):Pepper - <seq:(5:2)::(:2)>
|
195
195
|
HIER
|
196
196
|
|
197
|
-
assert_hierarchy(COURSES_DATA,<<-HIER)
|
197
|
+
assert_hierarchy(TestHelper::COURSES_DATA,<<-HIER)
|
198
198
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
199
199
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
200
200
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
data/test/styler_test.rb
CHANGED
@@ -8,7 +8,34 @@
|
|
8
8
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
9
|
#++
|
10
10
|
|
11
|
-
require '
|
11
|
+
require 'test_helper'
|
12
|
+
|
13
|
+
class StylerTest < Minitest::Test
|
14
|
+
def setup
|
15
|
+
@styler = MyStyler.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_styler
|
19
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
20
|
+
|---
|
21
|
+
|Burgers:
|
22
|
+
| Classic:
|
23
|
+
| Sauce:
|
24
|
+
| - Ketchup
|
25
|
+
| - Mustard
|
26
|
+
| Cheese: American
|
27
|
+
| Bun: Sesame Seed
|
28
|
+
| BBQ: {Sauce: Honey BBQ, Cheese: Cheddar, Bun: Kaiser}
|
29
|
+
| Fancy: {Sauce: Spicy Wasabi, Cheese: Smoked Gouda, Bun: Hawaiian}
|
30
|
+
|Toppings:
|
31
|
+
|- 'Mushrooms'
|
32
|
+
|- [Spinach, Onions, Pickles, Tomatoes]
|
33
|
+
|- [[Ketchup, Mustard], [Salt, Pepper]]
|
34
|
+
YAML
|
35
|
+
|
36
|
+
assert_equal expected,TestHelper::BURGERS_DATA.to_yaml(stylers: @styler)
|
37
|
+
end
|
38
|
+
end
|
12
39
|
|
13
40
|
class MyStyler
|
14
41
|
include Psychgus::Styler
|
@@ -23,15 +50,15 @@ class MyStyler
|
|
23
50
|
parent = sniffer.parent
|
24
51
|
|
25
52
|
if !parent.nil?
|
26
|
-
# BBQ
|
53
|
+
# BBQ.
|
27
54
|
node.style = Psychgus::MAPPING_FLOW if parent.node_of?(:scalar) && parent.value.casecmp('BBQ') == 0
|
28
55
|
|
29
|
-
# Fancy
|
56
|
+
# Fancy.
|
30
57
|
node.style = Psychgus::MAPPING_FLOW if parent.level == 4 && parent.position == 3
|
31
58
|
end
|
32
59
|
end
|
33
60
|
|
34
|
-
def style_scalar(
|
61
|
+
def style_scalar(_sniffer,node)
|
35
62
|
node.style = Psychgus::SCALAR_SINGLE_QUOTED if node.value.casecmp('Mushrooms') == 0
|
36
63
|
node.value = 'Spinach' if node.value.casecmp('Lettuce') == 0
|
37
64
|
end
|
@@ -39,35 +66,7 @@ class MyStyler
|
|
39
66
|
def style_sequence(sniffer,node)
|
40
67
|
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 3
|
41
68
|
|
42
|
-
# Burgers=>Classic=>Sauce and Mushrooms
|
69
|
+
# Burgers => Classic => Sauce and Mushrooms.
|
43
70
|
node.style = Psychgus::SEQUENCE_BLOCK if sniffer.position == 1
|
44
71
|
end
|
45
72
|
end
|
46
|
-
|
47
|
-
class StylerTest < PsychgusTester
|
48
|
-
def setup
|
49
|
-
@styler = MyStyler.new
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_styler
|
53
|
-
expected = <<-YAML
|
54
|
-
|---
|
55
|
-
|Burgers:
|
56
|
-
| Classic:
|
57
|
-
| Sauce:
|
58
|
-
| - Ketchup
|
59
|
-
| - Mustard
|
60
|
-
| Cheese: American
|
61
|
-
| Bun: Sesame Seed
|
62
|
-
| BBQ: {Sauce: Honey BBQ, Cheese: Cheddar, Bun: Kaiser}
|
63
|
-
| Fancy: {Sauce: Spicy Wasabi, Cheese: Smoked Gouda, Bun: Hawaiian}
|
64
|
-
|Toppings:
|
65
|
-
|- 'Mushrooms'
|
66
|
-
|- [Spinach, Onions, Pickles, Tomatoes]
|
67
|
-
|- [[Ketchup, Mustard], [Salt, Pepper]]
|
68
|
-
YAML
|
69
|
-
expected = self.class.lstrip_pipe(expected)
|
70
|
-
|
71
|
-
assert_equal expected,BURGERS_DATA.to_yaml(stylers: @styler)
|
72
|
-
end
|
73
|
-
end
|
data/test/stylers_test.rb
CHANGED
@@ -8,71 +8,71 @@
|
|
8
8
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
9
|
#++
|
10
10
|
|
11
|
-
require '
|
11
|
+
require 'test_helper'
|
12
12
|
|
13
|
-
class
|
14
|
-
include Psychgus::Blueberry
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
@eggs = {
|
18
|
-
styles: ['omelette','BBQ eggs','hard-boiled eggs','soft_boiled eggs','fried@eggs'],
|
19
|
-
colors: ['brown','white',['blue','green']]
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def psychgus_stylers(sniffer)
|
24
|
-
return Psychgus::FlowStyler.new(4)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class StylersTest < PsychgusTester
|
13
|
+
class StylersTest < Minitest::Test
|
29
14
|
def setup
|
30
15
|
@egg_carton = EggCarton.new
|
31
16
|
end
|
32
17
|
|
33
18
|
def test_capstyler
|
34
19
|
actual = @egg_carton.to_yaml(stylers: Psychgus::CapStyler.new(each_word: false))
|
35
|
-
expected = <<-YAML
|
20
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
36
21
|
|--- !ruby/object:EggCarton
|
37
22
|
|Eggs:
|
38
23
|
| :styles: [Omelette, BBQ eggs, Hard-boiled eggs, Soft_boiled eggs, Fried@eggs]
|
39
24
|
| :colors: [Brown, White, [Blue, Green]]
|
40
25
|
YAML
|
41
26
|
|
42
|
-
assert_equal
|
27
|
+
assert_equal expected,actual
|
43
28
|
|
44
29
|
actual = @egg_carton.to_yaml(stylers: Psychgus::CapStyler.new(new_delim: '+',delim: /[\s_\-@]/))
|
45
|
-
expected = <<-YAML
|
30
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
46
31
|
|--- !ruby/object:EggCarton
|
47
32
|
|Eggs:
|
48
33
|
| :styles: [Omelette, BBQ+Eggs, Hard+Boiled+Eggs, Soft+Boiled+Eggs, Fried+Eggs]
|
49
34
|
| :colors: [Brown, White, [Blue, Green]]
|
50
35
|
YAML
|
51
36
|
|
52
|
-
assert_equal
|
37
|
+
assert_equal expected,actual
|
53
38
|
end
|
54
39
|
|
55
40
|
def test_nosymstyler
|
56
41
|
actual = @egg_carton.to_yaml(stylers: Psychgus::NoSymStyler.new)
|
57
|
-
expected = <<-YAML
|
42
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
58
43
|
|--- !ruby/object:EggCarton
|
59
44
|
|eggs:
|
60
45
|
| Styles: [omelette, BBQ eggs, hard-boiled eggs, soft_boiled eggs, fried@eggs]
|
61
46
|
| Colors: [brown, white, [blue, green]]
|
62
47
|
YAML
|
63
48
|
|
64
|
-
assert_equal
|
49
|
+
assert_equal expected,actual
|
65
50
|
end
|
66
51
|
|
67
52
|
def test_notagstyler
|
68
53
|
actual = @egg_carton.to_yaml(stylers: Psychgus::NoTagStyler.new)
|
69
|
-
expected = <<-YAML
|
54
|
+
expected = TestHelper.lstrip_pipe(<<-YAML)
|
70
55
|
|---
|
71
56
|
|eggs:
|
72
57
|
| :styles: [omelette, BBQ eggs, hard-boiled eggs, soft_boiled eggs, fried@eggs]
|
73
58
|
| :colors: [brown, white, [blue, green]]
|
74
59
|
YAML
|
75
60
|
|
76
|
-
assert_equal
|
61
|
+
assert_equal expected,actual
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class EggCarton
|
66
|
+
include Psychgus::Blueberry
|
67
|
+
|
68
|
+
def initialize
|
69
|
+
@eggs = {
|
70
|
+
styles: ['omelette','BBQ eggs','hard-boiled eggs','soft_boiled eggs','fried@eggs'],
|
71
|
+
colors: ['brown','white',['blue','green']],
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def psychgus_stylers(_sniffer)
|
76
|
+
return Psychgus::FlowStyler.new(4)
|
77
77
|
end
|
78
78
|
end
|
@@ -12,8 +12,14 @@ require 'minitest/autorun'
|
|
12
12
|
|
13
13
|
require 'psychgus'
|
14
14
|
|
15
|
-
# Changing the YAML/data will break tests
|
16
|
-
|
15
|
+
# NOTE: Changing the YAML/data will break tests
|
16
|
+
module TestHelper
|
17
|
+
# This is for `<<-` heredoc.
|
18
|
+
# - Purposely not using `<<~` (tilde) for older Ruby versions.
|
19
|
+
def self.lstrip_pipe(str)
|
20
|
+
return str.gsub(/^\s*\|/,'')
|
21
|
+
end
|
22
|
+
|
17
23
|
BURGERS_YAML = <<-YAML
|
18
24
|
Burgers:
|
19
25
|
Classic:
|
@@ -63,10 +69,4 @@ Popular:
|
|
63
69
|
# Don't do 'aliases: true' because that doesn't exist
|
64
70
|
# in older versions of Psych.
|
65
71
|
DOLPHINS_DATA = Psych.unsafe_load(DOLPHINS_YAML).freeze
|
66
|
-
|
67
|
-
# This is for "<<-" heredoc
|
68
|
-
# - Purposely not using "<<~" (tilde) for older Ruby versions
|
69
|
-
def self.lstrip_pipe(str)
|
70
|
-
return str.gsub(/^\s*\|/,'')
|
71
|
-
end
|
72
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psychgus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Whited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: psych
|
@@ -53,19 +53,19 @@ files:
|
|
53
53
|
- psychgus.gemspec
|
54
54
|
- test/blueberry_test.rb
|
55
55
|
- test/psychgus_test.rb
|
56
|
-
- test/psychgus_tester.rb
|
57
56
|
- test/sniffer_test.rb
|
58
57
|
- test/styler_test.rb
|
59
58
|
- test/stylers_test.rb
|
60
|
-
-
|
59
|
+
- test/test_helper.rb
|
61
60
|
homepage: https://github.com/esotericpig/psychgus
|
62
61
|
licenses:
|
63
62
|
- LGPL-3.0-or-later
|
64
63
|
metadata:
|
64
|
+
rubygems_mfa_required: 'true'
|
65
65
|
homepage_uri: https://github.com/esotericpig/psychgus
|
66
66
|
source_code_uri: https://github.com/esotericpig/psychgus
|
67
67
|
bug_tracker_uri: https://github.com/esotericpig/psychgus/issues
|
68
|
-
changelog_uri: https://github.com/esotericpig/psychgus/blob/
|
68
|
+
changelog_uri: https://github.com/esotericpig/psychgus/blob/main/CHANGELOG.md
|
69
69
|
documentation_uri: https://esotericpig.github.io/docs/psychgus/yardoc/index.html
|
70
70
|
post_install_message:
|
71
71
|
rdoc_options: []
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.5.
|
85
|
+
rubygems_version: 3.5.21
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Easily style YAML files using Psych.
|