Skip to content

Commit

Permalink
test: Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Dec 7, 2024
1 parent d2efdbd commit 2e3e2be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
43 changes: 17 additions & 26 deletions src/compat/string/toLower.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,16 @@ describe('toLower', () => {
expect(actual).toEqual(expected);
});

it('should preserve contractions with apostrophes', () => {
const postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
["'", '\u2019'].forEach(apos => {
const actual = postfixes.map(postfix => toLower(`a b${apos}${postfix} c`));
const expected = postfixes.map(postfix => `A B${apos}${postfix.toLowerCase()} C`);
expect(actual).toEqual(expected);
});
});

it('should preserve spaces and special characters', () => {
expect(toLower('hello world')).toBe('HELLO WORLD');
expect(toLower('!@#$hello%^&*')).toBe('!@#$HELLO%^&*');
expect(toLower('tabs\tand\nnewlines')).toBe('TABS\tAND\nNEWLINES');
expect(toLower('HELLO WORLD')).toBe('hello world');
expect(toLower('!@#$HELLO%^&*')).toBe('!@#$hello%^&*');
expect(toLower('TABS\tAND\nNEWLINES')).toBe('tabs\tand\nnewlines');
});

it('should handle unicode characters', () => {
expect(toLower('café')).toBe('CAFÉ');
expect(toLower('über')).toBe('ÜBER');
expect(toLower('señor')).toBe('SEÑOR');
expect(toLower('CAFÉ')).toBe('café');
expect(toLower('ÜBER')).toBe('über');
expect(toLower('SEÑOR')).toBe('señor');
});

it('should preserve Latin mathematical operators', () => {
Expand All @@ -57,39 +48,39 @@ describe('toLower', () => {
expect(toLower(123)).toBe('123');
expect(toLower(-0)).toBe('-0');
expect(toLower(0)).toBe('0');
expect(toLower(Infinity)).toBe('INFINITY');
expect(toLower(NaN)).toBe('NAN');
expect(toLower(Infinity)).toBe('infinity');
expect(toLower(NaN)).toBe('nan');
});

it('should handle arrays', () => {
expect(toLower([1, 2, 3])).toBe('1,2,3');
expect(toLower(['a', 'b', 'c'])).toBe('A,B,C');
expect(toLower([1, 'b', -0])).toBe('1,B,-0');
expect(toLower(['a', 'b', 'c'])).toBe('a,b,c');
expect(toLower([1, 'b', -0])).toBe('1,b,-0');
expect(toLower([])).toBe('');
});

it('should handle nested arrays', () => {
expect(toLower([1, [2, 3], 4])).toBe('1,2,3,4');
expect(toLower([[['a']]])).toBe('A');
expect(toLower([[['a']]])).toBe('a');
});

it('should handle symbols', () => {
const sym1 = Symbol('test');
const sym2 = Symbol('');
expect(toLower(sym1)).toBe('SYMBOL(TEST)');
expect(toLower(sym2)).toBe('SYMBOL()');
expect(toLower([Symbol('a'), Symbol('b')])).toBe('SYMBOL(A),SYMBOL(B)');
expect(toLower(sym1)).toBe('symbol(test)');
expect(toLower(sym2)).toBe('symbol()');
expect(toLower([Symbol('a'), Symbol('b')])).toBe('symbol(a),symbol(b)');
});

it('should handle objects', () => {
const obj = { toString: () => 'custom' };
expect(toLower(obj)).toBe('CUSTOM');
expect(toLower({})).toBe('[OBJECT OBJECT]');
expect(toLower(obj)).toBe('custom');
expect(toLower({})).toBe('[object object]');
});

it('should handle mixed types in arrays', () => {
const sym = Symbol('test');
expect(toLower([1, 'b', sym, null, undefined])).toBe('1,B,SYMBOL(TEST),,');
expect(toLower([1, 'b', sym, null, undefined])).toBe('1,b,symbol(test),,');
});

it('should maintain proper TypeScript types', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/compat/util/invoke.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { toPath } from './toPath';
import { toKey } from '../_internal/toKey.ts';
import { last } from '../array/last.ts';
import { get } from '../object/get.ts';

Expand Down Expand Up @@ -55,7 +56,14 @@ function invokeImpl(object: unknown, path: PropertyKey[], args: any[]) {
return undefined;
}

const lastKey = String(last(path));
let lastKey = last(path);
let lastValue = lastKey?.valueOf();

if (typeof lastValue === 'number') {
lastKey = toKey(lastValue);
} else {
lastKey = String(lastKey);
}

const func = get(parent, lastKey);

Expand Down

0 comments on commit 2e3e2be

Please sign in to comment.