logfmt 0.0.7 → 0.0.10

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
- SHA1:
3
- metadata.gz: 2327cc4b6b81e1f8697b774dd0100e94465d9f13
4
- data.tar.gz: 81758010bbe3acd78c67f01aa5947a27b165c70e
2
+ SHA256:
3
+ metadata.gz: 5d357083dac3dea75a9cd937ac2ba24b8cfff5c11f0656749a084cc16fb6cd4a
4
+ data.tar.gz: 97aad097b305ded6c753de8c233cd2317c12dcb9834fec52047ea799d842f8ff
5
5
  SHA512:
6
- metadata.gz: 726f73839a6139edf96a8632cd5c8bb978eb884ccb4c1ddad021ba9dc5e623b6275182340ffe6a6546321e19c082fb79e1e6346878fe3f972214c32a0f833694
7
- data.tar.gz: bf601bd78782b3fa6d52421b7a101a1c17f399c113ba033da34a535daaed62797e80e46668be3513d7483dc09115662fd900b665cdcc18a7125d4ed79e836f37
6
+ metadata.gz: 8a140be6a60d67ca2f7eb8373689e7f246e7ffadae3fba22da5820992b38df1410a5faaabc0e37ab6e318434db0ba4973b4844e74e86f3e60ef9df19aff574c8
7
+ data.tar.gz: 9df321f5d270af2e288a6de8e2391d9a05159e680ae3bfa669751a92bd0e155e30d6fc86c55f246896c20d5d274e45b93878a5f365ebb0c652c94b52d53379a2
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format progress
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## \[Unreleased\]
7
+
8
+ ## [0.0.10] 2022-04-30
9
+ ### Changed
10
+ - Autoload the `Logfmt::Parser` when it's used, in preparation for the coming `Logfmt::Logger` and friends.
11
+ Alternatively you can eager-load it into memory: `require "logfmt/parser"`.
12
+
13
+ ### Added
14
+ - This CHANGELOG file.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Logfmt
2
2
 
3
- Parse log lines on the logfmt style:
3
+ Parse log lines in the logfmt style:
4
4
 
5
- >> require "logfmt"
6
- >> Logfmt.parse('foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf')
7
- => {"foo"=>"bar", "a"=>"14", "baz"=>"hello kitty", "cool%story"=>"bro", "f"=>true, "%^asdf"=>true}
5
+ ```ruby
6
+ require "logfmt/parser"
7
+
8
+ Logfmt::Parser.parse('foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf')
9
+ #=> {"foo"=>"bar", "a"=>14, "baz"=>"hello kitty", "cool%story"=>"bro", "f"=>true, "%^asdf"=>true}
10
+ ```
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
data/bench.rb CHANGED
@@ -1,13 +1,15 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
- require 'benchmark'
4
- require 'logfmt'
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
+
5
+ require "benchmark"
6
+ require "logfmt"
5
7
 
6
8
  N = 1_000
7
9
  line = 'foo=bar a=14 baz="hello kitty" ƒ=2h3s cool%story=bro f %^asdf'
8
10
 
9
11
  Benchmark.bm(20) do |x|
10
- x.report('char-by-char') do
12
+ x.report("char-by-char") do
11
13
  N.times do
12
14
  Logfmt.parse(line)
13
15
  end
data/bin/bundle ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_requirement
64
+ @bundler_requirement ||=
65
+ env_var_version || cli_arg_version ||
66
+ bundler_requirement_for(lockfile_version)
67
+ end
68
+
69
+ def bundler_requirement_for(version)
70
+ return "#{Gem::Requirement.default}.a" unless version
71
+
72
+ bundler_gem_version = Gem::Version.new(version)
73
+
74
+ requirement = bundler_gem_version.approximate_recommendation
75
+
76
+ return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")
77
+
78
+ requirement += ".a" if bundler_gem_version.prerelease?
79
+
80
+ requirement
81
+ end
82
+
83
+ def load_bundler!
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
85
+
86
+ activate_bundler
87
+ end
88
+
89
+ def activate_bundler
90
+ gem_error = activation_error_handling do
91
+ gem "bundler", bundler_requirement
92
+ end
93
+ return if gem_error.nil?
94
+ require_error = activation_error_handling do
95
+ require "bundler/version"
96
+ end
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
+ exit 42
100
+ end
101
+
102
+ def activation_error_handling
103
+ yield
104
+ nil
105
+ rescue StandardError, LoadError => e
106
+ e
107
+ end
108
+ end
109
+
110
+ m.load_bundler!
111
+
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "logfmt"
6
+
7
+ require "pry"
8
+ Pry.start
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/lib/logfmt/parser.rb CHANGED
@@ -1,109 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../logfmt"
4
+
1
5
  module Logfmt
2
- GARBAGE = 0
3
- KEY = 1
4
- EQUAL = 2
5
- IVALUE = 3
6
- QVALUE = 4
6
+ module Parser
7
+ GARBAGE = 0
8
+ KEY = 1
9
+ EQUAL = 2
10
+ IVALUE = 3
11
+ QVALUE = 4
7
12
 
8
- def self.numeric?(s)
9
- s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/)
10
- end
13
+ def self.numeric?(s)
14
+ s.is_a?(Numeric) || s.to_s.match?(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/)
15
+ end
11
16
 
12
- def self.integer?(s)
13
- s.match(/\A[-+]?[0-9]+\Z/)
14
- end
17
+ def self.integer?(s)
18
+ s.is_a?(Integer) || s.to_s.match?(/\A[-+]?[0-9]+\Z/)
19
+ end
15
20
 
16
- def self.parse(line)
17
- output = {}
18
- key, value = '', ''
19
- escaped = false
20
- state = GARBAGE
21
- i = 0
22
- line.each_char do |c|
23
- i += 1
24
- if state == GARBAGE
25
- if c > ' ' && c != '"' && c != '='
26
- key = c
27
- state = KEY
28
- end
29
- next
30
- end
31
- if state == KEY
32
- if c > ' ' && c != '"' && c != '='
33
- state = KEY
34
- key << c
35
- elsif c == '='
36
- output[key.strip] = true
37
- state = EQUAL
38
- else
39
- output[key.strip] = true
40
- state = GARBAGE
41
- end
42
- output[key.strip] = true if i >= line.length
43
- next
44
- end
45
- if state == EQUAL
46
- if c > ' ' && c != '"' && c != '='
47
- value = c
48
- state = IVALUE
49
- elsif c == '"'
50
- value = ''
51
- escaped = false
52
- state = QVALUE
53
- else
54
- state = GARBAGE
21
+ def self.parse(line)
22
+ output = {}
23
+ key, value = +"", +""
24
+ escaped = false
25
+ state = GARBAGE
26
+ i = 0
27
+ line.each_char do |c|
28
+ i += 1
29
+ if state == GARBAGE
30
+ if c > " " && c != '"' && c != "="
31
+ key = c
32
+ state = KEY
33
+ end
34
+ next
55
35
  end
56
- if i >= line.length
57
- if integer?(value)
58
- value = Integer(value)
59
- elsif numeric?(value)
60
- value = Float(value)
36
+ if state == KEY
37
+ if c > " " && c != '"' && c != "="
38
+ state = KEY
39
+ key << c
40
+ elsif c == "="
41
+ output[key.strip] = true
42
+ state = EQUAL
43
+ else
44
+ output[key.strip] = true
45
+ state = GARBAGE
61
46
  end
62
- output[key.strip] = value || true
47
+ output[key.strip] = true if i >= line.length
48
+ next
63
49
  end
64
- next
65
- end
66
- if state == IVALUE
67
- if !(c > ' ' && c != '"' && c != '=')
68
- if integer?(value)
69
- value = Integer(value)
70
- elsif numeric?(value)
71
- value = Float(value)
50
+ if state == EQUAL
51
+ if c > " " && c != '"' && c != "="
52
+ value = c
53
+ state = IVALUE
54
+ elsif c == '"'
55
+ value = +""
56
+ escaped = false
57
+ state = QVALUE
58
+ else
59
+ state = GARBAGE
72
60
  end
73
- output[key.strip] = value
74
- state = GARBAGE
75
- else
76
- value << c
61
+ if i >= line.length
62
+ if integer?(value)
63
+ value = value.to_i
64
+ elsif numeric?(value)
65
+ fvalue = value.to_f
66
+ value = fvalue if fvalue.finite?
67
+ end
68
+ output[key.strip] = value || true
69
+ end
70
+ next
77
71
  end
78
- if i >= line.length
79
- if integer?(value)
80
- value = Integer(value)
81
- elsif numeric?(value)
82
- value = Float(value)
72
+ if state == IVALUE
73
+ if !(c > " " && c != '"')
74
+ if integer?(value)
75
+ value = value.to_i
76
+ elsif numeric?(value)
77
+ fvalue = value.to_f
78
+ value = fvalue if fvalue.finite?
79
+ end
80
+ output[key.strip] = value
81
+ state = GARBAGE
82
+ else
83
+ value << c
83
84
  end
84
- output[key.strip] = value
85
+ if i >= line.length
86
+ if integer?(value)
87
+ value = value.to_i
88
+ elsif numeric?(value)
89
+ fvalue = value.to_f
90
+ value = fvalue if fvalue.finite?
91
+ end
92
+ output[key.strip] = value
93
+ end
94
+ next
85
95
  end
86
- next
87
- end
88
- if state == QVALUE
89
- if c == '\\'
90
- escaped = true
91
- value << '\\'
92
- elsif c == '"'
93
- if escaped
96
+ if state == QVALUE
97
+ if c == "\\"
98
+ escaped = true
99
+ value << "\\"
100
+ elsif c == '"'
101
+ if escaped
102
+ escaped = false
103
+ value.chop! << c
104
+ next
105
+ end
106
+ output[key.strip] = value
107
+ state = GARBAGE
108
+ else
94
109
  escaped = false
95
110
  value << c
96
- next
97
111
  end
98
- output[key.strip] = value
99
- state = GARBAGE
100
- else
101
- escaped = false
102
- value << c
112
+ next
103
113
  end
104
- next
105
114
  end
115
+ output
106
116
  end
107
- output
108
117
  end
109
118
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Logfmt
2
- VERSION = '0.0.7'
4
+ VERSION = "0.0.10"
3
5
  end
data/lib/logfmt.rb CHANGED
@@ -1,2 +1,11 @@
1
- require 'logfmt/version'
2
- require 'logfmt/parser'
1
+ # frozen_string_literal: true
2
+
3
+ require "logfmt/version"
4
+
5
+ module Logfmt
6
+ autoload(:Parser, "logfmt/parser")
7
+
8
+ def self.parse(line)
9
+ const_get(:Parser).parse(line)
10
+ end
11
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logfmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothée Peignier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-28 00:00:00.000000000 Z
11
+ date: 2022-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: pry-byebug
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '3.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '3.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.3'
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.3'
54
+ version: '3.0'
41
55
  description: Parse log lines in the logfmt style.
42
56
  email:
43
57
  - timothee.peignier@tryphon.org
@@ -45,23 +59,27 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - ".gitignore"
49
62
  - ".rspec"
50
- - ".travis-ci.yml"
63
+ - CHANGELOG.md
51
64
  - Gemfile
52
65
  - README.md
53
66
  - Rakefile
54
67
  - bench.rb
68
+ - bin/bundle
69
+ - bin/console
70
+ - bin/rake
71
+ - bin/rspec
55
72
  - lib/logfmt.rb
56
73
  - lib/logfmt/parser.rb
57
74
  - lib/logfmt/version.rb
58
- - logfmt.gemspec
59
- - spec/logfmt/parser_spec.rb
60
- - spec/spec_helper.rb
61
75
  homepage: https://github.com/cyberdelia/logfmt-ruby
62
76
  licenses:
63
77
  - MIT
64
- metadata: {}
78
+ metadata:
79
+ bug_tracker_uri: https://github.com/cyberdelia/logfmt-ruby/issues
80
+ changelog_uri: https://github.com/cyberdelia/logfmt-ruby/blog/master/CHANGELOG.md
81
+ documentation_uri: https://github.com/cyberdelia/logfmt-ruby
82
+ source_code_uri: https://github.com/cyberdelia/logfmt-ruby
65
83
  post_install_message:
66
84
  rdoc_options: []
67
85
  require_paths:
@@ -70,18 +88,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
88
  requirements:
71
89
  - - ">="
72
90
  - !ruby/object:Gem::Version
73
- version: '0'
91
+ version: 2.4.0
74
92
  required_rubygems_version: !ruby/object:Gem::Requirement
75
93
  requirements:
76
94
  - - ">="
77
95
  - !ruby/object:Gem::Version
78
96
  version: '0'
79
97
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.2.2
98
+ rubygems_version: 3.3.7
82
99
  signing_key:
83
100
  specification_version: 4
84
101
  summary: Parse logfmt messages.
85
- test_files:
86
- - spec/logfmt/parser_spec.rb
87
- - spec/spec_helper.rb
102
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .ruby-version
data/.travis-ci.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
6
- script: bundle exec rspec spec
data/logfmt.gemspec DELETED
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'logfmt/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = 'logfmt'
8
- gem.version = Logfmt::VERSION
9
- gem.authors = ['Timothée Peignier']
10
- gem.email = ['timothee.peignier@tryphon.org']
11
- gem.description = %q{Parse log lines in the logfmt style.}
12
- gem.summary = %q{Parse logfmt messages.}
13
- gem.homepage = 'https://github.com/cyberdelia/logfmt-ruby'
14
- gem.license = 'MIT'
15
-
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ['lib']
20
- gem.add_development_dependency 'rspec', '~> 3.0'
21
- gem.add_development_dependency 'rake', '~> 10.3'
22
- end
@@ -1,134 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'logfmt/parser'
4
-
5
- describe Logfmt do
6
- it 'parse empty log line' do
7
- data = Logfmt.parse('')
8
- expect(data).to eq({})
9
- end
10
-
11
- it 'parse whitespace only log line' do
12
- data = Logfmt.parse("\t")
13
- expect(data).to eq({})
14
- end
15
-
16
- it 'parse key without value' do
17
- data = Logfmt.parse('key')
18
- expect(data).to eq('key' => true)
19
- end
20
-
21
- it 'parse key without value and whitespace' do
22
- data = Logfmt.parse(' key ')
23
- expect(data).to eq('key' => true)
24
- end
25
-
26
- it 'parse multiple single keys' do
27
- data = Logfmt.parse('key1 key2')
28
- expect(data).to eq('key1' => true, 'key2' => true)
29
- end
30
-
31
- it 'parse unquoted value' do
32
- data = Logfmt.parse('key=value')
33
- expect(data).to eq('key' => 'value')
34
- end
35
-
36
- it 'parse pairs' do
37
- data = Logfmt.parse('key1=value1 key2=value2')
38
- expect(data).to eq('key1' => 'value1', 'key2' => 'value2')
39
- end
40
-
41
- it 'parse mixed single/non-single pairs' do
42
- data = Logfmt.parse('key1=value1 key2')
43
- expect(data).to eq('key1' => 'value1', 'key2' => true)
44
- end
45
-
46
- it 'parse mixed pairs whatever the order' do
47
- data = Logfmt.parse('key1 key2=value2')
48
- expect(data).to eq('key1' => true, 'key2' => 'value2')
49
- end
50
-
51
- it 'parse quoted value' do
52
- data = Logfmt.parse('key="quoted value"')
53
- expect(data).to eq('key' => 'quoted value')
54
- end
55
-
56
- it 'parse escaped quote value ' do
57
- data = Logfmt.parse('key="quoted \" value" r="esc\t"')
58
- expect(data).to eq('key' => 'quoted \" value', 'r' => 'esc\\t')
59
- end
60
-
61
- it 'parse mixed pairs' do
62
- data = Logfmt.parse('key1="quoted \" value" key2 key3=value3')
63
- expect(data).to eq('key1' => 'quoted \" value', 'key2' => true, 'key3' => 'value3')
64
- end
65
-
66
- it 'parse mixed characters pairs' do
67
- data = Logfmt.parse('foo=bar a=14 baz="hello kitty" ƒ=2h3s cool%story=bro f %^asdf')
68
- expect(data).to eq('foo' => 'bar', 'a' => 14, 'baz' => 'hello kitty',
69
- 'ƒ' => '2h3s', 'cool%story' => 'bro', 'f' => true, '%^asdf' => true)
70
- end
71
-
72
- it 'parse pair with empty quote' do
73
- data = Logfmt.parse('key=""')
74
- expect(data).to eq('key' => '')
75
- end
76
-
77
- # Currently, the value comes back as "true", which could mess up stats
78
- # Really, only "true" should come back as "true"
79
- # it 'parse 1 as integer type' do
80
- # data = Logfmt.parse('key=1')
81
- # expect(data['key'].class).to eq(Fixnum)
82
- # end
83
-
84
- it 'parse positive integer as integer type' do
85
- data = Logfmt.parse('key=234')
86
- expect(data['key']).to eq(234)
87
- expect(data['key'].class).to eq(Fixnum)
88
- end
89
-
90
- it 'parse negative integer as integer type' do
91
- data = Logfmt.parse('key=-3428')
92
- expect(data['key']).to eq(-3428)
93
- expect(data['key'].class).to eq(Fixnum)
94
- end
95
-
96
- it 'parse positive float as float type' do
97
- data = Logfmt.parse('key=3.342')
98
- expect(data['key']).to eq(3.342)
99
- expect(data['key'].class).to eq(Float)
100
- end
101
-
102
- it 'parse negative float as float type' do
103
- data = Logfmt.parse('key=-0.9934')
104
- expect(data['key']).to eq(-0.9934)
105
- expect(data['key'].class).to eq(Float)
106
- end
107
-
108
- it 'parse exponential float as float type' do
109
- data = Logfmt.parse('key=2.342342342342344e+18')
110
- expect(data['key']).to eq(2.342342342342344e+18)
111
- expect(data['key'].class).to eq(Float)
112
- end
113
-
114
- it 'parse quoted integer as string type' do
115
- data = Logfmt.parse('key="234"')
116
- expect(data['key'].class).to eq(String)
117
- end
118
-
119
- it 'parse quoted float as string type' do
120
- data = Logfmt.parse('key="3.14"')
121
- expect(data['key'].class).to eq(String)
122
- end
123
-
124
- it 'parse IP address as string type' do
125
- data = Logfmt.parse('key=10.10.10.1')
126
- expect(data['key'].class).to eq(String)
127
- end
128
-
129
- it 'parse last as integer type' do
130
- data = Logfmt.parse('key1=4 key2=9')
131
- expect(data['key1']).to eq(4)
132
- expect(data['key2']).to eq(9)
133
- end
134
- end
data/spec/spec_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
- RSpec.configure do |config|
8
- config.run_all_when_everything_filtered = true
9
- config.filter_run :focus
10
-
11
- # Run specs in random order to surface order dependencies. If you find an
12
- # order dependency and want to debug it, you can fix the order by providing
13
- # the seed, which is printed after each run.
14
- # --seed 1234
15
- config.order = 'random'
16
- end