psychgus 1.3.3 → 1.3.4
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 +4 -0
- data/CHANGELOG.md +22 -7
- data/Gemfile +0 -18
- data/README.md +27 -28
- data/Rakefile +20 -42
- data/lib/psychgus.rb +169 -179
- data/lib/psychgus/blueberry.rb +28 -39
- data/lib/psychgus/ext.rb +6 -17
- data/lib/psychgus/ext/core_ext.rb +17 -28
- data/lib/psychgus/ext/node_ext.rb +13 -24
- data/lib/psychgus/ext/yaml_tree_ext.rb +23 -34
- data/lib/psychgus/stylables.rb +78 -89
- data/lib/psychgus/styled_document_stream.rb +14 -25
- data/lib/psychgus/styled_tree_builder.rb +90 -101
- data/lib/psychgus/styler.rb +33 -44
- data/lib/psychgus/stylers.rb +67 -78
- data/lib/psychgus/super_sniffer.rb +111 -123
- data/lib/psychgus/super_sniffer/parent.rb +42 -51
- data/lib/psychgus/version.rb +4 -16
- data/psychgus.gemspec +39 -43
- data/test/blueberry_test.rb +30 -41
- data/test/psychgus_test.rb +51 -60
- data/test/psychgus_tester.rb +23 -31
- data/test/sniffer_test.rb +18 -32
- data/test/styler_test.rb +20 -31
- data/test/stylers_test.rb +32 -43
- metadata +15 -14
data/test/psychgus_test.rb
CHANGED
@@ -1,22 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
#--
|
5
5
|
# This file is part of Psychgus.
|
6
|
-
# Copyright (c) 2019 Jonathan Bradley Whited
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# Psychgus is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU Lesser General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU Lesser General Public License
|
19
|
-
# along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2019-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
20
9
|
#++
|
21
10
|
|
22
11
|
|
@@ -26,18 +15,18 @@ require 'tempfile'
|
|
26
15
|
|
27
16
|
class FlowStyler
|
28
17
|
include Psychgus::Styler
|
29
|
-
|
18
|
+
|
30
19
|
def style_mapping(sniffer,node)
|
31
20
|
node.style = Psychgus::MAPPING_FLOW if sniffer.level >= 4
|
32
21
|
end
|
33
|
-
|
22
|
+
|
34
23
|
def style_sequence(sniffer,node)
|
35
24
|
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
|
36
25
|
end
|
37
26
|
end
|
38
27
|
|
39
28
|
class PsychgusTest < PsychgusTester
|
40
|
-
EXPECTED_BURGERS = <<-
|
29
|
+
EXPECTED_BURGERS = <<-YAML
|
41
30
|
---
|
42
31
|
Burgers:
|
43
32
|
Classic: {Sauce: [Ketchup, Mustard], Cheese: American, Bun: Sesame Seed}
|
@@ -47,14 +36,14 @@ Toppings:
|
|
47
36
|
- Mushrooms
|
48
37
|
- [Lettuce, Onions, Pickles, Tomatoes]
|
49
38
|
- [[Ketchup, Mustard], [Salt, Pepper]]
|
50
|
-
|
51
|
-
|
52
|
-
def setup
|
53
|
-
@flow_styler = FlowStyler.new
|
39
|
+
YAML
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@flow_styler = FlowStyler.new
|
54
43
|
end
|
55
|
-
|
56
|
-
def test_alias
|
57
|
-
expected = <<-
|
44
|
+
|
45
|
+
def test_alias
|
46
|
+
expected = <<-YAML
|
58
47
|
|---
|
59
48
|
|Dolphins:
|
60
49
|
| Common: {Length: "~2.5m", Weight: "~235kg"}
|
@@ -64,56 +53,56 @@ Toppings:
|
|
64
53
|
|Popular:
|
65
54
|
|- {Length: "~4m", Weight: "~300kg"}
|
66
55
|
|- {Length: "~7m", Weight: "~3600kg"}
|
67
|
-
|
56
|
+
YAML
|
68
57
|
expected = self.class.lstrip_pipe(expected)
|
69
|
-
|
58
|
+
|
70
59
|
assert_equal expected,DOLPHINS_DATA.to_yaml(deref_aliases: true,stylers: @flow_styler)
|
71
60
|
end
|
72
|
-
|
73
|
-
def test_dump
|
61
|
+
|
62
|
+
def test_dump
|
74
63
|
assert_equal EXPECTED_BURGERS,Psychgus.dump(BURGERS_DATA,stylers: @flow_styler)
|
75
64
|
assert_equal EXPECTED_BURGERS,Psychgus.dump_stream(BURGERS_DATA,stylers: @flow_styler)
|
76
65
|
assert_equal EXPECTED_BURGERS,BURGERS_DATA.to_yaml(stylers: @flow_styler)
|
77
66
|
end
|
78
|
-
|
67
|
+
|
79
68
|
# Execute "rake test_all" if you update Psychgus.dump_file()/load_file()
|
80
|
-
def test_file
|
69
|
+
def test_file
|
81
70
|
if !TEST_ALL
|
82
71
|
skip(TEST_ALL_SKIP_MSG)
|
83
72
|
return # Justin Case
|
84
73
|
end
|
85
|
-
|
74
|
+
|
86
75
|
Tempfile.create(['Psychgus','.yaml']) do |file|
|
87
76
|
puts "Testing #{self.class.name} w/ temp file: #{file.path}"
|
88
|
-
|
77
|
+
|
89
78
|
Psychgus.dump_file(file,BURGERS_DATA,
|
90
79
|
mode: File::CREAT | File::RDWR,
|
91
80
|
opt: {textmode: true},
|
92
81
|
#perm: 644, # Unix only
|
93
82
|
stylers: @flow_styler,
|
94
83
|
)
|
95
|
-
|
96
|
-
file.rewind
|
97
|
-
|
98
|
-
lines = file.readlines
|
84
|
+
|
85
|
+
file.rewind
|
86
|
+
|
87
|
+
lines = file.readlines.join
|
99
88
|
assert_equal EXPECTED_BURGERS,lines
|
100
|
-
|
101
|
-
file.rewind
|
102
|
-
file.close
|
103
|
-
|
89
|
+
|
90
|
+
file.rewind
|
91
|
+
file.close
|
92
|
+
|
104
93
|
data = Psych.load_file(file)
|
105
94
|
refute_equal false,data
|
106
95
|
refute_equal nil,data
|
107
|
-
|
96
|
+
|
108
97
|
data = Psychgus.parse_file(file)
|
109
98
|
refute_equal false,data
|
110
99
|
refute_equal nil,data
|
111
100
|
end
|
112
101
|
end
|
113
|
-
|
114
|
-
def test_indent
|
102
|
+
|
103
|
+
def test_indent
|
115
104
|
# Indent of 3 spaces
|
116
|
-
expected = <<-
|
105
|
+
expected = <<-YAML
|
117
106
|
|---
|
118
107
|
|Burgers:
|
119
108
|
| Classic: {Sauce: [Ketchup, Mustard], Cheese: American, Bun: Sesame Seed}
|
@@ -123,47 +112,49 @@ Toppings:
|
|
123
112
|
|- Mushrooms
|
124
113
|
|- [Lettuce, Onions, Pickles, Tomatoes]
|
125
114
|
|- [[Ketchup, Mustard], [Salt, Pepper]]
|
126
|
-
|
115
|
+
YAML
|
127
116
|
expected = self.class.lstrip_pipe(expected)
|
128
|
-
|
117
|
+
|
118
|
+
# rubocop:disable Style/HashSyntax
|
129
119
|
assert_equal expected,BURGERS_DATA.to_yaml(indent: 3,stylers: @flow_styler)
|
130
|
-
assert_equal expected,BURGERS_DATA.to_yaml(**{:indent=>3,:stylers
|
120
|
+
assert_equal expected,BURGERS_DATA.to_yaml(**{:indent => 3,:stylers => @flow_styler})
|
131
121
|
assert_equal expected,BURGERS_DATA.to_yaml(indentation: 3,stylers: @flow_styler)
|
132
|
-
assert_equal expected,BURGERS_DATA.to_yaml(**{:indentation=>3,:stylers
|
122
|
+
assert_equal expected,BURGERS_DATA.to_yaml(**{:indentation => 3,:stylers => @flow_styler})
|
123
|
+
# rubocop:enable all
|
133
124
|
end
|
134
|
-
|
135
|
-
def test_node_consts
|
125
|
+
|
126
|
+
def test_node_consts
|
136
127
|
assert_equal Psych::Nodes::Mapping::ANY,Psychgus::MAPPING_ANY
|
137
128
|
assert_equal Psych::Nodes::Mapping::BLOCK,Psychgus::MAPPING_BLOCK
|
138
129
|
assert_equal Psych::Nodes::Mapping::FLOW,Psychgus::MAPPING_FLOW
|
139
|
-
|
130
|
+
|
140
131
|
assert_equal Psych::Nodes::Scalar::ANY,Psychgus::SCALAR_ANY
|
141
132
|
assert_equal Psych::Nodes::Scalar::PLAIN,Psychgus::SCALAR_PLAIN
|
142
133
|
assert_equal Psych::Nodes::Scalar::SINGLE_QUOTED,Psychgus::SCALAR_SINGLE_QUOTED
|
143
134
|
assert_equal Psych::Nodes::Scalar::DOUBLE_QUOTED,Psychgus::SCALAR_DOUBLE_QUOTED
|
144
135
|
assert_equal Psych::Nodes::Scalar::LITERAL,Psychgus::SCALAR_LITERAL
|
145
136
|
assert_equal Psych::Nodes::Scalar::FOLDED,Psychgus::SCALAR_FOLDED
|
146
|
-
|
137
|
+
|
147
138
|
assert_equal Psych::Nodes::Sequence::ANY,Psychgus::SEQUENCE_ANY
|
148
139
|
assert_equal Psych::Nodes::Sequence::BLOCK,Psychgus::SEQUENCE_BLOCK
|
149
140
|
assert_equal Psych::Nodes::Sequence::FLOW,Psychgus::SEQUENCE_FLOW
|
150
|
-
|
141
|
+
|
151
142
|
assert_equal Psych::Nodes::Stream::ANY,Psychgus::STREAM_ANY
|
152
143
|
assert_equal Psych::Nodes::Stream::UTF8,Psychgus::STREAM_UTF8
|
153
144
|
assert_equal Psych::Nodes::Stream::UTF16LE,Psychgus::STREAM_UTF16LE
|
154
145
|
assert_equal Psych::Nodes::Stream::UTF16BE,Psychgus::STREAM_UTF16BE
|
155
146
|
end
|
156
|
-
|
157
|
-
def test_parse
|
147
|
+
|
148
|
+
def test_parse
|
158
149
|
parser = Psychgus.parser(stylers: @flow_styler)
|
159
150
|
parser.parse(BURGERS_YAML)
|
160
|
-
yaml = "---\n" + parser.handler.root.to_yaml
|
151
|
+
yaml = "---\n" + parser.handler.root.to_yaml
|
161
152
|
assert_equal EXPECTED_BURGERS,yaml
|
162
|
-
|
153
|
+
|
163
154
|
node = Psychgus.parse(BURGERS_YAML,stylers: @flow_styler)
|
164
155
|
refute_equal false,node
|
165
|
-
|
166
|
-
yaml = Psychgus.parse_stream(BURGERS_YAML,stylers: @flow_styler).to_yaml
|
156
|
+
|
157
|
+
yaml = Psychgus.parse_stream(BURGERS_YAML,stylers: @flow_styler).to_yaml
|
167
158
|
yaml = "---\n#{yaml}"
|
168
159
|
assert_equal EXPECTED_BURGERS,yaml
|
169
160
|
end
|
data/test/psychgus_tester.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: UTF-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
#--
|
6
5
|
# This file is part of Psychgus.
|
7
|
-
# Copyright (c) 2019 Jonathan Bradley Whited
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Psychgus is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU Lesser General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU Lesser General Public License
|
20
|
-
# along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2019-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
21
9
|
#++
|
22
10
|
|
23
11
|
|
@@ -30,13 +18,13 @@ class PsychgusTester < Minitest::Test
|
|
30
18
|
# If true, will...
|
31
19
|
# - Run tests that create temp file(s).
|
32
20
|
# - I don't like creating temp file(s) every time I run tests (which is a lot).
|
33
|
-
#
|
21
|
+
#
|
34
22
|
# To do this, execute:
|
35
23
|
# rake test_all
|
36
|
-
TEST_ALL = (ENV['PSYCHGUS_TEST'].to_s
|
37
|
-
TEST_ALL_SKIP_MSG =
|
38
|
-
|
39
|
-
BURGERS_YAML = <<-
|
24
|
+
TEST_ALL = (ENV['PSYCHGUS_TEST'].to_s.strip.casecmp('all') == 0)
|
25
|
+
TEST_ALL_SKIP_MSG = 'Execute "rake test_all" for this test'
|
26
|
+
|
27
|
+
BURGERS_YAML = <<-YAML
|
40
28
|
Burgers:
|
41
29
|
Classic:
|
42
30
|
Sauce: [Ketchup,Mustard]
|
@@ -54,10 +42,10 @@ Toppings:
|
|
54
42
|
- Mushrooms
|
55
43
|
- [Lettuce, Onions, Pickles, Tomatoes]
|
56
44
|
- [[Ketchup,Mustard], [Salt,Pepper]]
|
57
|
-
|
58
|
-
BURGERS_DATA = Psych.load(BURGERS_YAML).freeze
|
59
|
-
|
60
|
-
COURSES_YAML = <<-
|
45
|
+
YAML
|
46
|
+
BURGERS_DATA = Psych.load(BURGERS_YAML).freeze
|
47
|
+
|
48
|
+
COURSES_YAML = <<-YAML
|
61
49
|
Courses:
|
62
50
|
COSC: [470,'Computer Science']
|
63
51
|
MUSC: [340,'Music']
|
@@ -67,10 +55,10 @@ Schedule:
|
|
67
55
|
- {Course: MUSC,Time: '10:30'}
|
68
56
|
- {Course: ARTS,Time: '15:10'}
|
69
57
|
- {Course: COSC,Time: '13:10'}
|
70
|
-
|
71
|
-
COURSES_DATA = Psych.load(COURSES_YAML).freeze
|
72
|
-
|
73
|
-
DOLPHINS_YAML = <<-
|
58
|
+
YAML
|
59
|
+
COURSES_DATA = Psych.load(COURSES_YAML).freeze
|
60
|
+
|
61
|
+
DOLPHINS_YAML = <<-YAML
|
74
62
|
Dolphins:
|
75
63
|
Common: &com {Length: ~2.5m, Weight: ~235kg}
|
76
64
|
Bottlenose: &bot {Length: ~4m, Weight: ~300kg}
|
@@ -79,9 +67,13 @@ Dolphins:
|
|
79
67
|
Popular:
|
80
68
|
- *bot
|
81
69
|
- *orc
|
82
|
-
|
83
|
-
|
84
|
-
|
70
|
+
YAML
|
71
|
+
# Psych v4+ uses safe_load() by default for load(),
|
72
|
+
# so use unsafe_load() to have aliases turned on.
|
73
|
+
# Don't do 'aliases: true' because that doesn't exist
|
74
|
+
# in older versions of Psych.
|
75
|
+
DOLPHINS_DATA = Psych.unsafe_load(DOLPHINS_YAML).freeze
|
76
|
+
|
85
77
|
# This is for "<<-" heredoc
|
86
78
|
# - Purposely not using "<<~" (tilde) for older Ruby versions
|
87
79
|
def self.lstrip_pipe(str)
|
data/test/sniffer_test.rb
CHANGED
@@ -1,22 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
#--
|
5
5
|
# This file is part of Psychgus.
|
6
|
-
# Copyright (c) 2019 Jonathan Bradley Whited
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# Psychgus is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU Lesser General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU Lesser General Public License
|
19
|
-
# along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2019-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
20
9
|
#++
|
21
10
|
|
22
11
|
|
@@ -25,18 +14,18 @@ require 'psychgus_tester'
|
|
25
14
|
require 'stringio'
|
26
15
|
|
27
16
|
class SnifferTest < PsychgusTester
|
28
|
-
def setup
|
17
|
+
def setup
|
29
18
|
end
|
30
|
-
|
19
|
+
|
31
20
|
def assert_hierarchy(*data,expected)
|
32
21
|
expected = self.class.lstrip_pipe(expected)
|
33
22
|
hierarchy = Psychgus.hierarchy(*data,verbose: true)
|
34
|
-
|
23
|
+
|
35
24
|
assert_equal expected,hierarchy
|
36
25
|
end
|
37
|
-
|
38
|
-
def test_multi_doc
|
39
|
-
assert_hierarchy(BURGERS_DATA,COURSES_DATA,DOLPHINS_DATA,<<-
|
26
|
+
|
27
|
+
def test_multi_doc
|
28
|
+
assert_hierarchy(BURGERS_DATA,COURSES_DATA,DOLPHINS_DATA,<<-HIER)
|
40
29
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
41
30
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
42
31
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
@@ -153,12 +142,11 @@ class SnifferTest < PsychgusTester
|
|
153
142
|
| (3:1):Psych::Nodes::Sequence - <Popular:(2:2):value:(:1)>
|
154
143
|
| (4:1):Psych::Nodes::Alias - <seq:(3:1)::(:1)>
|
155
144
|
| (4:2):Psych::Nodes::Alias - <seq:(3:1)::(:2)>
|
156
|
-
|
157
|
-
)
|
145
|
+
HIER
|
158
146
|
end
|
159
|
-
|
160
|
-
def test_single_docs
|
161
|
-
assert_hierarchy(BURGERS_DATA,<<-
|
147
|
+
|
148
|
+
def test_single_docs
|
149
|
+
assert_hierarchy(BURGERS_DATA,<<-HIER)
|
162
150
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
163
151
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
164
152
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
@@ -205,10 +193,9 @@ class SnifferTest < PsychgusTester
|
|
205
193
|
| (5:2):Psych::Nodes::Sequence - <seq:(4:3)::(:2)>
|
206
194
|
| (6:1):Salt - <seq:(5:2)::(:1)>
|
207
195
|
| (6:2):Pepper - <seq:(5:2)::(:2)>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
assert_hierarchy(COURSES_DATA,<<-EOH
|
196
|
+
HIER
|
197
|
+
|
198
|
+
assert_hierarchy(COURSES_DATA,<<-HIER)
|
212
199
|
|(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
|
213
200
|
|(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
|
214
201
|
|(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
|
@@ -248,7 +235,6 @@ class SnifferTest < PsychgusTester
|
|
248
235
|
| (6:1):COSC - <Course:(5:1):value:(:1)>
|
249
236
|
| (5:2):Time - <map:(4:4):key:(:2)>
|
250
237
|
| (6:1):13:10 - <Time:(5:2):value:(:1)>
|
251
|
-
|
252
|
-
)
|
238
|
+
HIER
|
253
239
|
end
|
254
240
|
end
|
data/test/styler_test.rb
CHANGED
@@ -1,22 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
#--
|
5
5
|
# This file is part of Psychgus.
|
6
|
-
# Copyright (c) 2019 Jonathan Bradley Whited
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# Psychgus is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU Lesser General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU Lesser General Public License
|
19
|
-
# along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2019-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
20
9
|
#++
|
21
10
|
|
22
11
|
|
@@ -24,45 +13,45 @@ require 'psychgus_tester'
|
|
24
13
|
|
25
14
|
class MyStyler
|
26
15
|
include Psychgus::Styler
|
27
|
-
|
16
|
+
|
28
17
|
def style(sniffer,node)
|
29
18
|
end
|
30
|
-
|
19
|
+
|
31
20
|
def style_alias(sniffer,node)
|
32
21
|
end
|
33
|
-
|
22
|
+
|
34
23
|
def style_mapping(sniffer,node)
|
35
24
|
parent = sniffer.parent
|
36
|
-
|
37
|
-
if !parent.nil?
|
25
|
+
|
26
|
+
if !parent.nil?
|
38
27
|
# BBQ
|
39
28
|
node.style = Psychgus::MAPPING_FLOW if parent.node_of?(:scalar) && parent.value.casecmp('BBQ') == 0
|
40
|
-
|
29
|
+
|
41
30
|
# Fancy
|
42
31
|
node.style = Psychgus::MAPPING_FLOW if parent.level == 4 && parent.position == 3
|
43
32
|
end
|
44
33
|
end
|
45
|
-
|
34
|
+
|
46
35
|
def style_scalar(sniffer,node)
|
47
36
|
node.style = Psychgus::SCALAR_SINGLE_QUOTED if node.value.casecmp('Mushrooms') == 0
|
48
37
|
node.value = 'Spinach' if node.value.casecmp('Lettuce') == 0
|
49
38
|
end
|
50
|
-
|
39
|
+
|
51
40
|
def style_sequence(sniffer,node)
|
52
41
|
node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 3
|
53
|
-
|
42
|
+
|
54
43
|
# Burgers=>Classic=>Sauce and Mushrooms
|
55
44
|
node.style = Psychgus::SEQUENCE_BLOCK if sniffer.position == 1
|
56
45
|
end
|
57
46
|
end
|
58
47
|
|
59
48
|
class StylerTest < PsychgusTester
|
60
|
-
def setup
|
61
|
-
@styler = MyStyler.new
|
49
|
+
def setup
|
50
|
+
@styler = MyStyler.new
|
62
51
|
end
|
63
|
-
|
64
|
-
def test_styler
|
65
|
-
expected = <<-
|
52
|
+
|
53
|
+
def test_styler
|
54
|
+
expected = <<-YAML
|
66
55
|
|---
|
67
56
|
|Burgers:
|
68
57
|
| Classic:
|
@@ -77,9 +66,9 @@ class StylerTest < PsychgusTester
|
|
77
66
|
|- 'Mushrooms'
|
78
67
|
|- [Spinach, Onions, Pickles, Tomatoes]
|
79
68
|
|- [[Ketchup, Mustard], [Salt, Pepper]]
|
80
|
-
|
69
|
+
YAML
|
81
70
|
expected = self.class.lstrip_pipe(expected)
|
82
|
-
|
71
|
+
|
83
72
|
assert_equal expected,BURGERS_DATA.to_yaml(stylers: @styler)
|
84
73
|
end
|
85
74
|
end
|