mirror of https://github.com/tailix/libkernaux.git
Ruby: add methods KernAux.supports_*?
This commit is contained in:
parent
a8af451550
commit
635f7b5849
|
@ -65,7 +65,7 @@ module KernAux
|
|||
|
||||
# @!parse [ruby]
|
||||
|
||||
if singleton_class.method_defined? :snprintf1
|
||||
if Version.supports_printf?
|
||||
##
|
||||
# Typical `printf`.
|
||||
#
|
||||
|
@ -127,8 +127,7 @@ module KernAux
|
|||
# @return [Array<String>] command line arguments
|
||||
#
|
||||
# @raise [CmdlineError] syntax is invalid
|
||||
|
||||
# @!parse [ruby]
|
||||
##
|
||||
|
||||
##
|
||||
# @!method utoa(number, base, prefix)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# rubocop:disable Lint/EmptyClass
|
||||
|
||||
if defined? KernAux::File
|
||||
if KernAux::Version.supports_file?
|
||||
module KernAux
|
||||
##
|
||||
# File simulator.
|
||||
|
|
|
@ -3,4 +3,62 @@
|
|||
module KernAux
|
||||
# Gem version.
|
||||
VERSION = '0.3.0'
|
||||
|
||||
##
|
||||
# This module includes functions to determine if specific features are
|
||||
# supported by the library.
|
||||
#
|
||||
module Version
|
||||
def self.supports_cmdline?
|
||||
KernAux.singleton_class.method_defined? :cmdline
|
||||
end
|
||||
|
||||
def self.supports_file?
|
||||
defined? KernAux::File
|
||||
end
|
||||
|
||||
def self.supports_itoa?
|
||||
KernAux.singleton_class.method_defined? :itoa
|
||||
end
|
||||
|
||||
def self.supports_itoa2?
|
||||
KernAux.singleton_class.method_defined? :itoa2
|
||||
end
|
||||
|
||||
def self.supports_itoa8?
|
||||
KernAux.singleton_class.method_defined? :itoa8
|
||||
end
|
||||
|
||||
def self.supports_itoa10?
|
||||
KernAux.singleton_class.method_defined? :itoa10
|
||||
end
|
||||
|
||||
def self.supports_itoa16?
|
||||
KernAux.singleton_class.method_defined? :itoa16
|
||||
end
|
||||
|
||||
def self.supports_printf?
|
||||
KernAux.singleton_class.method_defined? :snprintf1
|
||||
end
|
||||
|
||||
def self.supports_utoa?
|
||||
KernAux.singleton_class.method_defined? :utoa
|
||||
end
|
||||
|
||||
def self.supports_utoa2?
|
||||
KernAux.singleton_class.method_defined? :utoa2
|
||||
end
|
||||
|
||||
def self.supports_utoa8?
|
||||
KernAux.singleton_class.method_defined? :utoa8
|
||||
end
|
||||
|
||||
def self.supports_utoa10?
|
||||
KernAux.singleton_class.method_defined? :utoa10
|
||||
end
|
||||
|
||||
def self.supports_utoa16?
|
||||
KernAux.singleton_class.method_defined? :utoa16
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.cmdline' do
|
||||
if described_class.singleton_class.method_defined? :cmdline
|
||||
KernAux::Version.supports_cmdline? and RSpec.describe KernAux, '.cmdline' do
|
||||
subject(:cmdline) { described_class.cmdline str }
|
||||
|
||||
let(:str) { 'foo bar\\ baz "car cdr"' }
|
||||
|
@ -92,4 +91,3 @@ RSpec.describe KernAux, '.cmdline' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.itoa10' do
|
||||
if described_class.singleton_class.method_defined? :itoa10
|
||||
KernAux::Version.supports_itoa10? and RSpec.describe KernAux, '.itoa10' do
|
||||
subject(:itoa10) { described_class.itoa10 number }
|
||||
|
||||
let(:number) { rand((-2**63)..(2**63 - 1)) }
|
||||
|
@ -60,4 +59,3 @@ RSpec.describe KernAux, '.itoa10' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.itoa16' do
|
||||
if described_class.singleton_class.method_defined? :itoa16
|
||||
KernAux::Version.supports_itoa16? and RSpec.describe KernAux, '.itoa16' do
|
||||
subject(:itoa16) { described_class.itoa16 number }
|
||||
|
||||
let(:number) { rand((-2**63)..(2**63 - 1)) }
|
||||
|
@ -62,4 +61,3 @@ RSpec.describe KernAux, '.itoa16' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.itoa2' do
|
||||
if described_class.singleton_class.method_defined? :itoa2
|
||||
KernAux::Version.supports_itoa2? and RSpec.describe KernAux, '.itoa2' do
|
||||
subject(:itoa2) { described_class.itoa2 number }
|
||||
|
||||
let(:number) { rand((-2**63)..(2**63 - 1)) }
|
||||
|
@ -62,4 +61,3 @@ RSpec.describe KernAux, '.itoa2' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.itoa8' do
|
||||
if described_class.singleton_class.method_defined? :itoa8
|
||||
KernAux::Version.supports_itoa8? and RSpec.describe KernAux, '.itoa8' do
|
||||
subject(:itoa8) { described_class.itoa8 number }
|
||||
|
||||
let(:number) { rand((-2**63)..(2**63 - 1)) }
|
||||
|
@ -62,4 +61,3 @@ RSpec.describe KernAux, '.itoa8' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.itoa' do
|
||||
if described_class.singleton_class.method_defined? :itoa
|
||||
KernAux::Version.supports_itoa? and RSpec.describe KernAux, '.itoa' do
|
||||
subject(:itoa) { described_class.itoa number, base, prefix }
|
||||
|
||||
let(:number) { rand((-2**63)..(2**63 - 1)) }
|
||||
|
@ -235,4 +234,3 @@ RSpec.describe KernAux, '.itoa' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.utoa10' do
|
||||
if described_class.singleton_class.method_defined? :utoa10
|
||||
KernAux::Version.supports_utoa10? and RSpec.describe KernAux, '.utoa10' do
|
||||
subject(:utoa10) { described_class.utoa10 number }
|
||||
|
||||
let(:number) { rand 0..(2**64 - 1) }
|
||||
|
@ -42,4 +41,3 @@ RSpec.describe KernAux, '.utoa10' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.utoa16' do
|
||||
if described_class.singleton_class.method_defined? :utoa16
|
||||
KernAux::Version.supports_utoa16? and RSpec.describe KernAux, '.utoa16' do
|
||||
subject(:utoa16) { described_class.utoa16 number }
|
||||
|
||||
let(:number) { rand 0..(2**64 - 1) }
|
||||
|
@ -42,4 +41,3 @@ RSpec.describe KernAux, '.utoa16' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.utoa2' do
|
||||
if described_class.singleton_class.method_defined? :utoa2
|
||||
KernAux::Version.supports_utoa2? and RSpec.describe KernAux, '.utoa2' do
|
||||
subject(:utoa2) { described_class.utoa2 number }
|
||||
|
||||
let(:number) { rand 0..(2**64 - 1) }
|
||||
|
@ -42,4 +41,3 @@ RSpec.describe KernAux, '.utoa2' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.utoa8' do
|
||||
if described_class.singleton_class.method_defined? :utoa8
|
||||
KernAux::Version.supports_utoa8? and RSpec.describe KernAux, '.utoa8' do
|
||||
subject(:utoa8) { described_class.utoa8 number }
|
||||
|
||||
let(:number) { rand 0..(2**64 - 1) }
|
||||
|
@ -42,4 +41,3 @@ RSpec.describe KernAux, '.utoa8' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.utoa' do
|
||||
if described_class.singleton_class.method_defined? :utoa
|
||||
KernAux::Version.supports_utoa? and RSpec.describe KernAux, '.utoa' do
|
||||
subject(:utoa) { described_class.utoa number, base, prefix }
|
||||
|
||||
let(:number) { rand 0..(2**64 - 1) }
|
||||
|
@ -207,4 +206,3 @@ RSpec.describe KernAux, '.utoa' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.snprintf1' do
|
||||
if described_class.singleton_class.method_defined? :snprintf1
|
||||
KernAux::Version.supports_printf? and RSpec.describe KernAux, '.snprintf1' do
|
||||
let(:size) { 10_000 }
|
||||
|
||||
context 'with 0 arguments' do
|
||||
|
@ -279,4 +278,3 @@ RSpec.describe KernAux, '.snprintf1' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.sprintf1' do
|
||||
if described_class.singleton_class.method_defined? :sprintf1
|
||||
KernAux::Version.supports_printf? and RSpec.describe KernAux, '.sprintf1' do
|
||||
context 'with 1 argument' do
|
||||
subject(:sprintf1) { described_class.sprintf1 format }
|
||||
|
||||
|
@ -25,4 +24,3 @@ RSpec.describe KernAux, '.sprintf1' do
|
|||
it { is_expected.to eq described_class.snprintf1(100, format, arg).first }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.sprintf' do
|
||||
if described_class.singleton_class.method_defined? :sprintf
|
||||
KernAux::Version.supports_printf? and RSpec.describe KernAux, '.sprintf' do
|
||||
subject :sprintf do
|
||||
described_class.sprintf 'Hello, ', ['%s', 'World'], '!'
|
||||
end
|
||||
|
@ -52,4 +51,3 @@ RSpec.describe KernAux, '.sprintf' do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue