clocale 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 77da4c8e02189b850a4d3899ec6b31438faece31
4
- data.tar.gz: 49ea1a19cc344523a9e5a38d356d59a20b99dbbc
2
+ SHA256:
3
+ metadata.gz: 754426568e2bd5d5ca12e2aa4eaf352f58ad320f74cfe521c1be6afb40812fa6
4
+ data.tar.gz: ae661ea430059426eae209d78ebcb01defb1cb51d454825b6858569da2257fed
5
5
  SHA512:
6
- metadata.gz: '07129a7dd8e2d3da9e8c321a486effe639f2670fc2f2431115892dd6e5c9ccc4aaefb202a43f98847605aea7f481b7b13130934d0173ae268ea146dde08cad78'
7
- data.tar.gz: f22eac2aab0616901b5188e8a454eb96e419c9452b5752dd5aad1d08e305779ffff55e85bd202840260d4f822300d6da11e45369f525dcbf06d1222163653b7b
6
+ metadata.gz: 3d332dce7214607e2736506a75826fa6e6a7b8d68cfbc26d460706a786d011fce66ba747fbb28c5f012dbdf6b1dd5495814973b95817cda20c4649f13188242c
7
+ data.tar.gz: 3f41b2b35b1ff4c06452edb11a299e34c7e1698421c5e492821eafdfb67cd2da838d6139e1ca5d4cda34161b634b164726c22e2b0d7906ed05868ff83a59fe18
@@ -5,6 +5,7 @@ environment:
5
5
  matrix:
6
6
  - RUBY_VERSION: 24
7
7
  - RUBY_VERSION: 24-x64
8
+ - RUBY_VERSION: 25-x64
8
9
 
9
10
  cache:
10
11
  - vendor/bundle
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ require: rubocop-rspec
2
+
3
+ Metrics/LineLength:
4
+ Max: 100
5
+
6
+ Style/BlockComments:
7
+ Exclude:
8
+ - 'spec/spec_helper.rb'
9
+
10
+ Layout/EndOfLine:
11
+ EnforcedStyle: lf # enforce LF line endings on all platforms
12
+
13
+ Style/BlockDelimiters:
14
+ EnforcedStyle: braces_for_chaining
@@ -0,0 +1,20 @@
1
+ conditions: v1
2
+
3
+ if: type = pull_request OR tag IS present
4
+
5
+ os:
6
+ - linux
7
+ - osx
8
+
9
+ language: ruby
10
+
11
+ rvm:
12
+ - '2.3'
13
+ - '2.4'
14
+ - '2.5'
15
+
16
+ install:
17
+ - bundle install --path vendor/bundle
18
+
19
+ script:
20
+ - bundle exec rake
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # clocale
1
+ # clocale [![travis-badge][]][travis] [![appveyor-badge][]][appveyor] [![codecov-badge][]][codecov]
2
2
 
3
- [![Build
4
- status](https://ci.appveyor.com/api/projects/status/l7pp3mjqvocb2n9r/branch/master?svg=true)](https://ci.appveyor.com/project/avdv/clocale/branch/master)
3
+ [travis]: https://travis-ci.org/avdv/clocale
4
+ [travis-badge]: https://travis-ci.org/avdv/clocale.svg?branch=master
5
+ [appveyor]: https://ci.appveyor.com/project/avdv/clocale/branch/master
6
+ [appveyor-badge]: https://ci.appveyor.com/api/projects/status/l7pp3mjqvocb2n9r/branch/master?svg=true
7
+ [codecov]: https://codecov.io/gh/avdv/clocale
8
+ [codecov-badge]: https://codecov.io/gh/avdv/clocale/branch/master/graph/badge.svg
5
9
 
6
10
  This Ruby extension provides access to the C library's `setlocale`, `strxfrm`
7
11
  and `strcoll` functions which are inherently useful for proper sorting
data/Rakefile CHANGED
@@ -3,6 +3,14 @@ require 'rubygems/tasks'
3
3
 
4
4
  Gem::Tasks.new
5
5
 
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.ruby_opts = '-w'
9
+ end
10
+
11
+ require 'rubocop/rake_task'
12
+ RuboCop::RakeTask.new
13
+
6
14
  Rake::ExtensionTask.new 'clocale' do |ext|
7
15
  ext.lib_dir = 'lib/clocale'
8
16
  end
@@ -13,4 +21,5 @@ task test: %w[compile] do
13
21
  ruby '-Ilib', '-rclocale', '-e', 'p CLocale.setlocale(CLocale::LC_ALL, "")'
14
22
  end
15
23
 
16
- task default: :test
24
+ task spec: :compile
25
+ task default: %i[spec rubocop]
@@ -1,19 +1,23 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'clocale'
3
- spec.version = '0.0.3'
3
+ spec.version = '0.0.4'
4
4
  spec.authors = ['Claudio Bley']
5
5
  spec.email = ['claudio.bley@gmail.com']
6
- spec.summary = "A Ruby gem that wraps C locale functions."
6
+ spec.summary = 'A Ruby gem that wraps C locale functions.'
7
7
  spec.homepage = 'https://github.com/avdv/clocale'
8
8
  spec.license = 'MIT'
9
9
 
10
10
  spec.extensions = %w[ext/clocale/extconf.rb]
11
11
 
12
12
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
13
- f.match(%r{^.gitignore})
13
+ f.match(/^.gitignore/)
14
14
  end
15
15
 
16
+ spec.add_development_dependency 'codecov', '~> 0.1.10'
16
17
  spec.add_development_dependency 'rake', '~> 12.3'
17
18
  spec.add_development_dependency 'rake-compiler', '~> 1.0'
19
+ spec.add_development_dependency 'rspec', '~> 3.7'
20
+ spec.add_development_dependency 'rubocop', '~> 0.58'
21
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
18
22
  spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
19
23
  end
@@ -2,6 +2,25 @@
2
2
  #include <locale.h>
3
3
  #include <string.h>
4
4
 
5
+ /*
6
+ * Changes or queries the locale for a specific category.
7
+ *
8
+ * @param category [Integer] one of the constants defined in the CLocale module
9
+ * @param locale [String, nil] Possible values for `locale`:
10
+ *
11
+ * <tt>nil</tt>:: query the current setting, does not change the programs locale
12
+ *
13
+ * <tt>""</tt>:: specifies an implementation defined native environment
14
+ *
15
+ * <tt>"C"</tt>:: specifies a minimal "portable" locale
16
+ *
17
+ * @return [String] the value associated with the category
18
+ *
19
+ * @raise [RuntimeError] if setting the locale fails
20
+ *
21
+ * Calls the <tt>setlocale()</tt> C library function, see
22
+ * http://pubs.opengroup.org/onlinepubs/009695399/functions/setlocale.html.
23
+ */
5
24
  static VALUE
6
25
  lc_setlocale(VALUE self, VALUE category, VALUE locale) {
7
26
  const char* loc = NULL;
@@ -13,12 +32,29 @@ lc_setlocale(VALUE self, VALUE category, VALUE locale) {
13
32
  char* ret = setlocale(cat, loc);
14
33
 
15
34
  if (ret == NULL) {
16
- rb_raise(rb_eRuntimeError, "error calling setlocale(%d, \"%s\")", cat, loc);
35
+ VALUE sym = rb_funcall(self, rb_intern("lookup_const"), 1, category);
36
+
37
+ if (NIL_P(sym)) {
38
+ rb_raise(rb_eRuntimeError, "error calling `setlocale(%d, \"%s\")`", cat, loc);
39
+ } else {
40
+ rb_raise(rb_eRuntimeError, "error calling `setlocale(%" PRIsVALUE ", \"%s\")`", sym, loc);
41
+ }
17
42
  } else {
18
43
  return rb_str_new2(ret);
19
44
  }
20
45
  }
21
46
 
47
+ /*
48
+ * Compares two Strings using the current locale.
49
+ *
50
+ * @param s1 [String]
51
+ * @param s2 [String]
52
+ *
53
+ * @return [Integer] -1, 0, +1 if s1 is less than, equal to, or greater than s2 respectively
54
+ *
55
+ * Calls the <tt>strcoll()</tt> C library function, see
56
+ * http://pubs.opengroup.org/onlinepubs/009695399/functions/strcoll.html.
57
+ */
22
58
  static VALUE
23
59
  lc_strcoll(VALUE self, VALUE s1, VALUE s2) {
24
60
  int ret = strcoll(StringValueCStr(s1), StringValueCStr(s2));
@@ -30,6 +66,19 @@ lc_strcoll(VALUE self, VALUE s1, VALUE s2) {
30
66
  return INT2FIX(ret);
31
67
  }
32
68
 
69
+ /*
70
+ * Transform the given String into a canonical form for char comparison.
71
+ *
72
+ * This is useful for sorting a list using Enumerable#sort_by which does a
73
+ * Schwartzian transform.
74
+ *
75
+ * @param s [String]
76
+ *
77
+ * @return [String] transformed according to the current <tt>LC_COLLATE</tt> locale setting
78
+ *
79
+ * Calls the <tt>strxfrm</tt> C library function, see
80
+ * http://pubs.opengroup.org/onlinepubs/009695399/functions/strxfrm.html.
81
+ */
33
82
  static VALUE
34
83
  lc_strxfrm(VALUE self, VALUE str) {
35
84
  VALUE ret;
@@ -50,7 +99,7 @@ lc_strxfrm(VALUE self, VALUE str) {
50
99
  size = needed + 1;
51
100
  buf = realloc(buf, size);
52
101
 
53
- if (buf == NULL) rb_raise(rb_eNoMemError, "could not allocate %u bytes", size);
102
+ if (buf == NULL) rb_raise(rb_eNoMemError, "could not allocate %zu bytes", size);
54
103
  }
55
104
  }
56
105
 
@@ -2,7 +2,7 @@ require 'mkmf'
2
2
 
3
3
  def check_functions
4
4
  %w[setlocale strcoll strxfrm].each do |func|
5
- abort "missing function `#{ func }``" unless have_func func
5
+ abort "missing function `#{func}``" unless have_func func
6
6
  end
7
7
  end
8
8
 
@@ -1,2 +1,15 @@
1
+ # This module defines the `LC_*` constants and locale functions from the linked
2
+ # C library of the current Ruby interpreter.
3
+ #
4
+ # @author Claudio Bley <claudio.bley@gmail.com>
5
+ module CLocale
6
+ # Looks up the constant corresponding to the given integer value.
7
+ #
8
+ # @param int [Integer]
9
+ # @return [Symbol,nil] the <tt>LC_*</tt> constant as Symbol if found, nil otherwise
10
+ def self.lookup_const(int)
11
+ CLocale.constants.find { |s| CLocale.const_get(s) == int }
12
+ end
13
+ end
1
14
 
2
15
  require 'clocale/clocale'
@@ -0,0 +1,29 @@
1
+ require 'clocale'
2
+
3
+ RSpec.describe CLocale do
4
+ %i[LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME].each do |const|
5
+ it "has #{const} constant" do
6
+ is_expected.to(satisfy { |m| m.const_defined? const })
7
+ end
8
+ end
9
+
10
+ describe 'lookup' do
11
+ described_class.constants.each do |const|
12
+ it "returns corresponding symbol for #{const}" do
13
+ int = described_class.const_get const
14
+
15
+ expect(described_class.lookup_const(int)).to eq(const)
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'can call setlocale' do
21
+ expect { described_class.setlocale(CLocale::LC_ALL, '') }.not_to raise_error
22
+ end
23
+
24
+ it 'raises an error with invalid locales' do
25
+ expect {
26
+ described_class.setlocale(CLocale::LC_COLLATE, 'FOOBAR')
27
+ }.to raise_error(RuntimeError, /LC_COLLATE/)
28
+ end
29
+ end
@@ -0,0 +1,108 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ if ENV['CI']
5
+ require 'codecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
7
+ end
8
+
9
+ # This file was generated by the `rspec --init` command. Conventionally, all
10
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
11
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
12
+ # this file to always be loaded, without a need to explicitly require it in any
13
+ # files.
14
+ #
15
+ # Given that it is always loaded, you are encouraged to keep this file as
16
+ # light-weight as possible. Requiring heavyweight dependencies from this file
17
+ # will add to the boot time of your test suite on EVERY test run, even for an
18
+ # individual file that may not need all of that loaded. Instead, consider making
19
+ # a separate helper file that requires the additional dependencies and performs
20
+ # the additional setup, and require it from the spec files that actually need
21
+ # it.
22
+ #
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ # rspec-expectations config goes here. You can use an alternate
26
+ # assertion/expectation library such as wrong or the stdlib/minitest
27
+ # assertions if you prefer.
28
+ config.expect_with :rspec do |expectations|
29
+ # This option will default to `true` in RSpec 4. It makes the `description`
30
+ # and `failure_message` of custom matchers include text for helper methods
31
+ # defined using `chain`, e.g.:
32
+ # be_bigger_than(2).and_smaller_than(4).description
33
+ # # => "be bigger than 2 and smaller than 4"
34
+ # ...rather than:
35
+ # # => "be bigger than 2"
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ end
38
+
39
+ # rspec-mocks config goes here. You can use an alternate test double
40
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
41
+ config.mock_with :rspec do |mocks|
42
+ # Prevents you from mocking or stubbing a method that does not exist on
43
+ # a real object. This is generally recommended, and will default to
44
+ # `true` in RSpec 4.
45
+ mocks.verify_partial_doubles = true
46
+ end
47
+
48
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
49
+ # have no way to turn it off -- the option exists only for backwards
50
+ # compatibility in RSpec 3). It causes shared context metadata to be
51
+ # inherited by the metadata hash of host groups and examples, rather than
52
+ # triggering implicit auto-inclusion in groups with matching metadata.
53
+ config.shared_context_metadata_behavior = :apply_to_host_groups
54
+
55
+ # The settings below are suggested to provide a good initial experience
56
+ # with RSpec, but feel free to customize to your heart's content.
57
+ =begin
58
+ # This allows you to limit a spec run to individual examples or groups
59
+ # you care about by tagging them with `:focus` metadata. When nothing
60
+ # is tagged with `:focus`, all examples get run. RSpec also provides
61
+ # aliases for `it`, `describe`, and `context` that include `:focus`
62
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
63
+ config.filter_run_when_matching :focus
64
+
65
+ # Allows RSpec to persist some state between runs in order to support
66
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
67
+ # you configure your source control system to ignore this file.
68
+ config.example_status_persistence_file_path = "spec/examples.txt"
69
+
70
+ # Limits the available syntax to the non-monkey patched syntax that is
71
+ # recommended. For more details, see:
72
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
73
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
74
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
75
+ config.disable_monkey_patching!
76
+
77
+ # This setting enables warnings. It's recommended, but in some cases may
78
+ # be too noisy due to issues in dependencies.
79
+ config.warnings = true
80
+
81
+ # Many RSpec users commonly either run the entire suite or an individual
82
+ # file, and it's useful to allow more verbose output when running an
83
+ # individual spec file.
84
+ if config.files_to_run.one?
85
+ # Use the documentation formatter for detailed output,
86
+ # unless a formatter has already been configured
87
+ # (e.g. via a command-line flag).
88
+ config.default_formatter = "doc"
89
+ end
90
+
91
+ # Print the 10 slowest examples and example groups at the
92
+ # end of the spec run, to help surface which specs are running
93
+ # particularly slow.
94
+ config.profile_examples = 10
95
+
96
+ # Run specs in random order to surface order dependencies. If you find an
97
+ # order dependency and want to debug it, you can fix the order by providing
98
+ # the seed, which is printed after each run.
99
+ # --seed 1234
100
+ config.order = :random
101
+
102
+ # Seed global randomization in this process using the `--seed` CLI option.
103
+ # Setting this allows you to use `--seed` to deterministically reproduce
104
+ # test failures related to randomization by passing the same `--seed` value
105
+ # as the one that triggered the failure.
106
+ Kernel.srand config.seed
107
+ =end
108
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clocale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.10
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,48 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.58'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.58'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.27'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.27'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: rubygems-tasks
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +117,9 @@ extensions:
61
117
  extra_rdoc_files: []
62
118
  files:
63
119
  - ".appveyor.yml"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
64
123
  - Gemfile
65
124
  - LICENSE
66
125
  - README.md
@@ -69,6 +128,8 @@ files:
69
128
  - ext/clocale/clocale.c
70
129
  - ext/clocale/extconf.rb
71
130
  - lib/clocale.rb
131
+ - spec/c_locale_spec.rb
132
+ - spec/spec_helper.rb
72
133
  homepage: https://github.com/avdv/clocale
73
134
  licenses:
74
135
  - MIT
@@ -89,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
150
  version: '0'
90
151
  requirements: []
91
152
  rubyforge_project:
92
- rubygems_version: 2.6.13
153
+ rubygems_version: 2.7.7
93
154
  signing_key:
94
155
  specification_version: 4
95
156
  summary: A Ruby gem that wraps C locale functions.