@rogolev/value 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +319 -1
- package/docs/classes/Expect/toBe.md +61 -0
- package/docs/classes/Expect/toBeArray.md +52 -0
- package/docs/classes/Expect/toBeAssoc.md +53 -0
- package/docs/classes/Expect/toBeBigInt.md +52 -0
- package/docs/classes/Expect/toBeBool.md +53 -0
- package/docs/classes/Expect/toBeBoolean.md +53 -0
- package/docs/classes/Expect/toBeChar.md +53 -0
- package/docs/classes/Expect/toBeClass.md +53 -0
- package/docs/classes/Expect/toBeFloat.md +53 -0
- package/docs/classes/Expect/toBeFunction.md +52 -0
- package/docs/classes/Expect/toBeInfinity.md +53 -0
- package/docs/classes/Expect/toBeInt.md +53 -0
- package/docs/classes/Expect/toBeInteger.md +53 -0
- package/docs/classes/Expect/toBeList.md +53 -0
- package/docs/classes/Expect/toBeNaN.md +53 -0
- package/docs/classes/Expect/toBeNull.md +51 -0
- package/docs/classes/Expect/toBeNumber.md +52 -0
- package/docs/classes/Expect/toBeNumeric.md +53 -0
- package/docs/classes/Expect/toBeObject.md +52 -0
- package/docs/classes/Expect/toBeScalar.md +53 -0
- package/docs/classes/Expect/toBeString.md +52 -0
- package/docs/classes/Expect/toBeSymbol.md +53 -0
- package/docs/classes/Expect/toBeUndefined.md +54 -0
- package/docs/classes/Expect/toEqual.md +69 -0
- package/docs/classes/Expect/toStrictEqual.md +70 -0
- package/docs/classes/Expect.md +87 -0
- package/docs/classes/Type/expectArray.md +63 -0
- package/docs/classes/Type/expectAssoc.md +65 -0
- package/docs/classes/Type/expectBigInt.md +63 -0
- package/docs/classes/Type/expectBool.md +65 -0
- package/docs/classes/Type/expectBoolean.md +65 -0
- package/docs/classes/Type/expectChar.md +63 -0
- package/docs/classes/Type/expectClass.md +63 -0
- package/docs/classes/Type/expectFloat.md +68 -0
- package/docs/classes/Type/expectFunction.md +63 -0
- package/docs/classes/Type/expectInfinity.md +65 -0
- package/docs/classes/Type/expectInt.md +64 -0
- package/docs/classes/Type/expectInteger.md +64 -0
- package/docs/classes/Type/expectList.md +63 -0
- package/docs/classes/Type/expectNaN.md +63 -0
- package/docs/classes/Type/expectNull.md +63 -0
- package/docs/classes/Type/expectNumber.md +63 -0
- package/docs/classes/Type/expectNumeric.md +63 -0
- package/docs/classes/Type/expectObject.md +64 -0
- package/docs/classes/Type/expectScalar.md +63 -0
- package/docs/classes/Type/expectString.md +63 -0
- package/docs/classes/Type/expectSymbol.md +63 -0
- package/docs/classes/Type/expectUndefined.md +63 -0
- package/docs/classes/Type.md +101 -2
- package/docs/classes.md +2 -1
- package/docs/helpers/array/array_chunk.md +80 -0
- package/docs/helpers/array/array_chunk_with_keys.md +81 -0
- package/docs/helpers/array/array_column.md +110 -0
- package/docs/helpers/array/array_combine.md +77 -0
- package/docs/helpers/array/array_count_values.md +71 -0
- package/docs/helpers/array/array_diff.md +97 -0
- package/docs/helpers/array/array_diff_assoc.md +81 -0
- package/docs/helpers/array/array_diff_key.md +81 -0
- package/docs/helpers/array/array_diff_uassoc.md +101 -0
- package/docs/helpers/array/array_diff_ukey.md +101 -0
- package/docs/helpers/array/array_fill.md +81 -0
- package/docs/helpers/array/array_fill_keys.md +73 -0
- package/docs/helpers/array/array_filter.md +79 -0
- package/docs/helpers/array/array_flip.md +70 -0
- package/docs/helpers/array/array_index_max.md +78 -0
- package/docs/helpers/array/array_index_min.md +78 -0
- package/docs/helpers/array/array_intersect.md +91 -0
- package/docs/helpers/array/array_intersect_assoc.md +91 -0
- package/docs/helpers/array/array_intersect_key.md +91 -0
- package/docs/helpers/array/array_intersect_uassoc.md +101 -0
- package/docs/helpers/array/array_intersect_ukey.md +101 -0
- package/docs/helpers/array/array_key_exists.md +73 -0
- package/docs/helpers/array/array_key_first.md +62 -0
- package/docs/helpers/array/array_key_last.md +62 -0
- package/docs/helpers/array/array_key_to_lower_case.md +57 -0
- package/docs/helpers/array/array_key_to_upper_case.md +57 -0
- package/docs/helpers/array/array_keys.md +62 -0
- package/docs/helpers/array/array_map.md +69 -0
- package/docs/helpers/array/array_merge.md +67 -0
- package/docs/helpers/array/array_merge_recursive.md +86 -0
- package/docs/helpers/array/array_pad.md +83 -0
- package/docs/helpers/array/array_pop.md +64 -0
- package/docs/helpers/array/array_product.md +62 -0
- package/docs/helpers/array/array_push.md +57 -0
- package/docs/helpers/array/array_rand.md +99 -0
- package/docs/helpers/array/array_reduce.md +77 -0
- package/docs/helpers/array/array_replace.md +85 -0
- package/docs/helpers/array/array_replace_recursive.md +87 -0
- package/docs/helpers/array/array_reverse.md +55 -0
- package/docs/helpers/array/array_search.md +74 -0
- package/docs/helpers/array/array_shift.md +64 -0
- package/docs/helpers/array/array_slice.md +65 -0
- package/docs/helpers/array/array_splice.md +103 -0
- package/docs/helpers/array/array_sum.md +55 -0
- package/docs/helpers/array/array_udiff.md +97 -0
- package/docs/helpers/array/array_udiff_assoc.md +101 -0
- package/docs/helpers/array/array_udiff_uassoc.md +88 -0
- package/docs/helpers/array/array_uintersect.md +101 -0
- package/docs/helpers/array/array_uintersect_assoc.md +102 -0
- package/docs/helpers/array/array_uintersect_uassoc.md +135 -0
- package/docs/helpers/array/array_unique.md +54 -0
- package/docs/helpers/array/array_unshift.md +58 -0
- package/docs/helpers/array/array_values.md +54 -0
- package/docs/helpers/array/array_walk.md +87 -0
- package/docs/helpers/array/array_walk_recursive.md +93 -0
- package/docs/helpers/array/count.md +54 -0
- package/docs/helpers/array/in_array.md +65 -0
- package/docs/helpers/array/natsort.md +60 -0
- package/docs/helpers/array/range.md +76 -0
- package/docs/helpers/array/shuffle.md +74 -0
- package/docs/helpers/array/sort.md +79 -0
- package/docs/helpers/expect.md +58 -0
- package/docs/helpers/expect_array.md +63 -0
- package/docs/helpers/expect_assoc.md +65 -0
- package/docs/helpers/expect_bigint.md +63 -0
- package/docs/helpers/expect_bool.md +65 -0
- package/docs/helpers/expect_boolean.md +65 -0
- package/docs/helpers/expect_char.md +63 -0
- package/docs/helpers/expect_class.md +63 -0
- package/docs/helpers/expect_float.md +65 -0
- package/docs/helpers/expect_function.md +63 -0
- package/docs/helpers/expect_infinity.md +65 -0
- package/docs/helpers/expect_int.md +65 -0
- package/docs/helpers/expect_integer.md +65 -0
- package/docs/helpers/expect_list.md +63 -0
- package/docs/helpers/expect_nan.md +63 -0
- package/docs/helpers/expect_null.md +63 -0
- package/docs/helpers/expect_number.md +63 -0
- package/docs/helpers/expect_numeric.md +63 -0
- package/docs/helpers/expect_object.md +64 -0
- package/docs/helpers/expect_scalar.md +63 -0
- package/docs/helpers/expect_string.md +63 -0
- package/docs/helpers/expect_symbol.md +63 -0
- package/docs/helpers/expect_undefined.md +64 -0
- package/docs/helpers/is_char.md +84 -0
- package/docs/helpers/is_equal.md +75 -0
- package/docs/helpers/string/is_digit_char.md +70 -0
- package/docs/helpers/string/is_whitespace_char.md +70 -0
- package/docs/helpers/string/natcompare.md +69 -0
- package/docs/helpers/string/natcompare_numeric.md +70 -0
- package/docs/helpers.md +172 -1
- package/index.mjs +91 -1
- package/package.json +1 -1
- package/prettier.config.mjs +2 -1
- package/src/classes/Expect.mjs +1445 -0
- package/src/classes/Type.mjs +2739 -1284
- package/src/constants.mjs +83 -14
- package/src/helpers/array/array_chunk.mjs +102 -0
- package/src/helpers/array/array_chunk_with_keys.mjs +102 -0
- package/src/helpers/array/array_column.mjs +131 -0
- package/src/helpers/array/array_combine.mjs +26 -0
- package/src/helpers/array/array_count_values.mjs +82 -0
- package/src/helpers/array/array_diff.mjs +77 -0
- package/src/helpers/array/array_diff_assoc.mjs +56 -0
- package/src/helpers/array/array_diff_key.mjs +56 -0
- package/src/helpers/array/array_diff_uassoc.mjs +76 -0
- package/src/helpers/array/array_diff_ukey.mjs +71 -0
- package/src/helpers/array/array_fill.mjs +108 -0
- package/src/helpers/array/array_fill_keys.mjs +90 -0
- package/src/helpers/array/array_filter.mjs +105 -0
- package/src/helpers/array/array_flip.mjs +58 -0
- package/src/helpers/array/array_index_max.mjs +82 -0
- package/src/helpers/array/array_index_min.mjs +82 -0
- package/src/helpers/array/array_intersect.mjs +71 -0
- package/src/helpers/array/array_intersect_assoc.mjs +67 -0
- package/src/helpers/array/array_intersect_key.mjs +67 -0
- package/src/helpers/array/array_intersect_uassoc.mjs +77 -0
- package/src/helpers/array/array_intersect_ukey.mjs +72 -0
- package/src/helpers/array/array_key_exists.mjs +83 -0
- package/src/helpers/array/array_key_first.mjs +73 -0
- package/src/helpers/array/array_key_last.mjs +74 -0
- package/src/helpers/array/array_key_to_lower_case.mjs +71 -0
- package/src/helpers/array/array_key_to_upper_case.mjs +71 -0
- package/src/helpers/array/array_keys.mjs +65 -0
- package/src/helpers/array/array_map.mjs +84 -0
- package/src/helpers/array/array_merge.mjs +95 -0
- package/src/helpers/array/array_merge_recursive.mjs +153 -0
- package/src/helpers/array/array_pad.mjs +105 -0
- package/src/helpers/array/array_pop.mjs +82 -0
- package/src/helpers/array/array_product.mjs +67 -0
- package/src/helpers/array/array_push.mjs +75 -0
- package/src/helpers/array/array_rand.mjs +129 -0
- package/src/helpers/array/array_reduce.mjs +90 -0
- package/src/helpers/array/array_replace.mjs +25 -0
- package/src/helpers/array/array_replace_recursive.mjs +109 -0
- package/src/helpers/array/array_reverse.mjs +62 -0
- package/src/helpers/array/array_search.mjs +104 -0
- package/src/helpers/array/array_shift.mjs +78 -0
- package/src/helpers/array/array_slice.mjs +99 -0
- package/src/helpers/array/array_splice.mjs +218 -0
- package/src/helpers/array/array_sum.mjs +60 -0
- package/src/helpers/array/array_udiff.mjs +91 -0
- package/src/helpers/array/array_udiff_assoc.mjs +71 -0
- package/src/helpers/array/array_udiff_uassoc.mjs +124 -0
- package/src/helpers/array/array_uintersect.mjs +72 -0
- package/src/helpers/array/array_uintersect_assoc.mjs +77 -0
- package/src/helpers/array/array_uintersect_uassoc.mjs +121 -0
- package/src/helpers/array/array_unique.mjs +77 -0
- package/src/helpers/array/array_unshift.mjs +64 -0
- package/src/helpers/array/array_values.mjs +57 -0
- package/src/helpers/array/array_walk.mjs +95 -0
- package/src/helpers/array/array_walk_recursive.mjs +104 -0
- package/src/helpers/array/count.mjs +57 -0
- package/src/helpers/array/in_array.mjs +67 -0
- package/src/helpers/array/natsort.mjs +62 -0
- package/src/helpers/array/range.mjs +121 -0
- package/src/helpers/array/shuffle.mjs +73 -0
- package/src/helpers/array/sort.mjs +69 -0
- package/src/helpers/expect.mjs +44 -0
- package/src/helpers/expect_array.mjs +66 -0
- package/src/helpers/expect_assoc.mjs +66 -0
- package/src/helpers/expect_bigint.mjs +66 -0
- package/src/helpers/expect_bool.mjs +66 -0
- package/src/helpers/expect_boolean.mjs +57 -0
- package/src/helpers/expect_char.mjs +66 -0
- package/src/helpers/expect_class.mjs +66 -0
- package/src/helpers/expect_float.mjs +66 -0
- package/src/helpers/expect_function.mjs +66 -0
- package/src/helpers/expect_infinity.mjs +66 -0
- package/src/helpers/expect_int.mjs +66 -0
- package/src/helpers/expect_integer.mjs +57 -0
- package/src/helpers/expect_list.mjs +66 -0
- package/src/helpers/expect_nan.mjs +66 -0
- package/src/helpers/expect_null.mjs +66 -0
- package/src/helpers/expect_number.mjs +66 -0
- package/src/helpers/expect_numeric.mjs +66 -0
- package/src/helpers/expect_object.mjs +67 -0
- package/src/helpers/expect_scalar.mjs +66 -0
- package/src/helpers/expect_string.mjs +65 -0
- package/src/helpers/expect_symbol.mjs +66 -0
- package/src/helpers/expect_undefined.mjs +66 -0
- package/src/helpers/is_char.mjs +54 -0
- package/src/helpers/is_equal.mjs +94 -0
- package/src/helpers/string/is_digit_char.mjs +60 -0
- package/src/helpers/string/is_whitespace_char.mjs +54 -0
- package/src/helpers/string/natcompare.mjs +107 -0
- package/src/helpers/string/natcompare_numeric.mjs +131 -0
- package/tests/classes/Expect/toBe.test.mjs +60 -0
- package/tests/classes/Expect/toBeArray.test.mjs +46 -0
- package/tests/classes/Expect/toBeAssoc.test.mjs +48 -0
- package/tests/classes/Expect/toBeBigInt.test.mjs +46 -0
- package/tests/classes/Expect/toBeBool.test.mjs +48 -0
- package/tests/classes/Expect/toBeBoolean.test.mjs +48 -0
- package/tests/classes/Expect/toBeChar.test.mjs +46 -0
- package/tests/classes/Expect/toBeClass.test.mjs +48 -0
- package/tests/classes/Expect/toBeFloat.test.mjs +48 -0
- package/tests/classes/Expect/toBeFunction.test.mjs +51 -0
- package/tests/classes/Expect/toBeInfinity.test.mjs +48 -0
- package/tests/classes/Expect/toBeInt.test.mjs +48 -0
- package/tests/classes/Expect/toBeInteger.test.mjs +48 -0
- package/tests/classes/Expect/toBeList.test.mjs +46 -0
- package/tests/classes/Expect/toBeNaN.test.mjs +46 -0
- package/tests/classes/Expect/toBeNull.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumber.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumeric.test.mjs +53 -0
- package/tests/classes/Expect/toBeObject.test.mjs +47 -0
- package/tests/classes/Expect/toBeScalar.test.mjs +63 -0
- package/tests/classes/Expect/toBeString.test.mjs +46 -0
- package/tests/classes/Expect/toBeSymbol.test.mjs +46 -0
- package/tests/classes/Expect/toBeUndefined.test.mjs +50 -0
- package/tests/classes/Expect/toEqual.test.mjs +66 -0
- package/tests/classes/Expect/toStrictEqual.test.mjs +73 -0
- package/tests/classes/Type.test.mjs +1320 -1262
- package/tests/helpers/array/array_chunk.test.mjs +49 -0
- package/tests/helpers/array/array_chunk_with_keys.test.mjs +45 -0
- package/tests/helpers/array/array_column.test.mjs +87 -0
- package/tests/helpers/array/array_combine.test.mjs +41 -0
- package/tests/helpers/array/array_count_values.test.mjs +40 -0
- package/tests/helpers/array/array_diff.test.mjs +78 -0
- package/tests/helpers/array/array_diff_assoc.test.mjs +64 -0
- package/tests/helpers/array/array_diff_key.test.mjs +64 -0
- package/tests/helpers/array/array_diff_uassoc.test.mjs +73 -0
- package/tests/helpers/array/array_diff_ukey.test.mjs +77 -0
- package/tests/helpers/array/array_fill.test.mjs +47 -0
- package/tests/helpers/array/array_fill_keys.test.mjs +35 -0
- package/tests/helpers/array/array_filter.test.mjs +38 -0
- package/tests/helpers/array/array_flip.test.mjs +33 -0
- package/tests/helpers/array/array_index_max.test.mjs +41 -0
- package/tests/helpers/array/array_index_min.test.mjs +41 -0
- package/tests/helpers/array/array_intersect.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_assoc.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_key.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_uassoc.test.mjs +76 -0
- package/tests/helpers/array/array_intersect_ukey.test.mjs +74 -0
- package/tests/helpers/array/array_key_exists.test.mjs +36 -0
- package/tests/helpers/array/array_key_first.test.mjs +29 -0
- package/tests/helpers/array/array_key_last.test.mjs +29 -0
- package/tests/helpers/array/array_key_to_lower_case.test.mjs +23 -0
- package/tests/helpers/array/array_key_to_upper_case.test.mjs +23 -0
- package/tests/helpers/array/array_keys.test.mjs +27 -0
- package/tests/helpers/array/array_map.test.mjs +32 -0
- package/tests/helpers/array/array_merge.test.mjs +37 -0
- package/tests/helpers/array/array_merge_recursive.test.mjs +65 -0
- package/tests/helpers/array/array_pad.test.mjs +48 -0
- package/tests/helpers/array/array_pop.test.mjs +29 -0
- package/tests/helpers/array/array_product.test.mjs +33 -0
- package/tests/helpers/array/array_push.test.mjs +31 -0
- package/tests/helpers/array/array_rand.test.mjs +59 -0
- package/tests/helpers/array/array_reduce.test.mjs +44 -0
- package/tests/helpers/array/array_replace.test.mjs +46 -0
- package/tests/helpers/array/array_replace_recursive.test.mjs +46 -0
- package/tests/helpers/array/array_reverse.test.mjs +31 -0
- package/tests/helpers/array/array_search.test.mjs +48 -0
- package/tests/helpers/array/array_shift.test.mjs +29 -0
- package/tests/helpers/array/array_slice.test.mjs +49 -0
- package/tests/helpers/array/array_splice.test.mjs +67 -0
- package/tests/helpers/array/array_sum.test.mjs +27 -0
- package/tests/helpers/array/array_udiff.test.mjs +95 -0
- package/tests/helpers/array/array_udiff_assoc.test.mjs +77 -0
- package/tests/helpers/array/array_udiff_uassoc.test.mjs +89 -0
- package/tests/helpers/array/array_uintersect.test.mjs +78 -0
- package/tests/helpers/array/array_uintersect_assoc.test.mjs +80 -0
- package/tests/helpers/array/array_uintersect_uassoc.test.mjs +122 -0
- package/tests/helpers/array/array_unique.test.mjs +27 -0
- package/tests/helpers/array/array_unshift.test.mjs +31 -0
- package/tests/helpers/array/array_values.test.mjs +27 -0
- package/tests/helpers/array/array_walk.test.mjs +48 -0
- package/tests/helpers/array/array_walk_recursive.test.mjs +53 -0
- package/tests/helpers/array/count.test.mjs +27 -0
- package/tests/helpers/array/in_array.test.mjs +52 -0
- package/tests/helpers/array/natsort.test.mjs +71 -0
- package/tests/helpers/array/range.test.mjs +51 -0
- package/tests/helpers/array/shuffle.test.mjs +42 -0
- package/tests/helpers/array/sort.test.mjs +60 -0
- package/tests/helpers/array.test.mjs +58 -58
- package/tests/helpers/expect.test.mjs +95 -0
- package/tests/helpers/expect_array.test.mjs +71 -0
- package/tests/helpers/expect_assoc.test.mjs +61 -0
- package/tests/helpers/expect_bigint.test.mjs +63 -0
- package/tests/helpers/expect_bool.test.mjs +59 -0
- package/tests/helpers/expect_boolean.test.mjs +61 -0
- package/tests/helpers/expect_char.test.mjs +63 -0
- package/tests/helpers/expect_class.test.mjs +64 -0
- package/tests/helpers/expect_float.test.mjs +64 -0
- package/tests/helpers/expect_function.test.mjs +65 -0
- package/tests/helpers/expect_infinity.test.mjs +62 -0
- package/tests/helpers/expect_int.test.mjs +57 -0
- package/tests/helpers/expect_integer.test.mjs +59 -0
- package/tests/helpers/expect_list.test.mjs +73 -0
- package/tests/helpers/expect_nan.test.mjs +57 -0
- package/tests/helpers/expect_null.test.mjs +57 -0
- package/tests/helpers/expect_number.test.mjs +57 -0
- package/tests/helpers/expect_numeric.test.mjs +57 -0
- package/tests/helpers/expect_object.test.mjs +63 -0
- package/tests/helpers/expect_scalar.test.mjs +72 -0
- package/tests/helpers/expect_string.test.mjs +65 -0
- package/tests/helpers/expect_symbol.test.mjs +66 -0
- package/tests/helpers/expect_undefined.test.mjs +59 -0
- package/tests/helpers/is_char.test.mjs +40 -0
- package/tests/helpers/is_equal.test.mjs +110 -0
- package/tests/helpers/string/is_digit_char.test.mjs +32 -0
- package/tests/helpers/string/is_whitespace_char.test.mjs +32 -0
- package/tests/helpers/string/natcompare.test.mjs +100 -0
- package/tests/helpers/string/natcompare_numeric.test.mjs +110 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
import is_string from '../is_string.mjs';
|
2
|
+
import is_digit_char from './is_digit_char.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Сравнивает две строки, содержащие числовые значения, в естественном порядке.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `natcompare_numeric` используется для сравнения двух строк, содержащих числовые значения, в естественном порядке.
|
10
|
+
* Она поддерживает строки с ведущими нулями и игнорирует их при сравнении.
|
11
|
+
*
|
12
|
+
* ### Параметры
|
13
|
+
*
|
14
|
+
* - `a` (string): Первая строка для сравнения.
|
15
|
+
* - `b` (string): Вторая строка для сравнения.
|
16
|
+
*
|
17
|
+
* ### Возвращаемое значение
|
18
|
+
*
|
19
|
+
* Возвращает отрицательное значение, если `a` меньше `b`, ноль, если `a` равно `b`, и положительное значение, если `a` больше `b`.
|
20
|
+
*
|
21
|
+
* ### Примеры использования
|
22
|
+
*
|
23
|
+
* 1. Сравнение строк с числовыми значениями:
|
24
|
+
*
|
25
|
+
* ```js
|
26
|
+
* const result = natcompare_numeric('10', '2');
|
27
|
+
* console.log(result); // 1
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* 2. Сравнение строк с ведущими нулями:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* const result = natcompare_numeric('0010', '10');
|
34
|
+
* console.log(result); // 0
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* 3. Сравнение строк с пробелами:
|
38
|
+
*
|
39
|
+
* ```js
|
40
|
+
* const result = natcompare_numeric(' 10', '10');
|
41
|
+
* console.log(result); // 0
|
42
|
+
* ```
|
43
|
+
*
|
44
|
+
* 4. Сравнение строк с буквами и числами:
|
45
|
+
*
|
46
|
+
* ```js
|
47
|
+
* const result = natcompare_numeric('a10', 'a2');
|
48
|
+
* console.log(result); // 1
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* 5. Сравнение строк с разными символами:
|
52
|
+
*
|
53
|
+
* ```js
|
54
|
+
* const result = natcompare_numeric('10-', '10+');
|
55
|
+
* console.log(result); // 0
|
56
|
+
* ```
|
57
|
+
*
|
58
|
+
* @param {string} a Первая строка для сравнения.
|
59
|
+
* @param {string} b Вторая строка для сравнения.
|
60
|
+
* @returns {number} Возвращает отрицательное значение, если `a` меньше `b`, ноль, если `a` равно `b`, и положительное значение, если `a` больше `b`.
|
61
|
+
* @throws {TypeError} Если параметры не являются строками.
|
62
|
+
*/
|
63
|
+
export default function natcompare_numeric(a, b) {
|
64
|
+
if (!is_string(a)) {
|
65
|
+
throw new TypeError('Параметр "a" должен быть строкой.');
|
66
|
+
}
|
67
|
+
|
68
|
+
if (!is_string(b)) {
|
69
|
+
throw new TypeError('Параметр "b" должен быть строкой.');
|
70
|
+
}
|
71
|
+
|
72
|
+
a = a.trim();
|
73
|
+
b = b.trim();
|
74
|
+
|
75
|
+
let result = 0;
|
76
|
+
|
77
|
+
let ia = 0;
|
78
|
+
let ib = 0;
|
79
|
+
|
80
|
+
// Пропускаем ведущие нули
|
81
|
+
while (ia < a.length && a[ia] === '0') {
|
82
|
+
ia++;
|
83
|
+
}
|
84
|
+
while (ib < b.length && b[ib] === '0') {
|
85
|
+
ib++;
|
86
|
+
}
|
87
|
+
|
88
|
+
// Сравниваем оставшиеся части строк
|
89
|
+
while (ia < a.length && ib < b.length) {
|
90
|
+
const ca = a[ia];
|
91
|
+
const cb = b[ib];
|
92
|
+
|
93
|
+
if (!is_digit_char(ca) && !is_digit_char(cb)) {
|
94
|
+
ia++;
|
95
|
+
ib++;
|
96
|
+
continue;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (!is_digit_char(ca)) {
|
100
|
+
ia++;
|
101
|
+
continue;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (!is_digit_char(cb)) {
|
105
|
+
ib++;
|
106
|
+
continue;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (ca < cb) {
|
110
|
+
if (result === 0) {
|
111
|
+
result = -1;
|
112
|
+
}
|
113
|
+
} else if (ca > cb) {
|
114
|
+
if (result === 0) {
|
115
|
+
result = 1;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
ia++;
|
120
|
+
ib++;
|
121
|
+
}
|
122
|
+
|
123
|
+
// Если одна строка длиннее другой, она считается больше
|
124
|
+
if (ia < a.length) {
|
125
|
+
return 1;
|
126
|
+
} else if (ib < b.length) {
|
127
|
+
return -1;
|
128
|
+
}
|
129
|
+
|
130
|
+
return result;
|
131
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBe класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значения строго равны (числа)', () => {
|
6
|
+
const expectInstance = new Expect(5);
|
7
|
+
expect(expectInstance.toBe(5)).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен возвращать true, если значения строго равны (строки)', () => {
|
11
|
+
const expectInstance = new Expect('hello');
|
12
|
+
expect(expectInstance.toBe('hello')).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должен выбрасывать ошибку, если значения не равны (числа)', () => {
|
16
|
+
const expectInstance = new Expect(5);
|
17
|
+
expect(() => expectInstance.toBe(10)).toThrow(TypeError);
|
18
|
+
expect(() => expectInstance.toBe(10)).toThrow('');
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значения не равны', () => {
|
22
|
+
const expectInstance = new Expect(5);
|
23
|
+
expect(() => expectInstance.toBe(10, 'Значения не равны')).toThrow(TypeError);
|
24
|
+
expect(() => expectInstance.toBe(10, 'Значения не равны')).toThrow('Значения не равны');
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
28
|
+
const expectInstance = new Expect(5);
|
29
|
+
expect(() => expectInstance.toBe(5, 123)).toThrow(TypeError);
|
30
|
+
expect(() => expectInstance.toBe(5, 123)).toThrow(
|
31
|
+
'Параметр "message" должен быть строкой.',
|
32
|
+
);
|
33
|
+
});
|
34
|
+
|
35
|
+
test('Должен возвращать true, если значения строго равны (объекты)', () => {
|
36
|
+
const obj = { a: 1, b: 2 };
|
37
|
+
const expectInstance = new Expect(obj);
|
38
|
+
expect(expectInstance.toBe(obj)).toBe(true);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должен выбрасывать ошибку, если значения не равны (объекты)', () => {
|
42
|
+
const obj1 = { a: 1, b: 2 };
|
43
|
+
const obj2 = { a: 1, b: 3 };
|
44
|
+
const expectInstance = new Expect(obj1);
|
45
|
+
expect(() => expectInstance.toBe(obj2)).toThrow(TypeError);
|
46
|
+
});
|
47
|
+
|
48
|
+
test('Должен возвращать true, если значения строго равны (массивы)', () => {
|
49
|
+
const arr = [1, 2, 3];
|
50
|
+
const expectInstance = new Expect(arr);
|
51
|
+
expect(expectInstance.toBe(arr)).toBe(true);
|
52
|
+
});
|
53
|
+
|
54
|
+
test('Должен выбрасывать ошибку, если значения не равны (массивы)', () => {
|
55
|
+
const arr1 = [1, 2, 3];
|
56
|
+
const arr2 = [1, 2, 4];
|
57
|
+
const expectInstance = new Expect(arr1);
|
58
|
+
expect(() => expectInstance.toBe(arr2)).toThrow(TypeError);
|
59
|
+
});
|
60
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeArray класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является массивом', () => {
|
6
|
+
const expectInstance = new Expect([1, 2, 3]);
|
7
|
+
expect(expectInstance.toBeArray()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен выбрасывать ошибку, если значение не является массивом', () => {
|
11
|
+
const expectInstance = new Expect('not an array');
|
12
|
+
expect(() => expectInstance.toBeArray()).toThrow(TypeError);
|
13
|
+
expect(() => expectInstance.toBeArray()).toThrow('');
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является массивом', () => {
|
17
|
+
const expectInstance = new Expect('not an array');
|
18
|
+
expect(() => expectInstance.toBeArray('Значение должно быть массивом')).toThrow(TypeError);
|
19
|
+
expect(() => expectInstance.toBeArray('Значение должно быть массивом')).toThrow(
|
20
|
+
'Значение должно быть массивом',
|
21
|
+
);
|
22
|
+
});
|
23
|
+
|
24
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
25
|
+
const expectInstance = new Expect([1, 2, 3]);
|
26
|
+
expect(() => expectInstance.toBeArray(123)).toThrow(TypeError);
|
27
|
+
expect(() => expectInstance.toBeArray(123)).toThrow(
|
28
|
+
'Параметр "message" должен быть строкой.',
|
29
|
+
);
|
30
|
+
});
|
31
|
+
|
32
|
+
test('Должен возвращать true, если значение является пустым массивом', () => {
|
33
|
+
const expectInstance = new Expect([]);
|
34
|
+
expect(expectInstance.toBeArray()).toBe(true);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должен возвращать true, если значение является массивом объектов', () => {
|
38
|
+
const expectInstance = new Expect([{ a: 1 }, { b: 2 }]);
|
39
|
+
expect(expectInstance.toBeArray()).toBe(true);
|
40
|
+
});
|
41
|
+
|
42
|
+
test('Должен возвращать true, если значение является ассоциативным массивом', () => {
|
43
|
+
const expectInstance = new Expect({ a: 1, b: 2 });
|
44
|
+
expect(expectInstance.toBeArray()).toBe(true);
|
45
|
+
});
|
46
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeAssoc класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является ассоциативным массивом', () => {
|
6
|
+
const expectInstance = new Expect({ a: 1, b: 2, c: 3 });
|
7
|
+
expect(expectInstance.toBeAssoc()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен выбрасывать ошибку, если значение не является ассоциативным массивом', () => {
|
11
|
+
const expectInstance = new Expect([1, 2, 3]);
|
12
|
+
expect(() => expectInstance.toBeAssoc()).toThrow(TypeError);
|
13
|
+
expect(() => expectInstance.toBeAssoc()).toThrow('');
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является ассоциативным массивом', () => {
|
17
|
+
const expectInstance = new Expect([1, 2, 3]);
|
18
|
+
expect(() =>
|
19
|
+
expectInstance.toBeAssoc('Значение должно быть ассоциативным массивом'),
|
20
|
+
).toThrow(TypeError);
|
21
|
+
expect(() =>
|
22
|
+
expectInstance.toBeAssoc('Значение должно быть ассоциативным массивом'),
|
23
|
+
).toThrow('Значение должно быть ассоциативным массивом');
|
24
|
+
});
|
25
|
+
|
26
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
27
|
+
const expectInstance = new Expect({ a: 1, b: 2, c: 3 });
|
28
|
+
expect(() => expectInstance.toBeAssoc(123)).toThrow(TypeError);
|
29
|
+
expect(() => expectInstance.toBeAssoc(123)).toThrow(
|
30
|
+
'Параметр "message" должен быть строкой.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должен возвращать true, если значение является пустым объектом', () => {
|
35
|
+
const expectInstance = new Expect({});
|
36
|
+
expect(expectInstance.toBeAssoc()).toBe(true);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('Должен возвращать true, если значение является объектом с вложенными объектами', () => {
|
40
|
+
const expectInstance = new Expect({ a: { b: 2 }, c: 3 });
|
41
|
+
expect(expectInstance.toBeAssoc()).toBe(true);
|
42
|
+
});
|
43
|
+
|
44
|
+
test('Должен выбрасывать ошибку, если значение является массивом, а не ассоциативным массивом', () => {
|
45
|
+
const expectInstance = new Expect([1, 2, 3]);
|
46
|
+
expect(() => expectInstance.toBeAssoc()).toThrow(TypeError);
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeBigInt класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является BigInt', () => {
|
6
|
+
const expectInstance = new Expect(123n);
|
7
|
+
expect(expectInstance.toBeBigInt()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен выбрасывать ошибку, если значение не является BigInt', () => {
|
11
|
+
const expectInstance = new Expect(123);
|
12
|
+
expect(() => expectInstance.toBeBigInt()).toThrow(TypeError);
|
13
|
+
expect(() => expectInstance.toBeBigInt()).toThrow('');
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является BigInt', () => {
|
17
|
+
const expectInstance = new Expect(123);
|
18
|
+
expect(() => expectInstance.toBeBigInt('Значение должно быть BigInt')).toThrow(TypeError);
|
19
|
+
expect(() => expectInstance.toBeBigInt('Значение должно быть BigInt')).toThrow(
|
20
|
+
'Значение должно быть BigInt',
|
21
|
+
);
|
22
|
+
});
|
23
|
+
|
24
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
25
|
+
const expectInstance = new Expect(123n);
|
26
|
+
expect(() => expectInstance.toBeBigInt(123)).toThrow(TypeError);
|
27
|
+
expect(() => expectInstance.toBeBigInt(123)).toThrow(
|
28
|
+
'Параметр "message" должен быть строкой.',
|
29
|
+
);
|
30
|
+
});
|
31
|
+
|
32
|
+
test('Должен возвращать true, если значение является отрицательным BigInt', () => {
|
33
|
+
const expectInstance = new Expect(-123n);
|
34
|
+
expect(expectInstance.toBeBigInt()).toBe(true);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не BigInt', () => {
|
38
|
+
const expectInstance = new Expect('123');
|
39
|
+
expect(() => expectInstance.toBeBigInt()).toThrow(TypeError);
|
40
|
+
});
|
41
|
+
|
42
|
+
test('Должен выбрасывать ошибку, если значение является числом с плавающей запятой, а не BigInt', () => {
|
43
|
+
const expectInstance = new Expect(123.45);
|
44
|
+
expect(() => expectInstance.toBeBigInt()).toThrow(TypeError);
|
45
|
+
});
|
46
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeBool класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является логическим типом (true)', () => {
|
6
|
+
const expectInstance = new Expect(true);
|
7
|
+
expect(expectInstance.toBeBool()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен возвращать true, если значение является логическим типом (false)', () => {
|
11
|
+
const expectInstance = new Expect(false);
|
12
|
+
expect(expectInstance.toBeBool()).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должен выбрасывать ошибку, если значение не является логическим типом', () => {
|
16
|
+
const expectInstance = new Expect(1);
|
17
|
+
expect(() => expectInstance.toBeBool()).toThrow(TypeError);
|
18
|
+
expect(() => expectInstance.toBeBool()).toThrow('');
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является логическим типом', () => {
|
22
|
+
const expectInstance = new Expect(1);
|
23
|
+
expect(() => expectInstance.toBeBool('Значение должно быть логическим типом')).toThrow(
|
24
|
+
TypeError,
|
25
|
+
);
|
26
|
+
expect(() => expectInstance.toBeBool('Значение должно быть логическим типом')).toThrow(
|
27
|
+
'Значение должно быть логическим типом',
|
28
|
+
);
|
29
|
+
});
|
30
|
+
|
31
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
32
|
+
const expectInstance = new Expect(true);
|
33
|
+
expect(() => expectInstance.toBeBool(123)).toThrow(TypeError);
|
34
|
+
expect(() => expectInstance.toBeBool(123)).toThrow(
|
35
|
+
'Параметр "message" должен быть строкой.',
|
36
|
+
);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не логическим типом', () => {
|
40
|
+
const expectInstance = new Expect('true');
|
41
|
+
expect(() => expectInstance.toBeBool()).toThrow(TypeError);
|
42
|
+
});
|
43
|
+
|
44
|
+
test('Должен выбрасывать ошибку, если значение является числом, а не логическим типом', () => {
|
45
|
+
const expectInstance = new Expect(0);
|
46
|
+
expect(() => expectInstance.toBeBool()).toThrow(TypeError);
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeBoolean класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является логическим типом (true)', () => {
|
6
|
+
const expectInstance = new Expect(true);
|
7
|
+
expect(expectInstance.toBeBoolean()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен возвращать true, если значение является логическим типом (false)', () => {
|
11
|
+
const expectInstance = new Expect(false);
|
12
|
+
expect(expectInstance.toBeBoolean()).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должен выбрасывать ошибку, если значение не является логическим типом', () => {
|
16
|
+
const expectInstance = new Expect(1);
|
17
|
+
expect(() => expectInstance.toBeBoolean()).toThrow(TypeError);
|
18
|
+
expect(() => expectInstance.toBeBoolean()).toThrow('');
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является логическим типом', () => {
|
22
|
+
const expectInstance = new Expect(1);
|
23
|
+
expect(() => expectInstance.toBeBoolean('Значение должно быть логическим типом')).toThrow(
|
24
|
+
TypeError,
|
25
|
+
);
|
26
|
+
expect(() => expectInstance.toBeBoolean('Значение должно быть логическим типом')).toThrow(
|
27
|
+
'Значение должно быть логическим типом',
|
28
|
+
);
|
29
|
+
});
|
30
|
+
|
31
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
32
|
+
const expectInstance = new Expect(true);
|
33
|
+
expect(() => expectInstance.toBeBoolean(123)).toThrow(TypeError);
|
34
|
+
expect(() => expectInstance.toBeBoolean(123)).toThrow(
|
35
|
+
'Параметр "message" должен быть строкой.',
|
36
|
+
);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не логическим типом', () => {
|
40
|
+
const expectInstance = new Expect('true');
|
41
|
+
expect(() => expectInstance.toBeBoolean()).toThrow(TypeError);
|
42
|
+
});
|
43
|
+
|
44
|
+
test('Должен выбрасывать ошибку, если значение является числом, а не логическим типом', () => {
|
45
|
+
const expectInstance = new Expect(0);
|
46
|
+
expect(() => expectInstance.toBeBoolean()).toThrow(TypeError);
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeChar класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является символом (один символ)', () => {
|
6
|
+
const expectInstance = new Expect('a');
|
7
|
+
expect(expectInstance.toBeChar()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен выбрасывать ошибку, если значение не является символом (строка из нескольких символов)', () => {
|
11
|
+
const expectInstance = new Expect('abc');
|
12
|
+
expect(() => expectInstance.toBeChar()).toThrow(TypeError);
|
13
|
+
expect(() => expectInstance.toBeChar()).toThrow('');
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является символом', () => {
|
17
|
+
const expectInstance = new Expect('abc');
|
18
|
+
expect(() => expectInstance.toBeChar('Значение должно быть символом')).toThrow(TypeError);
|
19
|
+
expect(() => expectInstance.toBeChar('Значение должно быть символом')).toThrow(
|
20
|
+
'Значение должно быть символом',
|
21
|
+
);
|
22
|
+
});
|
23
|
+
|
24
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
25
|
+
const expectInstance = new Expect('a');
|
26
|
+
expect(() => expectInstance.toBeChar(123)).toThrow(TypeError);
|
27
|
+
expect(() => expectInstance.toBeChar(123)).toThrow(
|
28
|
+
'Параметр "message" должен быть строкой.',
|
29
|
+
);
|
30
|
+
});
|
31
|
+
|
32
|
+
test('Должен выбрасывать ошибку, если значение является числом, а не символом', () => {
|
33
|
+
const expectInstance = new Expect(1);
|
34
|
+
expect(() => expectInstance.toBeChar()).toThrow(TypeError);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должен выбрасывать ошибку, если значение является пустой строкой', () => {
|
38
|
+
const expectInstance = new Expect('');
|
39
|
+
expect(() => expectInstance.toBeChar()).toThrow(TypeError);
|
40
|
+
});
|
41
|
+
|
42
|
+
test('Должен возвращать true, если значение является символом (специальный символ)', () => {
|
43
|
+
const expectInstance = new Expect('@');
|
44
|
+
expect(expectInstance.toBeChar()).toBe(true);
|
45
|
+
});
|
46
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeClass класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является классом', () => {
|
6
|
+
class MyClass {}
|
7
|
+
const expectInstance = new Expect(MyClass);
|
8
|
+
expect(expectInstance.toBeClass()).toBe(true);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должен выбрасывать ошибку, если значение не является классом (функция)', () => {
|
12
|
+
const expectInstance = new Expect(() => {});
|
13
|
+
expect(() => expectInstance.toBeClass()).toThrow(TypeError);
|
14
|
+
expect(() => expectInstance.toBeClass()).toThrow('');
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является классом', () => {
|
18
|
+
const expectInstance = new Expect(() => {});
|
19
|
+
expect(() => expectInstance.toBeClass('Значение должно быть классом')).toThrow(TypeError);
|
20
|
+
expect(() => expectInstance.toBeClass('Значение должно быть классом')).toThrow(
|
21
|
+
'Значение должно быть классом',
|
22
|
+
);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
26
|
+
class MyClass {}
|
27
|
+
const expectInstance = new Expect(MyClass);
|
28
|
+
expect(() => expectInstance.toBeClass(123)).toThrow(TypeError);
|
29
|
+
expect(() => expectInstance.toBeClass(123)).toThrow(
|
30
|
+
'Параметр "message" должен быть строкой.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должен выбрасывать ошибку, если значение является объектом, а не классом', () => {
|
35
|
+
const expectInstance = new Expect({ a: 1 });
|
36
|
+
expect(() => expectInstance.toBeClass()).toThrow(TypeError);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не классом', () => {
|
40
|
+
const expectInstance = new Expect('MyClass');
|
41
|
+
expect(() => expectInstance.toBeClass()).toThrow(TypeError);
|
42
|
+
});
|
43
|
+
|
44
|
+
test('Должен выбрасывать ошибку, если значение является числом, а не классом', () => {
|
45
|
+
const expectInstance = new Expect(123);
|
46
|
+
expect(() => expectInstance.toBeClass()).toThrow(TypeError);
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeFloat класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является числом с плавающей запятой', () => {
|
6
|
+
const expectInstance = new Expect(3.14);
|
7
|
+
expect(expectInstance.toBeFloat()).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должен выбрасывать ошибку, если значение не является числом с плавающей запятой', () => {
|
11
|
+
const expectInstance = new Expect(3);
|
12
|
+
expect(() => expectInstance.toBeFloat()).toThrow(TypeError);
|
13
|
+
expect(() => expectInstance.toBeFloat()).toThrow('');
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является числом с плавающей запятой', () => {
|
17
|
+
const expectInstance = new Expect(3);
|
18
|
+
expect(() =>
|
19
|
+
expectInstance.toBeFloat('Значение должно быть числом с плавающей запятой'),
|
20
|
+
).toThrow(TypeError);
|
21
|
+
expect(() =>
|
22
|
+
expectInstance.toBeFloat('Значение должно быть числом с плавающей запятой'),
|
23
|
+
).toThrow('Значение должно быть числом с плавающей запятой');
|
24
|
+
});
|
25
|
+
|
26
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
27
|
+
const expectInstance = new Expect(3.14);
|
28
|
+
expect(() => expectInstance.toBeFloat(123)).toThrow(TypeError);
|
29
|
+
expect(() => expectInstance.toBeFloat(123)).toThrow(
|
30
|
+
'Параметр "message" должен быть строкой.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не числом с плавающей запятой', () => {
|
35
|
+
const expectInstance = new Expect('3.14');
|
36
|
+
expect(() => expectInstance.toBeFloat()).toThrow(TypeError);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('Должен выбрасывать ошибку, если значение является целым числом, а не числом с плавающей запятой', () => {
|
40
|
+
const expectInstance = new Expect(3);
|
41
|
+
expect(() => expectInstance.toBeFloat()).toThrow(TypeError);
|
42
|
+
});
|
43
|
+
|
44
|
+
test('Должен возвращать true, если значение является отрицательным числом с плавающей запятой', () => {
|
45
|
+
const expectInstance = new Expect(-3.14);
|
46
|
+
expect(expectInstance.toBeFloat()).toBe(true);
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { Expect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Метод toBeFunction класса Expect', () => {
|
5
|
+
test('Должен возвращать true, если значение является функцией', () => {
|
6
|
+
function myFunction() {}
|
7
|
+
const expectInstance = new Expect(myFunction);
|
8
|
+
expect(expectInstance.toBeFunction()).toBe(true);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должен выбрасывать ошибку, если значение не является функцией (число)', () => {
|
12
|
+
const expectInstance = new Expect(123);
|
13
|
+
expect(() => expectInstance.toBeFunction()).toThrow(TypeError);
|
14
|
+
expect(() => expectInstance.toBeFunction()).toThrow('');
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должен выбрасывать ошибку с пользовательским сообщением, если значение не является функцией', () => {
|
18
|
+
const expectInstance = new Expect(123);
|
19
|
+
expect(() => expectInstance.toBeFunction('Значение должно быть функцией')).toThrow(
|
20
|
+
TypeError,
|
21
|
+
);
|
22
|
+
expect(() => expectInstance.toBeFunction('Значение должно быть функцией')).toThrow(
|
23
|
+
'Значение должно быть функцией',
|
24
|
+
);
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должен выбрасывать ошибку, если параметр message не является строкой', () => {
|
28
|
+
function myFunction() {}
|
29
|
+
const expectInstance = new Expect(myFunction);
|
30
|
+
expect(() => expectInstance.toBeFunction(123)).toThrow(TypeError);
|
31
|
+
expect(() => expectInstance.toBeFunction(123)).toThrow(
|
32
|
+
'Параметр "message" должен быть строкой.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должен выбрасывать ошибку, если значение является строкой, а не функцией', () => {
|
37
|
+
const expectInstance = new Expect('function');
|
38
|
+
expect(() => expectInstance.toBeFunction()).toThrow(TypeError);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должен выбрасывать ошибку, если значение является объектом, а не функцией', () => {
|
42
|
+
const expectInstance = new Expect({ a: 1 });
|
43
|
+
expect(() => expectInstance.toBeFunction()).toThrow(TypeError);
|
44
|
+
});
|
45
|
+
|
46
|
+
test('Должен возвращать true, если значение является функцией (стрелочная функция)', () => {
|
47
|
+
const myFunction = () => {};
|
48
|
+
const expectInstance = new Expect(myFunction);
|
49
|
+
expect(expectInstance.toBeFunction()).toBe(true);
|
50
|
+
});
|
51
|
+
});
|