All Files (100.0% covered at 4.15 hits/line)
19 files in total.
1112 relevant lines.
1112 lines covered and
0 lines missed
# ==============================================================================
# LIB - STRING FOUNDATION - STRING FOUNDATION
# frozen_string_literal: true
# ==============================================================================
# Require methods.
- 1
Dir.glob(File.join(File.dirname(__FILE__), "string_foundation", "*.rb")).each do |file|
- 9
require file
end
# ==============================================================================
# LIB - STRING FOUNDATION - BLANK
# frozen_string_literal: true
# ==============================================================================
- 1
class String
# Check whether a string is empty or only half-width spaces.
- 1
def blank?
- 12
self.empty? || /\A[[:space:]]*\z/.match(self).instance_of?(MatchData)
end
# Check whether a string is not empty or only half-width spaces.
- 1
def present?
- 6
!(self.blank?)
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - CASE
# frozen_string_literal: true
# ==============================================================================
- 1
class String
# Convert to lowerCamelCase.
- 1
def to_lcamel
- 11
ucamel = self.to_ucamel
- 22
ucamel.instance_eval { make_head_lower }
end
# Convert to UpperCamelCase.
- 1
def to_ucamel
split_camel.map do |cw|
- 140
cw.split(/\.|_|-|\s/).map { |w| w.capitalize }.join
end
- 22
.join
end
# Convert to lower_snake_case.
- 1
def to_lsnake
- 11
usnake = self.to_usnake
- 11
usnake.downcase
end
# Convert to Upper_Snake_Case.
- 1
def to_usnake
split_camel.map do |cw|
- 140
cw.split(/\.|_|-|\s/).map { |w| w.capitalize }.join("_")
end
- 22
.join("_")
end
# Convert to lower-kebab-case.
- 1
def to_lkebab
- 11
ukebab = self.to_ukebab
- 11
ukebab.downcase
end
# Convert to Upper-Kebab-Case.
- 1
def to_ukebab
split_camel.map do |cw|
- 140
cw.split(/\.|_|-|\s/).map { |w| w.capitalize }.join("-")
end
- 22
.join("-")
end
# Convert to lower space case.
- 1
def to_lspace
- 11
uspace = self.to_uspace
- 11
uspace.downcase
end
# Convert to Upper Space Case.
- 1
def to_uspace
split_camel.map do |cw|
- 140
cw.split(/\.|_|-|\s/).map { |w| w.capitalize }.join(" ")
end
- 22
.join(" ")
end
# Convert to lower.dot.case.
- 1
def to_ldot
- 11
udot = self.to_udot
- 11
udot.downcase
end
# Convert to Upper.Dot.Case.
- 1
def to_udot
split_camel.map do |cw|
- 140
cw.split(/\.|_|-|\s/).map { |w| w.capitalize }.join(".")
end
- 22
.join(".")
end
# ----------------------------------------------------------------------------
# Private
# ----------------------------------------------------------------------------
- 1
private
# Split string according to camel case.
- 1
def split_camel
- 113
self.split(/(?=[A-Z])/)
end
# Make first character lower case.
- 1
def make_head_lower
- 13
self[0].downcase + self[1..-1]
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - CONVERT
# frozen_string_literal: true
# ==============================================================================
- 1
require_relative "convertible"
- 1
require_relative "like"
- 1
require_relative "with"
- 1
class String
# Convert to TrueClass or FalseClass.
- 1
def to_bool
- 5
unless self.to_bool?
- 1
raise TypeError.new("#{self} cannot be converted to TrueClass or FalseClass")
end
- 4
(self == "true")
end
# Convert a booly string to TrueClass or FalseClass.
- 1
def to_booly
- 10
unless self.to_booly?
- 1
raise TypeError.new("#{self} cannot be converted to TrueClass or FalseClass")
end
- 9
return true if self == "true" || (self.to_f? && self.to_f > 0)
- 6
false
end
# Convert to a pretty value.
- 1
def to_pretty
- 9
return self.without_leading_zeros.to_i if self.like_i?
- 6
return self.without_leading_zeros.to_f if self.like_f?
- 4
return self.to_bool if self.to_bool?
- 2
(self.length > 0) ? self : nil
end
# Convert from newline character to specific characters.
- 1
def nl_to(char)
- 8
char = "" if char.nil?
- 8
self.gsub(/(\r\n|\n)/, char)
end
# Convert from newline character to a HTML tag "<br>".
- 1
def nl_to_br
- 3
self.nl_to("<br>")
end
- 1
alias_method :nl2, :nl_to
- 1
alias_method :nl2br, :nl_to_br
end
# ==============================================================================
# LIB - STRING FOUNDATION - CONVERTIBLE
# frozen_string_literal: true
# ==============================================================================
- 1
require_relative "with"
- 1
class String
# Whether or not to be possible to covert String to Integer.
- 1
def to_i?
- 37
Integer(Float(self.without_leading_zeros))
- 31
true
rescue ArgumentError
- 6
false
end
# Whether or not to be possible to covert String to Float.
- 1
def to_f?
- 52
Float(self.without_leading_zeros)
- 42
true
rescue ArgumentError
- 10
false
end
# Whether or not to be possible to covert String to Boolean.
- 1
def to_bool?
- 15
return true if ["true", "false"].include?(self)
- 7
false
end
# Whether or not to be possible to covert String to something which behaves
# like boolean types.
- 1
def to_booly?
- 16
return true if self.length == 0
- 14
return true if ["true", "false"].include?(self)
- 10
return true if self.to_f?
- 2
false
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - IS
# frozen_string_literal: true
# ==============================================================================
- 1
class String
- 1
def is_sym?(symbol)
- 7
raise ArgumentError.new("argument must be Symbol") unless symbol.instance_of?(Symbol)
- 6
(self == symbol.to_s)
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - LENGTH
# frozen_string_literal: true
# ==============================================================================
- 1
class String
# Check whether characters length is a specific number.
- 1
def length?(length)
- 9
unless [Integer, Range, Fixnum, Bignum].include?(length.class)
- 1
raise ArgumentError.new("argument must be Integer (including Fixnum or Bignum) or Range")
end
- 8
return (self.length == length) unless length.instance_of?(Range)
- 5
self.length.between?(length.first, length.last)
end
# Check whether characters length is less than a specific number.
- 1
def length_lt?(length)
- 10
self.instance_eval { allow_only_integer(length) }
- 3
(self.length < length)
end
# Check whether characters length is less than or equal to a specific number.
- 1
def length_lte?(length)
- 10
self.instance_eval { allow_only_integer(length) }
- 3
(self.length <= length)
end
# Check whether characters length is greater than a specific number.
- 1
def length_gt?(length)
- 10
self.instance_eval { allow_only_integer(length) }
- 3
(self.length > length)
end
# Check whether characters length is greater than or equal to a specific number.
- 1
def length_gte?(length)
- 10
self.instance_eval { allow_only_integer(length) }
- 3
(self.length >= length)
end
# ----------------------------------------------------------------------------
# Private
# ----------------------------------------------------------------------------
- 1
private
# Allow only Integer.
- 1
def allow_only_integer(argument)
- 20
return if [Integer, Fixnum, Bignum].include?(argument.class)
- 8
raise ArgumentError.new("argument must be Integer (including Fixnum or Bignum)")
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - LIKE
# frozen_string_literal: true
# ==============================================================================
- 1
require_relative "convertible"
- 1
class String
# Check whether a string is an integral number.
- 1
def like_i?
- 24
return false unless self.to_i?
- 19
num = self.without_leading_zeros
- 19
(num.to_i == num.to_i) && !num.include?(".")
end
# Check whether a string is a floating point number.
- 1
def like_f?
- 21
return false unless self.to_f?
- 16
num = self.without_leading_zeros
- 16
(num.to_i != num.to_f) || num.include?(".")
end
end
# ==============================================================================
# LIB - STRING FOUNDATION - WITH
# frozen_string_literal: true
# ==============================================================================
- 1
class String
# Remove leading zeros.
- 1
def without_leading_zeros
- 146
return self if self == "0"
- 136
is_positive = self.start_with?("0")
- 136
is_negative = self.start_with?("-0")
- 136
if is_positive || is_negative
- 56
sig = self[0, self.length].gsub(/(^0+)|(^-0+)/, "")
- 56
sig = "0" + sig if sig.start_with?(".") || sig.length == 0
- 56
sig = "-" + sig if is_negative && sig != "0"
- 56
sig
else
- 80
self
end
end
- 1
alias_method :without_zero_pad, :without_leading_zeros
end
# ==============================================================================
# SPEC - STRING FOUNDATION - BLANK SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Blank Methods ]" do
- 3
let(:string) { "" }
# ----------------------------------------------------------------------------
# Check Whether A String Is A Blank
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER A STRING IS A BLANK ::" do
- 7
subject { string.blank? }
- 1
context "when a string is empty," do
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a word," do
- 2
let(:string) { "string" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string includes half-width spaces," do
- 2
let(:string) { "this is string foundation." }
- 2
it { is_expected.to be false }
end
- 1
context "when a string includes only 1 half-width space," do
- 2
let(:string) { " " }
- 2
it { is_expected.to be true }
end
- 1
context "when a string includes only multiple half-width spaces," do
- 2
let(:string) { " " * 3 }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a newline," do
- 2
let(:string) { "\n" }
- 2
it { is_expected.to be true }
end
end
# ----------------------------------------------------------------------------
# Check Whether A String Is Present
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER A STRING IS PRESENT ::" do
- 7
subject { string.present? }
- 1
context "when a string is empty," do
- 2
it { is_expected.to be false }
end
- 1
context "when a string is a word," do
- 2
let(:string) { "string" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string includes half-width spaces," do
- 2
let(:string) { "this is string foundation." }
- 2
it { is_expected.to be true }
end
- 1
context "when a string includes only 1 half-width space," do
- 2
let(:string) { " " }
- 2
it { is_expected.to be false }
end
- 1
context "when a string includes only multiple half-width spaces," do
- 2
let(:string) { " " * 3 }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is a newline," do
- 2
let(:string) { "\n" }
- 2
it { is_expected.to be false }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - CASE SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Case Methods ]" do
# Define shared contexts.
# ----------------------------------------------------------------------------
- 21
shared_context "one word" do let(:string) { "string" } end
- 21
shared_context "lowerCamelCase" do let(:string) { "iAmJagaApple" } end
- 21
shared_context "UpperCamelCase" do let(:string) { "IAmJagaApple" } end
- 21
shared_context "lower_snake_case" do let(:string) { "I_am_jaga_apple" } end
- 21
shared_context "Upper_Snake_Case" do let(:string) { "I_Am_Jaga_Apple" } end
- 21
shared_context "lower-kebab-case" do let(:string) { "i-am-jaga-apple" } end
- 21
shared_context "Upper-Kebab-Case" do let(:string) { "I-Am-Jaga-Apple" } end
- 21
shared_context "lower space case" do let(:string) { "i am jaga apple" } end
- 21
shared_context "Upper Space Case" do let(:string) { "I Am Jaga Apple" } end
- 21
shared_context "lower.dot.case" do let(:string) { "i.am.jaga.apple" } end
- 21
shared_context "Upper.Dot.Case" do let(:string) { "I.Am.Jaga.Apple" } end
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Convert to lowerCamelCase
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO lowerCamelCase ::" do
- 12
subject { string.to_lcamel }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to lowerCamelCase" do
- 20
it { is_expected.to eq("iAmJagaApple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("string") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to lowerCamelCase"
end
end
# ----------------------------------------------------------------------------
# Convert to UpperCamelCase
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO UpperCamelCase ::" do
- 12
subject { string.to_ucamel }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to UpperCamelCase" do
- 20
it { is_expected.to eq("IAmJagaApple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("String") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to UpperCamelCase"
end
end
# ----------------------------------------------------------------------------
# Convert to lower_snake_case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO lower_snake_case ::" do
- 12
subject { string.to_lsnake }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to lower_snake_case" do
- 20
it { is_expected.to eq("i_am_jaga_apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("string") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to lower_snake_case"
end
end
# ----------------------------------------------------------------------------
# Convert to Upper_Snake_Case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO Upper_Snake_Case ::" do
- 12
subject { string.to_usnake }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to Upper_Snake_Case" do
- 20
it { is_expected.to eq("I_Am_Jaga_Apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("String") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to Upper_Snake_Case"
end
end
# ----------------------------------------------------------------------------
# Convert to lower-kebab-case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO lower-kebab-case ::" do
- 12
subject { string.to_lkebab }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to lower-kebab-case" do
- 20
it { is_expected.to eq("i-am-jaga-apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("string") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to lower-kebab-case"
end
end
# ----------------------------------------------------------------------------
# Convert to Upper-Kebab-Case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO Upper-Kebab-Case ::" do
- 12
subject { string.to_ukebab }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to Upper-Kebab-Case" do
- 20
it { is_expected.to eq("I-Am-Jaga-Apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("String") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to Upper-Kebab-Case"
end
end
# ----------------------------------------------------------------------------
# Convert to lower space case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO lower space case ::" do
- 12
subject { string.to_lspace }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to lower space case" do
- 20
it { is_expected.to eq("i am jaga apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("string") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to lower space case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to lower space case"
end
end
# ----------------------------------------------------------------------------
# Convert to Upper Space Case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO Upper Space Case ::" do
- 12
subject { string.to_uspace }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to Upper Space Case" do
- 20
it { is_expected.to eq("I Am Jaga Apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("String") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to Upper Space Case"
end
end
# ----------------------------------------------------------------------------
# Convert to lower.dot.case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO lower.dot.case ::" do
- 12
subject { string.to_ldot }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to lower.dot.case" do
- 20
it { is_expected.to eq("i.am.jaga.apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("string") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to lower.dot.case"
end
end
# ----------------------------------------------------------------------------
# Private
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Convert to Upper.Dot.Case
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO Upper.Dot.Case ::" do
- 12
subject { string.to_udot }
# Define shared examples.
# --------------------------------------------------------------------------
- 1
shared_examples "be converted to Upper.Dot.Case" do
- 20
it { is_expected.to eq("I.Am.Jaga.Apple") }
end
# --------------------------------------------------------------------------
- 1
context "When a string has one word," do
- 1
include_context "one word"
- 2
it { is_expected.to eq("String") }
end
- 1
context "When a string lowerCamelCase," do
- 1
include_context "lowerCamelCase"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string UpperCamelCase," do
- 1
include_context "UpperCamelCase"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string lower_snake_case," do
- 1
include_context "lower_snake_case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string Upper_Snake_Case," do
- 1
include_context "Upper_Snake_Case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string lower-kebab-case," do
- 1
include_context "lower-kebab-case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string Upper-Kebab-Case," do
- 1
include_context "Upper-Kebab-Case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string lower space case," do
- 1
include_context "lower space case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string Upper Space Case," do
- 1
include_context "Upper Space Case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string lower.dot.case," do
- 1
include_context "lower.dot.case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
- 1
context "When a string Upper.Dot.Case," do
- 1
include_context "Upper.Dot.Case"
- 1
it_behaves_like "be converted to Upper.Dot.Case"
end
end
# ----------------------------------------------------------------------------
# Split String According to Camel Case
# ----------------------------------------------------------------------------
- 1
describe "SPLIT ACCORDING TO CAMEL CASE ::" do
- 1
let(:string) { nil }
- 7
subject { string.instance_eval { split_camel } }
- 1
context "When string is Upper Camel Case," do
- 2
let!(:string) { "ThisIsWord" }
- 2
it { is_expected.to eq(["This", "Is", "Word"]) }
end
- 1
context "When string is Lower Camel Case," do
- 2
let!(:string) { "thisIsWord" }
- 2
it { is_expected.to eq(["this", "Is", "Word"]) }
end
- 1
context "When string is not Camel Case," do
- 2
let!(:string) { "thisisword" }
- 2
it { is_expected.to eq(["thisisword"]) }
end
end
# ----------------------------------------------------------------------------
# Make First Character Lower Case
# ----------------------------------------------------------------------------
- 1
describe "MAKE FIRST CHARACTER LOWER CASE ::" do
- 1
let(:string) { nil }
- 5
subject { string.instance_eval { make_head_lower } }
- 1
context "When first character is Upper Case," do
- 2
let(:string) { "ThisIsString" }
- 2
it { is_expected.to eq("thisIsString") }
end
- 1
context "When first character is Lower Case," do
- 2
let(:string) { "thisIsString" }
- 2
it { is_expected.to eq("thisIsString") }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - CONVERT SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Convert Methods ]" do
# ----------------------------------------------------------------------------
# Convert To TrueClass Or FalseClass
# ----------------------------------------------------------------------------
- 1
describe "CONVERT TO TRUECLASS OR FALSE CLASS" do
- 1
let(:string) { nil }
- 4
subject { string.to_bool }
- 1
context "when a string is \"true\"," do
- 2
let(:string) { "true" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is \"false\"," do
- 2
let(:string) { "false" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is invalid," do
- 2
let(:string) { "dummy" }
- 2
it { is_expected_as_block.to raise_error(TypeError) }
end
end
# ----------------------------------------------------------------------------
# Convert A BOOLY STRING To TrueClass Or FalseClass
# ----------------------------------------------------------------------------
- 1
describe "CONVERT A BOOLY STRING TO TRUECLASS OR FALSE CLASS" do
- 1
let(:string) { nil }
- 11
subject { string.to_booly }
- 1
context "when a string is \"true\"," do
- 2
let(:string) { "true" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is \"false\"," do
- 2
let(:string) { "false" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is invalid," do
- 2
let(:string) { "dummy" }
- 2
it { is_expected_as_block.to raise_error(TypeError) }
end
- 1
context "when a string is a positive integral number," do
- 2
let(:string) { "1" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a negative integral number," do
- 2
let(:string) { "-1" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is a positive floating point number," do
- 2
let(:string) { "0.1" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a negative floating point number," do
- 2
let(:string) { "-0.1" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is 0," do
- 2
let(:string) { "0" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is 0.0," do
- 2
let(:string) { "0.0" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is an empty string," do
- 2
let(:string) { "" }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Convert To Proper Class From String
# ----------------------------------------------------------------------------
- 1
describe "CONVER TO PROPER CLASS FROM STRING" do
- 1
let(:string) { nil }
- 10
subject { string.to_pretty }
- 1
context "when a string is \"0\"," do
- 2
let(:string) { "0" }
- 2
it { is_expected.to eq(0) }
end
- 1
context "when a string is \"1\"," do
- 2
let(:string) { "1" }
- 2
it { is_expected.to eq(1) }
end
- 1
context "when a string is \"000123\"," do
- 2
let(:string) { "000123" }
- 2
it { is_expected.to eq(123) }
end
- 1
context "when a string is \"0.0\"," do
- 2
let(:string) { "0.0" }
- 2
it { is_expected.to eq(0.0) }
end
- 1
context "when a string is \"000.00123\"," do
- 2
let(:string) { "000.00123" }
- 2
it { is_expected.to eq(0.00123) }
end
- 1
context "when a string is \"true\"," do
- 2
let(:string) { "true" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is \"false\"," do
- 2
let(:string) { "false" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is \"dummy\"," do
- 2
let(:string) { "dummy" }
- 2
it { is_expected.to eq(string) }
end
- 1
context "when a string is an empty string," do
- 2
let(:string) { "" }
- 2
it { is_expected.to be_nil }
end
end
# ----------------------------------------------------------------------------
# Convert From Newline To Characters
# ----------------------------------------------------------------------------
- 1
describe "CONVERT FROM NEWLINE TO CHARACTERS" do
- 5
let(:string) { "I am Jaga Apple.\nI am Jaga Apple." }
- 4
let(:char) { "<br>" }
- 6
subject { string.nl_to(char) }
- 1
context "when a string has newlines \"\\n\"," do
- 2
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
end
- 1
context "when a string has newlines \"\\r\\n\"," do
- 2
let(:string) { "I am Jaga Apple.\r\nI am Jaga Apple." }
- 2
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
end
- 1
context "when a string does not have newlines," do
- 2
let(:string) { "I am Jaga Apple. I am Jaga Apple." }
- 2
it { is_expected.to eq(string) }
end
- 1
context "when an argument is not set," do
- 2
subject { string.nl_to }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is nil," do
- 2
let(:char) { nil }
- 2
it { is_expected.to eq("I am Jaga Apple.I am Jaga Apple.") }
end
- 1
context "when an argument is an empty string," do
- 2
let(:char) { "" }
- 2
it { is_expected.to eq("I am Jaga Apple.I am Jaga Apple.") }
end
end
# ----------------------------------------------------------------------------
# Convert From Newline To <br>
# ----------------------------------------------------------------------------
- 1
describe "CONVERT FROM NEWLINE TO `<br>`" do
- 2
let(:string) { "I am Jaga Apple.\nI am Jaga Apple." }
- 4
subject { string.nl_to_br }
- 1
context "when a string has newlines \"\n\"," do
- 2
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
end
- 1
context "when a string has newlines \"\\r\\n\"," do
- 2
let(:string) { "I am Jaga Apple.\r\nI am Jaga Apple." }
- 2
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
end
- 1
context "when a string does not have newlines," do
- 2
let(:string) { "I am Jaga Apple. I am Jaga Apple." }
- 2
it { is_expected.to eq(string) }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - CONVERTIBLE SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Convertible Methods ]" do
# ----------------------------------------------------------------------------
# Check Convertible To Integer
# ----------------------------------------------------------------------------
- 1
describe "CHECK CONVERTIBLE TO INTEGER" do
- 1
let(:string) { nil }
- 14
subject { string.to_i? }
- 1
context "when a string is an integral number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number without an integer," do
- 1
context "it is a positive number," do
- 2
let(:string) { ".123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string a number has leading zeros," do
- 1
context "it is a positive number," do
- 2
let(:string) { "00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-00000123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Convertible To Float
# ----------------------------------------------------------------------------
- 1
describe "CHECK CONVERTIBLE TO FLOAT" do
- 1
let(:string) { nil }
- 14
subject { string.to_f? }
- 1
context "when a string is an integral number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number without an integer," do
- 1
context "it is a positive number," do
- 2
let(:string) { ".123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string a number has leading zeros," do
- 1
context "it is a positive number," do
- 2
let(:string) { "00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-00000123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Convertible To Boolean
# ----------------------------------------------------------------------------
- 1
describe "CHECK CONVERTIBLE TO BOOLEAN" do
- 1
let(:string) { nil }
- 7
subject { string.to_bool? }
- 1
context "when a string is \"true\"," do
- 2
let(:string) { "true" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is \"false\"," do
- 2
let(:string) { "false" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is empty," do
- 2
let(:string) { "" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is a positive number," do
- 2
let(:string) { "1" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is a negative number," do
- 2
let(:string) { "-1" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Convertaile To Booly
# ----------------------------------------------------------------------------
- 1
describe "CHECK CONVERTIBLE TO BOOLYs" do
- 1
let(:string) { nil }
- 7
subject { string.to_booly? }
- 1
context "when a string is \"true\"," do
- 2
let(:string) { "true" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is \"false\"," do
- 2
let(:string) { "false" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is empty," do
- 2
let(:string) { "" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a positive number," do
- 2
let(:string) { "1" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is a negative number," do
- 2
let(:string) { "-1" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - IS SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Is Methods ]" do
- 4
let(:string) { "string" }
- 2
let(:expected_symbol) { :string }
# ----------------------------------------------------------------------------
# Check Whether Character Is A Specific Symbol
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTER IS A SPECIFIC SYMBOL ::" do
- 8
subject { string.is_sym?(expected_symbol) }
- 1
context "when an argument is not a Symbol," do
- 2
let(:expected_symbol) { "string" }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an object equal to an argument," do
- 1
context "object and argument are alphabets," do
- 2
it { is_expected.to be true }
end
- 1
context "object and argument are numbers," do
- 2
let(:string) { "123" }
- 2
let(:expected_symbol) { :"123" }
- 2
it { is_expected.to be true }
end
- 1
context "object and argument are empty," do
- 2
let(:string) { "" }
- 2
let(:expected_symbol) { :"" }
- 2
it { is_expected.to be true }
end
- 1
context "object and argument include underscores," do
- 2
let(:string) { "string_foundation" }
- 2
let(:expected_symbol) { :string_foundation }
- 2
it { is_expected.to be true }
end
- 1
context "object and argument include dashes," do
- 2
let(:string) { "string-foundation" }
- 2
let(:expected_symbol) { :"string-foundation" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when an object is not equal to an argument," do
- 2
let(:expected_symbol) { :integer }
- 2
it { is_expected.to be false }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - LENGTH SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Length Methods ]" do
- 30
let(:string) { "string" }
- 1
let(:expected_length) { 0 }
# ----------------------------------------------------------------------------
# Check Whether Characters Length Is A Specific Number
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTERS LENGTH IS A SPECIFIC NUMBER ::" do
- 10
subject { string.length?(expected_length) }
- 1
context "when an argument is String," do
- 2
let(:expected_length) { string.length.to_s }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is Integer," do
- 1
context "characters length is equal to an argument," do
- 2
let(:expected_length) { string.length }
- 2
it { is_expected.to be true }
end
- 1
context "characters length is less than an argument," do
- 2
let(:expected_length) { string.length + 1 }
- 2
it { is_expected.to be false }
end
- 1
context "characters length is greater than an argument," do
- 2
let(:expected_length) { string.length - 1 }
- 2
it { is_expected.to be false }
end
end
- 1
context "when an argument is Range," do
- 1
context "characters length is in range," do
- 2
let(:expected_length) { (string.length - 1)..(string.length + 1) }
- 2
it { is_expected.to be true }
end
- 1
context "characters length is equal to the minimum of range," do
- 2
let(:expected_length) { string.length..(string.length + 1) }
- 2
it { is_expected.to be true }
end
- 1
context "characters length is equal to the maximum of range," do
- 2
let(:expected_length) { (string.length - 1)..string.length }
- 2
it { is_expected.to be true }
end
- 1
context "characters length is less than the minimum of range," do
- 2
let(:expected_length) { (string.length + 1)..(string.length + 2) }
- 2
it { is_expected.to be false }
end
- 1
context "characters length is greater than the maximum of range," do
- 2
let(:expected_length) { (string.length - 2)..(string.length - 1) }
- 2
it { is_expected.to be false }
end
end
end
# ----------------------------------------------------------------------------
# Check Whether Characters Length Is Less Than A Specific Number
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTERS LENGTH IS LESS THAN A SPECIFIC NUMBER ::" do
- 6
subject { string.length_lt?(expected_length) }
- 1
context "when an argument is String," do
- 2
let(:expected_length) { string.length.to_s }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is Range," do
- 2
let(:expected_length) { (string.length - 1)..(string.length + 1) }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when characters length is less than an argument," do
- 2
let(:expected_length) { string.length + 1 }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is equal to an argument," do
- 2
let(:expected_length) { string.length }
- 2
it { is_expected.to be false }
end
- 1
context "when characters length is greater than an argument," do
- 2
let(:expected_length) { string.length - 1 }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Whether Characters Length Is Less Than Or Equal To A Specific Number
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTERS LENGTH IS LESS THAN OR EQUAL TO A SPECIFIC NUMBER ::" do
- 6
subject { string.length_lte?(expected_length) }
- 1
context "when an argument is String," do
- 2
let(:expected_length) { string.length.to_s }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is Range," do
- 2
let(:expected_length) { (string.length - 1)..(string.length + 1) }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when characters length is equal to an argument," do
- 2
let(:expected_length) { string.length }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is less than an argument," do
- 2
let(:expected_length) { string.length + 1 }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is greater than an argument," do
- 2
let(:expected_length) { string.length - 1 }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Whether Characters Length Is Greater Than A Specific Number
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTERS LENGTH IS GREATER THAN A SPECIFIC NUMBER ::" do
- 6
subject { string.length_gt?(expected_length) }
- 1
context "when an argument is String," do
- 2
let(:expected_length) { string.length.to_s }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is Range," do
- 2
let(:expected_length) { (string.length - 1)..(string.length + 1) }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when characters length is greater than an argument," do
- 2
let(:expected_length) { string.length - 1 }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is equal to an argument," do
- 2
let(:expected_length) { string.length }
- 2
it { is_expected.to be false }
end
- 1
context "when characters length is less than an argument," do
- 2
let(:expected_length) { string.length + 1 }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Whether Characters Length Is Greater Than Or Equal To A Specific Number
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER CHARACTERS LENGTH IS GREATER THAN OR EQUAL TO A SPECIFIC NUMBER ::" do
- 6
subject { string.length_gte?(expected_length) }
- 1
context "when an argument is String," do
- 2
let(:expected_length) { string.length.to_s }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when an argument is Range," do
- 2
let(:expected_length) { (string.length - 1)..(string.length + 1) }
- 2
it { is_expected_as_block.to raise_error(ArgumentError) }
end
- 1
context "when characters length is equal to an argument," do
- 2
let(:expected_length) { string.length }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is greater than an argument," do
- 2
let(:expected_length) { string.length - 1 }
- 2
it { is_expected.to be true }
end
- 1
context "when characters length is less than an argument," do
- 2
let(:expected_length) { string.length + 1 }
- 2
it { is_expected.to be false }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - LIKE SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ Like Methods ]" do
# ----------------------------------------------------------------------------
# Check Whether A String Is Integer
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER A STRING IS INTEGER ::" do
- 1
let(:string) { nil }
- 16
subject { string.like_i? }
- 1
context "when a string is an integral number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "0.123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+0.123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5.123" }
- 2
it { is_expected.to be false }
end
end
- 1
context "when a string is a floating point number without an integer," do
- 1
context "it is a positive number," do
- 2
let(:string) { ".123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+.123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-.123" }
- 2
it { is_expected.to be false }
end
end
- 1
context "when a string a number has leading zeros," do
- 1
context "it is a positive number," do
- 2
let(:string) { "00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+00000123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-00000123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is 0," do
- 2
let(:string) { "0" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is 0.0," do
- 2
let(:string) { "0.0" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
# ----------------------------------------------------------------------------
# Check Whether A String Is Float
# ----------------------------------------------------------------------------
- 1
describe "CHECK WHETHER A STRING IS FLOAT ::" do
- 1
let(:string) { nil }
- 16
subject { string.like_f? }
- 1
context "when a string is an integral number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5" }
- 2
it { is_expected.to be false }
end
end
- 1
context "when a string is a floating point number," do
- 1
context "it is a positive number," do
- 2
let(:string) { "0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+0.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-5.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string is a floating point number without an integer," do
- 1
context "it is a positive number," do
- 2
let(:string) { ".123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+.123" }
- 2
it { is_expected.to be true }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-.123" }
- 2
it { is_expected.to be true }
end
end
- 1
context "when a string a number has leading zeros," do
- 1
context "it is a positive number," do
- 2
let(:string) { "00000123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a positive number with a sign," do
- 2
let(:string) { "+00000123" }
- 2
it { is_expected.to be false }
end
- 1
context "it is a negative number," do
- 2
let(:string) { "-00000123" }
- 2
it { is_expected.to be false }
end
end
- 1
context "when a string is 0," do
- 2
let(:string) { "0" }
- 2
it { is_expected.to be false }
end
- 1
context "when a string is 0.0," do
- 2
let(:string) { "0.0" }
- 2
it { is_expected.to be true }
end
- 1
context "when a string is not a number," do
- 2
let(:string) { "abc" }
- 2
it { is_expected.to be false }
end
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - VERSION SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe StringFoundation::VERSION do
# ----------------------------------------------------------------------------
# Version Definition
# ----------------------------------------------------------------------------
- 1
it "should have a version number" do
- 1
expect(StringFoundation::VERSION).not_to be_nil
end
end
# ==============================================================================
# SPEC - STRING FOUNDATION - WITH SPEC
# frozen_string_literal: true
# ==============================================================================
- 1
describe "[ With Methods ]" do
# ----------------------------------------------------------------------------
# Without Leading Zeros
# ----------------------------------------------------------------------------
- 1
describe "WITHOUT LEADING ZEROS ::" do
- 1
let(:string_number) { nil }
- 9
subject { string_number.without_leading_zeros }
- 1
context "when a string has leading zeros," do
- 1
context "without a plus or minus sign," do
- 2
let(:string_number) { "0000123" }
- 2
it { is_expected.to eq("123") }
end
- 1
context "with a minus sign," do
- 2
let(:string_number) { "-0000123" }
- 2
it { is_expected.to eq("-123") }
end
end
- 1
context "when a string has some zero characters," do
- 1
context "without a plus or minus sign," do
- 2
let(:string_number) { "00001230000" }
- 2
it { is_expected.to eq("1230000") }
end
- 1
context "with a minus sign," do
- 2
let(:string_number) { "-00001230000" }
- 2
it { is_expected.to eq("-1230000") }
end
end
- 1
context "when a string like a floating point number has leading zeros," do
- 1
context "without a plus or minus sign," do
- 2
let(:string_number) { "000000.3" }
- 2
it { is_expected.to eq("0.3") }
end
- 1
context "with a minus sign," do
- 2
let(:string_number) { "-000000.3" }
- 2
it { is_expected.to eq("-0.3") }
end
end
- 1
context "when a string is \"0\"," do
- 1
context "without a plus or minus sign," do
- 2
let(:string_number) { "0" }
- 2
it { is_expected.to eq("0") }
end
- 1
context "with a minus sign," do
- 2
let(:string_number) { "-0" }
- 2
it { is_expected.to eq("0") }
end
end
- 1
context "when a string has only zero characters," do
- 1
context "without a plus or minus sign," do
- 1
it "should return a string \"0\"" do
- 1
expect("00".without_leading_zeros).to eq("0")
- 1
expect("000".without_leading_zeros).to eq("0")
- 1
expect("0000".without_leading_zeros).to eq("0")
- 1
expect("00000".without_leading_zeros).to eq("0")
end
end
- 1
context "with a minus sign," do
- 1
it "should return a string \"0\"" do
- 1
expect("-00".without_leading_zeros).to eq("0")
- 1
expect("-000".without_leading_zeros).to eq("0")
- 1
expect("-0000".without_leading_zeros).to eq("0")
- 1
expect("-00000".without_leading_zeros).to eq("0")
end
end
end
- 1
context "when a string does not start with \"0\" and \"-0\"," do
- 1
it "should return the same string" do
- 1
random_text = RandomToken.gen(10, seed: :alphabet).without_leading_zeros
- 1
expect(random_text).to eq(random_text)
end
end
end
end
# ==============================================================================
# SPEC - SUPPORT - ENHANCED MATCHERS EXTENSION
# frozen_string_literal: true
# ==============================================================================
- 1
module EnhancedMatchersExtension
# Call a proc object and be expected.
- 1
def is_expected_as_block
- 26
expect { subject }
end
end