ios_parser 0.6.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abbb84cb462b8506f141ce88c1333f8f25e8bc9f31e5bc166d2f76f275044529
4
- data.tar.gz: 7ed4f70c4396caae3d84df7dc17176b5a4c1e1f4eede31cdf63af8d34c61285f
3
+ metadata.gz: d622ced70b173f1c2b514b3060694ecf722641e098367551ac66878c40059c5f
4
+ data.tar.gz: 20fedb53829b28a18ce1d5aa72107b13534ea3b01118a7b988fc6f4b4d01a83c
5
5
  SHA512:
6
- metadata.gz: 209623e73042e19dd5bb9108f3aee56ab357e2b84ad388f028e1055cf90eee73fc9040c448e6e394729880a3690abc38e2c945371dac73a7004db3bab78180a2
7
- data.tar.gz: dc1b41a7d3e821d9bfdb2ce9e4b6cad8012396b2ba3ed1e39b56eecc7582870e829e8cb512ebca9a68ffb281c13aab1c5c7d6af48c53cec9ede3bbcc58078bb5
6
+ metadata.gz: 5ab205f2e84a5bf71e3bf1ceb1b2b8c5cef6bfcf0900ca4d472fcd1079174a448549efba14d58597eb04cde8f5bf29d5c059db14624b2695b763a75f5468df1f
7
+ data.tar.gz: 36fd7e6722935457f9c8e3f60231fe37c4c5fe0ee9a6a9922ed45a5a5b9fbd7d26f9b631056298a8b95acdeb7f4c5e6a136b4df9d0ede939918062e292766231
@@ -0,0 +1,48 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ matrix:
24
+ ruby-version:
25
+ - '2.0'
26
+ - '2.1'
27
+ - '2.2'
28
+ - '2.3'
29
+ - '2.4'
30
+ - '2.5'
31
+ - '2.6'
32
+ - '2.7'
33
+ - '3.0'
34
+ - '3.1'
35
+ - jruby-9.1.17.0
36
+ - jruby-9.2.21.0
37
+ - jruby-9.3.6.0
38
+
39
+ steps:
40
+ - uses: actions/checkout@v3
41
+ - name: Set up Ruby
42
+ # https://github.com/ruby/setup-ruby#versioning
43
+ uses: ruby/setup-ruby@v1
44
+ with:
45
+ ruby-version: ${{ matrix.ruby-version }}
46
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
47
+ - name: Run tests
48
+ run: bundle exec rake
@@ -87,6 +87,33 @@ int is_certificate(LexInfo *lex) {
87
87
  return 1;
88
88
  }
89
89
 
90
+ int is_authentication_banner_begin(LexInfo *lex) {
91
+ VALUE authentication_ary, authentication, banner_ary, banner;
92
+ int token_count = RARRAY_LEN(lex->tokens);
93
+ int authentication_pos = token_count -2;
94
+ int banner_pos = token_count - 1;
95
+
96
+ if (banner_pos < 0) { return 0; }
97
+
98
+ banner_ary = rb_ary_entry(lex->tokens, banner_pos);
99
+ banner = TOKEN_VALUE(banner_ary);
100
+ if (TYPE(banner) != T_STRING) { return 0; }
101
+
102
+ StringValue(banner);
103
+ if (RSTRING_LEN(banner) != CMD_LEN("banner")) { return 0; }
104
+ if (0 != strncmp(RSTRING_PTR(banner), "banner", 6)) { return 0; }
105
+
106
+ authentication_ary = rb_ary_entry(lex->tokens, authentication_pos);
107
+ authentication = TOKEN_VALUE(authentication_ary);
108
+ if (TYPE(authentication) != T_STRING) { return 0; }
109
+
110
+ StringValue(authentication);
111
+ if (RSTRING_LEN(authentication) != CMD_LEN("authentication")) { return 0; }
112
+ if (0 != strncmp(RSTRING_PTR(authentication), "authentication", 14)) { return 0; }
113
+
114
+ return 1;
115
+ }
116
+
90
117
  int is_banner_begin(LexInfo *lex) {
91
118
  VALUE banner_ary, banner;
92
119
  int token_count = RARRAY_LEN(lex->tokens);
@@ -94,6 +121,8 @@ int is_banner_begin(LexInfo *lex) {
94
121
 
95
122
  if (banner_pos < 0) { return 0; }
96
123
 
124
+ if (is_authentication_banner_begin(lex)) { return 1; }
125
+
97
126
  banner_ary = rb_ary_entry(lex->tokens, banner_pos);
98
127
  banner = TOKEN_VALUE(banner_ary);
99
128
  if (TYPE(banner) != T_STRING) { return 0; }
@@ -125,7 +154,7 @@ static void delimit(LexInfo *lex) {
125
154
  case (LEX_STATE_INTEGER):
126
155
  strncpy(string, &lex->text[lex->token_start], lex->token_length);
127
156
  string[lex->token_length] = '\0';
128
- token = rb_int_new(atoi(string));
157
+ token = rb_int_new(atoll(string));
129
158
  break;
130
159
 
131
160
  case (LEX_STATE_DECIMAL):
data/ios_parser.gemspec CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.extensions << 'ext/ios_parser/c_lexer/extconf.rb'
20
20
  end
21
21
 
22
+ s.required_ruby_version = '>=2.0'
23
+
22
24
  s.add_development_dependency 'rake-compiler', '~>0.9'
23
25
  s.add_development_dependency 'rspec', '~>3.2'
24
26
  s.add_development_dependency 'rubocop', '~> 0.54' if RUBY_VERSION > '2.1'
@@ -21,7 +21,7 @@ module IOSParser
21
21
  end
22
22
 
23
23
  def name
24
- tokens.first.value
24
+ (tokens.first) && tokens.first.value
25
25
  end
26
26
 
27
27
  def ==(other)
@@ -64,7 +64,7 @@ module IOSParser
64
64
 
65
65
  def to_s(dedent: false)
66
66
  indent_opts = { base: dedent ? path.length : 0 }
67
- map { |cmd| "#{cmd.indentation(indent_opts)}#{cmd.line}\n" }.join
67
+ map { |cmd| "#{cmd.indentation(**indent_opts)}#{cmd.line}\n" }.join
68
68
  end
69
69
 
70
70
  def to_hash
@@ -92,7 +92,7 @@ module IOSParser
92
92
  hash[:commands].each_index do |i|
93
93
  hash[:commands][i] = from_hash(hash[:commands][i])
94
94
  end
95
- new(hash)
95
+ new(**hash)
96
96
  end
97
97
  end
98
98
  end # class Command
@@ -46,7 +46,7 @@ module IOSParser
46
46
  indent: @indent
47
47
  }
48
48
 
49
- Command.new(opts).tap do |cmd|
49
+ Command.new(**opts).tap do |cmd|
50
50
  cmd.commands = subsections(cmd)
51
51
  end
52
52
  end
@@ -113,7 +113,10 @@ module IOSParser
113
113
  end
114
114
 
115
115
  def banner_begin?
116
- tokens[-2] && tokens[-2].value == 'banner'
116
+ tokens[-2] && (
117
+ tokens[-2].value == 'banner' ||
118
+ tokens[-2..-1].map(&:value) == %w[authentication banner]
119
+ )
117
120
  end
118
121
 
119
122
  def banner
@@ -1,7 +1,7 @@
1
1
  module IOSParser
2
2
  class << self
3
3
  def version
4
- '0.6.0'
4
+ '0.8.0'
5
5
  end
6
6
  end
7
7
  end
@@ -137,6 +137,29 @@ END
137
137
  it { expect(subject_pure.map(&:value)).to eq output }
138
138
  end
139
139
 
140
+ context 'aaa authentication banner' do
141
+ let(:input) { <<END.unindent }
142
+ aaa authentication banner ^C
143
+ xyz
144
+ ^C
145
+ aaa blah
146
+ END
147
+
148
+ let(:output) do
149
+ ['aaa', 'authentication', 'banner',
150
+ :BANNER_BEGIN, "xyz\n", :BANNER_END, :EOL,
151
+ 'aaa', 'blah', :EOL]
152
+ end
153
+
154
+ it 'lexes (c lexer)' do
155
+ expect(subject.map(&:value)).to eq output
156
+ end
157
+
158
+ it 'lexes (ruby lexer)' do
159
+ expect(subject_pure.map(&:value)).to eq output
160
+ end
161
+ end
162
+
140
163
  context 'decimal number' do
141
164
  let(:input) { 'boson levels at 93.2' }
142
165
  let(:output) { ['boson', 'levels', 'at', 93.2] }
@@ -356,6 +379,19 @@ END
356
379
  it { expect(subject_pure.map(&:value)).to eq output }
357
380
  it { expect(subject.map(&:value)).to eq output }
358
381
  end # context 'comment at end of line' do
382
+
383
+ context 'large integers up to 2^63-1' do
384
+ let(:input) do
385
+ "42 4200000000 9223372036854775807"
386
+ end
387
+
388
+ let(:output) do
389
+ [42, 4200000000, 9223372036854775807]
390
+ end
391
+
392
+ it { expect(subject_pure.map(&:value)).to eq output }
393
+ it { expect(subject.map(&:value)).to eq output }
394
+ end # context 'large integers up to 2^63-1' do
359
395
  end
360
396
  end
361
397
  end
@@ -3,6 +3,20 @@ require 'ios_parser'
3
3
 
4
4
  describe IOSParser do
5
5
  describe '.parse' do
6
+ context 'with blank line at start' do
7
+ it 'parses and extracts sections' do
8
+ parser = IOSParser.parse("\ntest config")
9
+ expect(parser.find_all(name: "test").count).to eq 1
10
+ end
11
+ end
12
+
13
+ context 'with blank line in middle' do
14
+ it 'parses and extracts sections' do
15
+ parser = IOSParser.parse("preamble\n\ntest config")
16
+ expect(parser.find_all(name: "test").count).to eq 1
17
+ end
18
+ end
19
+
6
20
  context 'indented region' do
7
21
  let(:input) { <<-END.unindent }
8
22
  policy-map mypolicy_in
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ios_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Miller
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -52,16 +52,16 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.54'
55
- description:
55
+ description:
56
56
  email: bjmllr@gmail.com
57
57
  executables: []
58
58
  extensions:
59
59
  - ext/ios_parser/c_lexer/extconf.rb
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/ruby.yml"
62
63
  - ".gitignore"
63
64
  - ".rubocop.yml"
64
- - ".travis.yml"
65
65
  - CHANGELOG.md
66
66
  - CODE_OF_CONDUCT.md
67
67
  - Gemfile
@@ -95,7 +95,7 @@ homepage: https://github.com/bjmllr/ios_parser
95
95
  licenses:
96
96
  - GPL-3.0
97
97
  metadata: {}
98
- post_install_message:
98
+ post_install_message:
99
99
  rdoc_options: []
100
100
  require_paths:
101
101
  - lib
@@ -103,16 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: '2.0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.7.3
115
- signing_key:
113
+ rubygems_version: 3.1.6
114
+ signing_key:
116
115
  specification_version: 4
117
116
  summary: convert network switch and router config files to structured data
118
117
  test_files:
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.10
6
- - 2.3.8
7
- - 2.4.5
8
- - 2.5.3
9
- - jruby-9.1.16.0
10
- - jruby-9.2.0.0
11
- matrix:
12
- include:
13
- - rvm: jruby
14
- env: JRUBY_OPTS='-Xcompat.version=2.0'
15
- bundler_args: --without guard
16
- before_install:
17
- - if [ "jruby" != "$TRAVIS_RUBY_VERSION" ]; then gem i rubygems-update -v '<3' && update_rubygems; gem install bundler -v 1.17.3 --without guard; fi