-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
339 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require "test_helper" | ||
require "coolkit/core/remove_first_from_array" | ||
|
||
module CoreTest | ||
class ArrayTest < TestCase | ||
|
||
# @return [Array] | ||
def cases | ||
return [ | ||
{ | ||
description: "remove string", | ||
array: ["one", "two", "three"], | ||
item: "two", | ||
result: ["one", "three"], | ||
}, | ||
{ | ||
description: "remove empty string", | ||
array: ["one", "two", "", "three"], | ||
item: "", | ||
result: ["one", "two", "three"], | ||
}, | ||
{ | ||
description: "remove number", | ||
array: [0, 1, 2, 4], | ||
item: 2, | ||
result: [0, 1, 4], | ||
}, | ||
{ | ||
description: "remove only the first occurrence of a number", | ||
array: [0, 1, 2, 2, 4], | ||
item: 2, | ||
result: [0, 1, 2, 4], | ||
}, | ||
{ | ||
description: "remove symbol from mixed array", | ||
array: [1, "two", :three, "three"], | ||
item: :three, | ||
result: [1, "two", "three"], | ||
}, | ||
{ | ||
description: "remove string from an empty array", | ||
array: [], | ||
item: "value", | ||
result: [], | ||
}, | ||
{ | ||
description: "remove nil from an empty array", | ||
array: [], | ||
item: nil, | ||
result: [], | ||
}, | ||
{ | ||
description: "remove item not present in array", | ||
array: ["one", "two"], | ||
item: "three", | ||
result: ["one", "two"], | ||
}, | ||
] | ||
end | ||
|
||
def test_remove_first! | ||
cases = self.cases() | ||
cases.each do |c| | ||
assert_equal(c[:result], Coolkit.remove_first_from_array(c[:array], c[:item])) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "test_helper" | ||
require "coolkit/core/parse_json_file" | ||
|
||
module CoreTest | ||
class JSONTest < TestCase | ||
|
||
def test_read | ||
data = Coolkit.parse_json_file(file_fixture("simple.json")) | ||
assert_equal("value", data["key"]) | ||
end | ||
|
||
def test_read_with_options | ||
data = Coolkit.parse_json_file(file_fixture("simple.json"), symbolize_names: true) | ||
assert_equal("value", data[:key]) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/comment" | ||
|
||
module CoreTest | ||
module StringTest | ||
class CommentTest < TestCase | ||
|
||
def test_comment_1 | ||
want = <<~STRING | ||
# def some_method | ||
# some_code | ||
# end | ||
STRING | ||
input = <<~STRING | ||
def some_method | ||
some_code | ||
end | ||
STRING | ||
assert_equal(want, Coolkit.comment(input)) | ||
end | ||
|
||
def test_comment_2 | ||
assert_equal("# foo", Coolkit.comment("foo")) | ||
assert_equal("# foo", Coolkit.comment(" foo")) | ||
assert_equal("# foo\n# \t\tbar", Coolkit.comment("foo\n\t\tbar")) | ||
end | ||
|
||
def test_comment_3 | ||
assert_equal("# foo\n# \n# bar", Coolkit.comment("foo\n\nbar")) | ||
assert_equal("# foo\n\n# bar", Coolkit.comment("foo\n\nbar", indent_empty_lines: false)) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/indent" | ||
|
||
module CoreTest | ||
module StringTest | ||
class IndentTest < TestCase | ||
|
||
def test_indent_1 | ||
want = <<-STRING | ||
def some_method | ||
some_code | ||
end | ||
STRING | ||
input = <<~STRING | ||
def some_method | ||
some_code | ||
end | ||
STRING | ||
assert_equal(want, Coolkit.indent(input, 2)) | ||
end | ||
|
||
def test_indent_2 | ||
assert_equal(" foo", Coolkit.indent(" foo", 2)) | ||
assert_equal("\t\tfoo\n\t\t\t\tbar", Coolkit.indent("foo\n\t\tbar", 2)) | ||
assert_equal("\t\tfoo", Coolkit.indent("foo", 2, indent_string: "\t")) | ||
end | ||
|
||
def test_indent_3 | ||
assert_equal(" foo\n\n bar", Coolkit.indent("foo\n\nbar", 2)) | ||
assert_equal(" foo\n \n bar", Coolkit.indent("foo\n\nbar", 2, indent_string: nil, indent_empty_lines: true)) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/normalize" | ||
|
||
module CoreTest | ||
module StringTest | ||
class NormalizeTest < TestCase | ||
[ | ||
{ | ||
want: "Number of Accepted Transaction Sets", | ||
have: "Number of Accepted Transaction Sets", | ||
}, | ||
{ | ||
want: "Free Form Message", | ||
have: "Free Form Message", | ||
}, | ||
{ | ||
want: "Free Form Message", | ||
have: "Free-Form Message", | ||
}, | ||
{ | ||
want: "Pick up Date", | ||
have: "Pick-up Date", | ||
}, | ||
{ | ||
want: "Harbor Maintenance Fee Exemption Code", | ||
have: "Harbor Maintenance Fee (HMF) Exemption Code", | ||
}, | ||
{ | ||
want: "Product Service Substitution Code", | ||
have: "Product/Service Substitution Code", | ||
}, | ||
{ | ||
want: "Bill of Lading Waybill Number", | ||
have: "Bill of Lading/Waybill Number", | ||
}, | ||
{ | ||
want: "Pre Cooled Code", | ||
have: "Pre-Cooled (Rule 710) Code", | ||
}, | ||
{ | ||
want: "Surface Layer Position Code", | ||
have: "Surface/Layer/Position Code", | ||
}, | ||
{ | ||
want: "U P C EAN Consumer Package Code", | ||
have: "U.P.C./EAN Consumer Package Code", | ||
}, | ||
{ | ||
want: "D U N S Number", | ||
have: "D-U-N-S Number", | ||
}, | ||
{ | ||
want: "Service Promotion Allowance or Charge Code", | ||
have: "Service, Promotion, Allowance, or Charge Code", | ||
}, | ||
{ | ||
want: "Shippers Export Declaration Requirements", | ||
have: "Shipper's Export Declaration Requirements", | ||
}, | ||
{ | ||
want: "Resource Code", | ||
have: "Resource Code (or Identifier)", | ||
}, | ||
{ | ||
want: "Interchange ID Qualifier", | ||
have: "Interchange ID Qualifier", | ||
}, | ||
{ | ||
want: "Length of Binary Data", | ||
have: "Length of Binary Data", | ||
}, | ||
].each do |c| | ||
define_method("test_normalize_#{c[:have]}") do | ||
assert_equal(c[:want], Coolkit.normalize(c[:have])) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/pascal_case" | ||
|
||
module CoreTest | ||
module StringTest | ||
class PascalCaseTest < TestCase | ||
{ | ||
"Number of Accepted Transaction Sets" => "NumberOfAcceptedTransactionSets", | ||
"Free Form Message" => "FreeFormMessage", | ||
"Free-Form Message" => "FreeFormMessage", | ||
"Pick-up Date" => "PickUpDate", | ||
"Harbor Maintenance Fee (HMF) Exemption Code" => "HarborMaintenanceFeeExemptionCode", | ||
"Product/Service Substitution Code" => "ProductServiceSubstitutionCode", | ||
"Bill of Lading/Waybill Number" => "BillOfLadingWaybillNumber", | ||
"Pre-Cooled (Rule 710) Code" => "PreCooledCode", | ||
"Surface/Layer/Position Code" => "SurfaceLayerPositionCode", | ||
"U.P.C./EAN Consumer Package Code" => "UPCEanConsumerPackageCode", | ||
"D-U-N-S Number" => "DUNSNumber", | ||
"Service, Promotion, Allowance, or Charge Code" => "ServicePromotionAllowanceOrChargeCode", | ||
"Shipper's Export Declaration Requirements" => "ShippersExportDeclarationRequirements", | ||
"Resource Code (or Identifier)" => "ResourceCode", | ||
"Interchange ID Qualifier" => "InterchangeIdQualifier", | ||
"Length of Binary Data" => "LengthOfBinaryData", | ||
}.each do |input, want| | ||
define_method("test_normalize_#{input}") do | ||
assert_equal(want, Coolkit.pascal_case(input)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/snake_case" | ||
|
||
module CoreTest | ||
module StringTest | ||
class SnakeCaseTest < TestCase | ||
{ | ||
"Number of Accepted Transaction Sets" => "number_of_accepted_transaction_sets", | ||
"Free Form Message" => "free_form_message", | ||
"Free-Form Message" => "free_form_message", | ||
"Pick-up Date" => "pick_up_date", | ||
"Harbor Maintenance Fee (HMF) Exemption Code" => "harbor_maintenance_fee_exemption_code", | ||
"Product/Service Substitution Code" => "product_service_substitution_code", | ||
"Bill of Lading/Waybill Number" => "bill_of_lading_waybill_number", | ||
"Pre-Cooled (Rule 710) Code" => "pre_cooled_code", | ||
"Surface/Layer/Position Code" => "surface_layer_position_code", | ||
"U.P.C./EAN Consumer Package Code" => "upc_ean_consumer_package_code", | ||
"D-U-N-S Number" => "d_u_n_s_number", # TODO: Don't like this result. | ||
"Service, Promotion, Allowance, or Charge Code" => "service_promotion_allowance_or_charge_code", | ||
"Shipper's Export Declaration Requirements" => "shippers_export_declaration_requirements", | ||
"Resource Code (or Identifier)" => "resource_code", | ||
"Interchange ID Qualifier" => "interchange_id_qualifier", | ||
"Length of Binary Data" => "length_of_binary_data", | ||
}.each do |input, want| | ||
define_method("test_normalize_#{input}") do | ||
assert_equal(want, Coolkit.snake_case(input)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "test_helper" | ||
require "coolkit/core/string/trim_trailing_whitespace" | ||
|
||
module CoreTest | ||
module StringTest | ||
class TrimTrailingWhitespaceTest < TestCase | ||
|
||
def test_1 | ||
want = "Hello\nWorld\n" | ||
have = Coolkit.trim_trailing_whitespace("Hello \nWorld\n") | ||
assert_equal(want, have) | ||
end | ||
|
||
def test_2 | ||
want = "Hello\n World\n" | ||
have = Coolkit.trim_trailing_whitespace("Hello \n World\n") | ||
assert_equal(want, have) | ||
end | ||
|
||
def test_3 | ||
want = "Hello\n\n World\n" | ||
have = Coolkit.trim_trailing_whitespace("Hello \n\n World\n ") | ||
assert_equal(want, have) | ||
end | ||
|
||
def test_4 | ||
want = "Hello\n\n World" | ||
have = Coolkit.trim_trailing_whitespace("Hello \n\n World") | ||
assert_equal(want, have) | ||
end | ||
|
||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.