psychgus 1.3.3 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/psychgus.gemspec CHANGED
@@ -1,68 +1,54 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of Psychgus.
6
- # Copyright (c) 2017-2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
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 <https://www.gnu.org/licenses/>.
20
- #++
4
+ require_relative 'lib/psychgus/version'
21
5
 
22
-
23
- lib = File.expand_path('../lib',__FILE__)
24
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
-
26
- require 'psychgus/version'
27
-
28
-
29
- Gem::Specification.new() do |spec|
6
+ Gem::Specification.new do |spec|
30
7
  spec.name = 'psychgus'
31
8
  spec.version = Psychgus::VERSION
32
- spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
33
- spec.email = ['bradley@esotericpig.com']
9
+ spec.authors = ['Bradley Whited']
10
+ spec.email = ['code@esotericpig.com']
34
11
  spec.licenses = ['LGPL-3.0-or-later']
35
12
  spec.homepage = 'https://github.com/esotericpig/psychgus'
36
- spec.summary = %q(Easily style YAML files using Psych.)
37
- spec.description = %q(Easily style YAML files using Psych, like Sequence/Mapping Flow style.)
38
-
13
+ spec.summary = 'Easily style YAML files using Psych.'
14
+ spec.description = 'Easily style YAML files using Psych, like Sequence/Mapping Flow style.'
15
+
39
16
  spec.metadata = {
17
+ 'homepage_uri' => 'https://github.com/esotericpig/psychgus',
18
+ 'source_code_uri' => 'https://github.com/esotericpig/psychgus',
40
19
  'bug_tracker_uri' => 'https://github.com/esotericpig/psychgus/issues',
41
20
  'changelog_uri' => 'https://github.com/esotericpig/psychgus/blob/master/CHANGELOG.md',
42
21
  'documentation_uri' => 'https://esotericpig.github.io/docs/psychgus/yardoc/index.html',
43
- 'homepage_uri' => 'https://github.com/esotericpig/psychgus',
44
- 'source_code_uri' => 'https://github.com/esotericpig/psychgus'
45
22
  }
46
-
47
- spec.require_paths = ['lib']
48
-
49
- spec.files = Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')) +
50
- Dir.glob(File.join('{test,yard}','**','*.{erb,rb}')) +
51
- %W( Gemfile #{spec.name}.gemspec Rakefile ) +
52
- %w( CHANGELOG.md LICENSE.txt README.md )
53
-
54
- spec.required_ruby_version = '>= 2.1.10'
55
-
23
+
24
+ spec.required_ruby_version = '>= 2.2'
25
+ spec.require_paths = ['lib']
26
+ spec.bindir = 'bin'
27
+
28
+ spec.files = [
29
+ Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
30
+ Dir.glob(File.join(spec.bindir,'*')),
31
+ Dir.glob(File.join('{samples,test,yard}','**','*.{erb,rb}')),
32
+ %W[ Gemfile #{spec.name}.gemspec Rakefile .yardopts ],
33
+ %w[ LICENSE.txt CHANGELOG.md README.md ],
34
+ ].flatten
35
+
36
+ # Test using different Gem versions:
37
+ # GST=1 bundle update && bundle exec rake test
38
+ gemspec_test = ENV.fetch('GST','').to_s.strip
39
+ psych_gemv = false
40
+
41
+ if !gemspec_test.empty?
42
+ case gemspec_test
43
+ when '1' then psych_gemv = '<= 5.1.1'
44
+ end
45
+
46
+ puts 'Using Gem versions:'
47
+ puts " psych: #{psych_gemv.inspect}"
48
+ end
49
+
56
50
  # 3.0 is needed for this issue:
57
51
  # - https://bugs.ruby-lang.org/issues/13115
58
52
  # - https://github.com/ruby/psych/commit/712a65a53f3c15105cd86e8ad3ee3c779050ada4
59
- spec.add_runtime_dependency 'psych','>= 3.0'
60
-
61
- spec.add_development_dependency 'bundler' ,'~> 2.1'
62
- spec.add_development_dependency 'minitest' ,'~> 5.14' # For testing
63
- spec.add_development_dependency 'rake' ,'~> 13.0'
64
- spec.add_development_dependency 'rdoc' ,'~> 6.2' # For RDoc for YARD (*.rb)
65
- spec.add_development_dependency 'redcarpet' ,'~> 3.5' # For Markdown for YARD (*.md)
66
- spec.add_development_dependency 'yard' ,'~> 0.9' # For documentation
67
- spec.add_development_dependency 'yard_ghurt','~> 1.2' # For YARD GitHub rake tasks
53
+ spec.add_dependency 'psych',psych_gemv || '>= 3.0'
68
54
  end
@@ -1,46 +1,34 @@
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 (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
-
23
11
  require 'psychgus_tester'
24
12
 
25
13
  class Burger
26
14
  include Psychgus::Blueberry
27
-
15
+
28
16
  attr_accessor :bun
29
17
  attr_accessor :cheese
30
18
  attr_accessor :sauce
31
-
19
+
32
20
  def initialize(sauce,cheese,bun)
33
21
  @bun = bun
34
22
  @cheese = cheese
35
23
  @sauce = sauce
36
24
  end
37
-
25
+
38
26
  def encode_with(coder)
39
27
  coder['Bun'] = @bun
40
28
  coder['Cheese'] = @cheese
41
29
  coder['Sauce'] = @sauce
42
30
  end
43
-
31
+
44
32
  def psychgus_stylers(sniffer)
45
33
  return BurgerStyler.new(sniffer)
46
34
  end
@@ -49,21 +37,21 @@ end
49
37
  class Burgers
50
38
  attr_accessor :burgers
51
39
  attr_accessor :toppings
52
-
53
- def initialize()
40
+
41
+ def initialize
54
42
  @burgers = {
55
43
  'Classic' => Burger.new(['Ketchup','Mustard'],'American','Sesame Seed'),
56
44
  'BBQ' => Burger.new('Honey BBQ','Cheddar','Kaiser'),
57
45
  'Fancy' => Burger.new('Spicy Wasabi','Smoked Gouda','Hawaiian')
58
46
  }
59
-
47
+
60
48
  @toppings = [
61
49
  'Mushrooms',
62
- %w(Lettuce Onions Pickles Tomatoes),
63
- [%w(Ketchup Mustard),%w(Salt Pepper)]
50
+ %w[Lettuce Onions Pickles Tomatoes],
51
+ [%w[Ketchup Mustard],%w[Salt Pepper]]
64
52
  ]
65
53
  end
66
-
54
+
67
55
  def encode_with(coder)
68
56
  coder['Burgers'] = @burgers
69
57
  coder['Toppings'] = @toppings
@@ -72,46 +60,46 @@ end
72
60
 
73
61
  class BurgerStyler
74
62
  include Psychgus::Styler
75
-
63
+
76
64
  def initialize(sniffer)
77
65
  @level = sniffer.level
78
66
  @position = sniffer.position
79
67
  end
80
-
68
+
81
69
  def style(sniffer,node)
82
70
  # Remove ugly and unsafe "!ruby/object:Burger"
83
71
  node.tag = nil if node.respond_to?(:tag)
84
72
  end
85
-
73
+
86
74
  def style_mapping(sniffer,node)
87
75
  parent = sniffer.parent
88
-
89
- if !parent.nil?()
76
+
77
+ if !parent.nil?
90
78
  # BBQ
91
79
  node.style = Psychgus::MAPPING_FLOW if parent.respond_to?(:value) && parent.value.casecmp('BBQ') == 0
92
80
  end
93
81
  end
94
-
82
+
95
83
  def style_scalar(sniffer,node)
96
84
  # Only for Burgers
97
85
  node.style = Psychgus::SCALAR_SINGLE_QUOTED
98
86
  end
99
-
87
+
100
88
  def style_sequence(sniffer,node)
101
89
  relative_level = (sniffer.level - @level) + 1
102
-
90
+
103
91
  # [Ketchup, Mustard]
104
92
  node.style = Psychgus::SEQUENCE_FLOW if relative_level == 3
105
93
  end
106
94
  end
107
95
 
108
96
  class BlueberryTest < PsychgusTester
109
- def setup()
110
- @burgers = Burgers.new()
97
+ def setup
98
+ @burgers = Burgers.new
111
99
  end
112
-
113
- def test_blueberry()
114
- expected = <<-EOY
100
+
101
+ def test_blueberry
102
+ expected = <<-YAML
115
103
  |--- !ruby/object:Burgers
116
104
  |Burgers:
117
105
  | Classic:
@@ -133,9 +121,9 @@ class BlueberryTest < PsychgusTester
133
121
  | - Mustard
134
122
  | - - Salt
135
123
  | - Pepper
136
- EOY
124
+ YAML
137
125
  expected = self.class.lstrip_pipe(expected)
138
-
139
- assert_equal expected,@burgers.to_yaml()
126
+
127
+ assert_equal expected,@burgers.to_yaml
140
128
  end
141
129
  end
@@ -1,43 +1,31 @@
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 (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
-
23
11
  require 'psychgus_tester'
24
12
 
25
13
  require 'tempfile'
26
14
 
27
15
  class FlowStyler
28
16
  include Psychgus::Styler
29
-
17
+
30
18
  def style_mapping(sniffer,node)
31
19
  node.style = Psychgus::MAPPING_FLOW if sniffer.level >= 4
32
20
  end
33
-
21
+
34
22
  def style_sequence(sniffer,node)
35
23
  node.style = Psychgus::SEQUENCE_FLOW if sniffer.level >= 4
36
24
  end
37
25
  end
38
26
 
39
27
  class PsychgusTest < PsychgusTester
40
- EXPECTED_BURGERS = <<-EOY
28
+ EXPECTED_BURGERS = <<-YAML
41
29
  ---
42
30
  Burgers:
43
31
  Classic: {Sauce: [Ketchup, Mustard], Cheese: American, Bun: Sesame Seed}
@@ -47,14 +35,14 @@ Toppings:
47
35
  - Mushrooms
48
36
  - [Lettuce, Onions, Pickles, Tomatoes]
49
37
  - [[Ketchup, Mustard], [Salt, Pepper]]
50
- EOY
51
-
52
- def setup()
53
- @flow_styler = FlowStyler.new()
38
+ YAML
39
+
40
+ def setup
41
+ @flow_styler = FlowStyler.new
54
42
  end
55
-
56
- def test_alias()
57
- expected = <<-EOY
43
+
44
+ def test_alias
45
+ expected = <<-YAML
58
46
  |---
59
47
  |Dolphins:
60
48
  | Common: {Length: "~2.5m", Weight: "~235kg"}
@@ -64,56 +52,50 @@ Toppings:
64
52
  |Popular:
65
53
  |- {Length: "~4m", Weight: "~300kg"}
66
54
  |- {Length: "~7m", Weight: "~3600kg"}
67
- EOY
55
+ YAML
68
56
  expected = self.class.lstrip_pipe(expected)
69
-
57
+
70
58
  assert_equal expected,DOLPHINS_DATA.to_yaml(deref_aliases: true,stylers: @flow_styler)
71
59
  end
72
-
73
- def test_dump()
60
+
61
+ def test_dump
74
62
  assert_equal EXPECTED_BURGERS,Psychgus.dump(BURGERS_DATA,stylers: @flow_styler)
75
63
  assert_equal EXPECTED_BURGERS,Psychgus.dump_stream(BURGERS_DATA,stylers: @flow_styler)
76
64
  assert_equal EXPECTED_BURGERS,BURGERS_DATA.to_yaml(stylers: @flow_styler)
77
65
  end
78
-
79
- # Execute "rake test_all" if you update Psychgus.dump_file()/load_file()
80
- def test_file()
81
- if !TEST_ALL
82
- skip(TEST_ALL_SKIP_MSG)
83
- return # Justin Case
84
- end
85
-
66
+
67
+ def test_file
86
68
  Tempfile.create(['Psychgus','.yaml']) do |file|
87
- puts "Testing #{self.class.name} w/ temp file: #{file.path}"
88
-
69
+ #puts "Testing #{self.class.name} w/ temp file: #{file.path}"
70
+
89
71
  Psychgus.dump_file(file,BURGERS_DATA,
90
72
  mode: File::CREAT | File::RDWR,
91
73
  opt: {textmode: true},
92
74
  #perm: 644, # Unix only
93
75
  stylers: @flow_styler,
94
76
  )
95
-
96
- file.rewind()
97
-
98
- lines = file.readlines().join()
77
+
78
+ file.rewind
79
+
80
+ lines = file.readlines.join
99
81
  assert_equal EXPECTED_BURGERS,lines
100
-
101
- file.rewind()
102
- file.close()
103
-
82
+
83
+ file.rewind
84
+ file.close
85
+
104
86
  data = Psych.load_file(file)
105
87
  refute_equal false,data
106
88
  refute_equal nil,data
107
-
89
+
108
90
  data = Psychgus.parse_file(file)
109
91
  refute_equal false,data
110
92
  refute_equal nil,data
111
93
  end
112
94
  end
113
-
114
- def test_indent()
95
+
96
+ def test_indent
115
97
  # Indent of 3 spaces
116
- expected = <<-EOY
98
+ expected = <<-YAML
117
99
  |---
118
100
  |Burgers:
119
101
  | Classic: {Sauce: [Ketchup, Mustard], Cheese: American, Bun: Sesame Seed}
@@ -123,47 +105,49 @@ Toppings:
123
105
  |- Mushrooms
124
106
  |- [Lettuce, Onions, Pickles, Tomatoes]
125
107
  |- [[Ketchup, Mustard], [Salt, Pepper]]
126
- EOY
108
+ YAML
127
109
  expected = self.class.lstrip_pipe(expected)
128
-
110
+
111
+ # rubocop:disable Style/HashSyntax
129
112
  assert_equal expected,BURGERS_DATA.to_yaml(indent: 3,stylers: @flow_styler)
130
- 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})
131
114
  assert_equal expected,BURGERS_DATA.to_yaml(indentation: 3,stylers: @flow_styler)
132
- 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})
116
+ # rubocop:enable all
133
117
  end
134
-
135
- def test_node_consts()
118
+
119
+ def test_node_consts
136
120
  assert_equal Psych::Nodes::Mapping::ANY,Psychgus::MAPPING_ANY
137
121
  assert_equal Psych::Nodes::Mapping::BLOCK,Psychgus::MAPPING_BLOCK
138
122
  assert_equal Psych::Nodes::Mapping::FLOW,Psychgus::MAPPING_FLOW
139
-
123
+
140
124
  assert_equal Psych::Nodes::Scalar::ANY,Psychgus::SCALAR_ANY
141
125
  assert_equal Psych::Nodes::Scalar::PLAIN,Psychgus::SCALAR_PLAIN
142
126
  assert_equal Psych::Nodes::Scalar::SINGLE_QUOTED,Psychgus::SCALAR_SINGLE_QUOTED
143
127
  assert_equal Psych::Nodes::Scalar::DOUBLE_QUOTED,Psychgus::SCALAR_DOUBLE_QUOTED
144
128
  assert_equal Psych::Nodes::Scalar::LITERAL,Psychgus::SCALAR_LITERAL
145
129
  assert_equal Psych::Nodes::Scalar::FOLDED,Psychgus::SCALAR_FOLDED
146
-
130
+
147
131
  assert_equal Psych::Nodes::Sequence::ANY,Psychgus::SEQUENCE_ANY
148
132
  assert_equal Psych::Nodes::Sequence::BLOCK,Psychgus::SEQUENCE_BLOCK
149
133
  assert_equal Psych::Nodes::Sequence::FLOW,Psychgus::SEQUENCE_FLOW
150
-
134
+
151
135
  assert_equal Psych::Nodes::Stream::ANY,Psychgus::STREAM_ANY
152
136
  assert_equal Psych::Nodes::Stream::UTF8,Psychgus::STREAM_UTF8
153
137
  assert_equal Psych::Nodes::Stream::UTF16LE,Psychgus::STREAM_UTF16LE
154
138
  assert_equal Psych::Nodes::Stream::UTF16BE,Psychgus::STREAM_UTF16BE
155
139
  end
156
-
157
- def test_parse()
140
+
141
+ def test_parse
158
142
  parser = Psychgus.parser(stylers: @flow_styler)
159
143
  parser.parse(BURGERS_YAML)
160
- yaml = "---\n" + parser.handler.root.to_yaml()
144
+ yaml = "---\n" + parser.handler.root.to_yaml
161
145
  assert_equal EXPECTED_BURGERS,yaml
162
-
146
+
163
147
  node = Psychgus.parse(BURGERS_YAML,stylers: @flow_styler)
164
148
  refute_equal false,node
165
-
166
- yaml = Psychgus.parse_stream(BURGERS_YAML,stylers: @flow_styler).to_yaml()
149
+
150
+ yaml = Psychgus.parse_stream(BURGERS_YAML,stylers: @flow_styler).to_yaml
167
151
  yaml = "---\n#{yaml}"
168
152
  assert_equal EXPECTED_BURGERS,yaml
169
153
  end
@@ -1,42 +1,20 @@
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 (@esotericpig)
8
- #
9
- # Psychgus is free software: you can redistribute it and/or modify
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
-
24
11
  require 'minitest/autorun'
25
12
 
26
13
  require 'psychgus'
27
14
 
28
15
  # Changing the YAML/data will break tests
29
16
  class PsychgusTester < Minitest::Test
30
- # If true, will...
31
- # - Run tests that create temp file(s).
32
- # - I don't like creating temp file(s) every time I run tests (which is a lot).
33
- #
34
- # To do this, execute:
35
- # rake test_all
36
- TEST_ALL = (ENV['PSYCHGUS_TEST'].to_s().strip().casecmp('all') == 0)
37
- TEST_ALL_SKIP_MSG = %q(Execute "rake test_all" for this test)
38
-
39
- BURGERS_YAML = <<-EOY.freeze()
17
+ BURGERS_YAML = <<-YAML
40
18
  Burgers:
41
19
  Classic:
42
20
  Sauce: [Ketchup,Mustard]
@@ -54,10 +32,10 @@ Toppings:
54
32
  - Mushrooms
55
33
  - [Lettuce, Onions, Pickles, Tomatoes]
56
34
  - [[Ketchup,Mustard], [Salt,Pepper]]
57
- EOY
58
- BURGERS_DATA = Psych.load(BURGERS_YAML).freeze()
59
-
60
- COURSES_YAML = <<-EOY.freeze()
35
+ YAML
36
+ BURGERS_DATA = Psych.load(BURGERS_YAML).freeze
37
+
38
+ COURSES_YAML = <<-YAML
61
39
  Courses:
62
40
  COSC: [470,'Computer Science']
63
41
  MUSC: [340,'Music']
@@ -67,10 +45,10 @@ Schedule:
67
45
  - {Course: MUSC,Time: '10:30'}
68
46
  - {Course: ARTS,Time: '15:10'}
69
47
  - {Course: COSC,Time: '13:10'}
70
- EOY
71
- COURSES_DATA = Psych.load(COURSES_YAML).freeze()
72
-
73
- DOLPHINS_YAML = <<-EOY.freeze()
48
+ YAML
49
+ COURSES_DATA = Psych.load(COURSES_YAML).freeze
50
+
51
+ DOLPHINS_YAML = <<-YAML
74
52
  Dolphins:
75
53
  Common: &com {Length: ~2.5m, Weight: ~235kg}
76
54
  Bottlenose: &bot {Length: ~4m, Weight: ~300kg}
@@ -79,9 +57,13 @@ Dolphins:
79
57
  Popular:
80
58
  - *bot
81
59
  - *orc
82
- EOY
83
- DOLPHINS_DATA = Psych.load(DOLPHINS_YAML).freeze()
84
-
60
+ YAML
61
+ # Psych v4+ uses safe_load() by default for load(),
62
+ # so use unsafe_load() to have aliases turned on.
63
+ # Don't do 'aliases: true' because that doesn't exist
64
+ # in older versions of Psych.
65
+ DOLPHINS_DATA = Psych.unsafe_load(DOLPHINS_YAML).freeze
66
+
85
67
  # This is for "<<-" heredoc
86
68
  # - Purposely not using "<<~" (tilde) for older Ruby versions
87
69
  def self.lstrip_pipe(str)
data/test/sniffer_test.rb CHANGED
@@ -1,42 +1,30 @@
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 (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
-
23
11
  require 'psychgus_tester'
24
12
 
25
13
  require 'stringio'
26
14
 
27
15
  class SnifferTest < PsychgusTester
28
- def setup()
16
+ def setup
29
17
  end
30
-
18
+
31
19
  def assert_hierarchy(*data,expected)
32
20
  expected = self.class.lstrip_pipe(expected)
33
21
  hierarchy = Psychgus.hierarchy(*data,verbose: true)
34
-
22
+
35
23
  assert_equal expected,hierarchy
36
24
  end
37
-
38
- def test_multi_doc()
39
- assert_hierarchy(BURGERS_DATA,COURSES_DATA,DOLPHINS_DATA,<<-EOH
25
+
26
+ def test_multi_doc
27
+ assert_hierarchy(BURGERS_DATA,COURSES_DATA,DOLPHINS_DATA,<<-HIER)
40
28
  |(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
41
29
  |(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
42
30
  |(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
@@ -153,12 +141,11 @@ class SnifferTest < PsychgusTester
153
141
  | (3:1):Psych::Nodes::Sequence - <Popular:(2:2):value:(:1)>
154
142
  | (4:1):Psych::Nodes::Alias - <seq:(3:1)::(:1)>
155
143
  | (4:2):Psych::Nodes::Alias - <seq:(3:1)::(:2)>
156
- EOH
157
- )
144
+ HIER
158
145
  end
159
-
160
- def test_single_docs()
161
- assert_hierarchy(BURGERS_DATA,<<-EOH
146
+
147
+ def test_single_docs
148
+ assert_hierarchy(BURGERS_DATA,<<-HIER)
162
149
  |(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
163
150
  |(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
164
151
  |(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
@@ -205,10 +192,9 @@ class SnifferTest < PsychgusTester
205
192
  | (5:2):Psych::Nodes::Sequence - <seq:(4:3)::(:2)>
206
193
  | (6:1):Salt - <seq:(5:2)::(:1)>
207
194
  | (6:2):Pepper - <seq:(5:2)::(:2)>
208
- EOH
209
- )
210
-
211
- assert_hierarchy(COURSES_DATA,<<-EOH
195
+ HIER
196
+
197
+ assert_hierarchy(COURSES_DATA,<<-HIER)
212
198
  |(1:1):Psych::Nodes::Stream - <root:(0:0)::(:1)>
213
199
  |(1:1):Psych::Nodes::Document - <stream:(1:1)::(:1)>
214
200
  |(1:1):Psych::Nodes::Mapping - <doc:(1:1)::(:1)>
@@ -248,7 +234,6 @@ class SnifferTest < PsychgusTester
248
234
  | (6:1):COSC - <Course:(5:1):value:(:1)>
249
235
  | (5:2):Time - <map:(4:4):key:(:2)>
250
236
  | (6:1):13:10 - <Time:(5:2):value:(:1)>
251
- EOH
252
- )
237
+ HIER
253
238
  end
254
239
  end