Ignore:
Timestamp:
12/12/24 17:06:06 (6 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Children:
79a0317
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified imaps-frontend/node_modules/es-to-primitive/test/es5.js

    rd565449 r0c6b92a  
    44var toPrimitive = require('../es5');
    55var is = require('object-is');
    6 var forEach = require('foreach');
     6var forEach = require('for-each');
    77var functionName = require('function.prototype.name');
    88var debug = require('object-inspect');
    9 var hasSymbols = require('has-symbols')();
     9var v = require('es-value-fixtures');
    1010
    1111test('function properties', function (t) {
     
    1616});
    1717
    18 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];
    19 
    2018test('primitives', function (t) {
    21         forEach(primitives, function (i) {
     19        forEach(v.primitives, function (i) {
    2220                t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value');
    2321                t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value');
     
    2725});
    2826
    29 test('Symbols', { skip: !hasSymbols }, function (t) {
    30         var symbols = [
    31                 Symbol('foo'),
    32                 Symbol.iterator,
    33                 Symbol['for']('foo') // eslint-disable-line no-restricted-properties
    34         ];
    35         forEach(symbols, function (sym) {
     27test('Symbols', { skip: !v.hasSymbols }, function (t) {
     28        forEach(v.symbols, function (sym) {
    3629                t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value');
    3730                t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value');
     
    7063});
    7164
    72 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
    73 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
    74 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
    75 var coercibleFnObject = {
    76         valueOf: function () { return function valueOfFn() {}; },
    77         toString: function () { return 42; }
    78 };
    79 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
    80 var uncoercibleFnObject = {
    81         valueOf: function () { return function valueOfFn() {}; },
    82         toString: function () { return function toStrFn() {}; }
    83 };
     65test('Objects', function (t) {
     66        t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
     67        t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to toString');
     68        t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    8469
    85 test('Objects', function (t) {
    86         t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
    87         t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to toString');
    88         t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    89 
    90         t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to toString');
    91         t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString');
    92         t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString');
     70        t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to toString');
     71        t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString');
     72        t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString');
    9373
    9474        t.ok(is(toPrimitive({}), '[object Object]'), '{} with no hint coerces to Object#toString');
     
    9676        t.ok(is(toPrimitive({}, Number), '[object Object]'), '{} with hint Number coerces to Object#toString');
    9777
    98         t.equal(toPrimitive(toStringOnlyObject), toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');
    99         t.equal(toPrimitive(toStringOnlyObject, String), toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString');
    100         t.equal(toPrimitive(toStringOnlyObject, Number), toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString');
     78        t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');
     79        t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString');
     80        t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString');
    10181
    102         t.equal(toPrimitive(valueOfOnlyObject), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
    103         t.equal(toPrimitive(valueOfOnlyObject, String), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf');
    104         t.equal(toPrimitive(valueOfOnlyObject, Number), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
     82        t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
     83        t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf');
     84        t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
    10585
    10686        t.test('exceptions', function (st) {
    107                 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
    108                 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
    109                 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
     87                st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
     88                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
     89                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
    11090
    111                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
    112                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
    113                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
     91                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
     92                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
     93                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
    11494                st.end();
    11595        });
Note: See TracChangeset for help on using the changeset viewer.