-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished core coverage and replaced or remove unnecessary utilities
- Loading branch information
Showing
9 changed files
with
112 additions
and
116 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import is from '@sindresorhus/is' | ||
import type { MergeDeep, UnknownRecord } from 'type-fest' | ||
|
||
export function mergeLocaleParts<First extends UnknownRecord, Next extends UnknownRecord>(first: First, next: Next) { | ||
const output: UnknownRecord = { ...first, ...next } | ||
for (const [key, value] of Object.entries(first)) { | ||
const now = output[key] | ||
if (is.object(value) && is.object(now)) { | ||
output[key] = mergeLocaleParts(value as UnknownRecord, now as UnknownRecord) | ||
} else if (is.array(value) && is.array(now)) { | ||
output[key] = now | ||
} | ||
} | ||
|
||
return output as MergeDeep<First, Next> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest' | ||
import type { PortEntry } from '../../main/services/ports' | ||
import { isIpOrValidPort, isValidLocation } from '@/location' | ||
|
||
let ports: PortEntry[] | ||
beforeAll(() => { | ||
ports = [ | ||
{ | ||
locationId: undefined, | ||
manufacturer: 'Mock Serial Port', | ||
path: '/dev/ttyS0', | ||
pnpId: undefined, | ||
productId: '8087', | ||
serialNumber: '1', | ||
title: 'Mock Serial Port', | ||
vendorId: '8086' | ||
} | ||
] | ||
}) | ||
|
||
afterAll(() => { | ||
vi.restoreAllMocks() | ||
vi.resetModules() | ||
}) | ||
|
||
describe('isIpOrValidPort', () => { | ||
test('port', () => { | ||
expect(isIpOrValidPort('port:/dev/ttyS0', ports)).toBeTruthy() | ||
expect(isIpOrValidPort('port:/dev/ttyS5', ports)).toBeFalsy() | ||
expect(isIpOrValidPort('port:', ports)).toBeFalsy() | ||
expect(isIpOrValidPort('port', ports)).toBeFalsy() | ||
}) | ||
test('ip', () => { | ||
expect(isIpOrValidPort('ip:example.com', ports)).toBeTruthy() | ||
expect(isIpOrValidPort('ip:example', ports)).toBeTruthy() | ||
expect(isIpOrValidPort('ip:127.5.0.111', ports)).toBeTruthy() | ||
expect(isIpOrValidPort('ip:', ports)).toBeFalsy() | ||
expect(isIpOrValidPort('ip', ports)).toBeFalsy() | ||
}) | ||
test('random', () => { | ||
expect(isIpOrValidPort('file:', ports)).toBeFalsy() | ||
expect(isIpOrValidPort('', ports)).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('isValidLocation', () => { | ||
test('port', () => { | ||
expect(isValidLocation('port:/dev/ttyS0', ports)).toBeTruthy() | ||
expect(isValidLocation('port:/dev/ttyS5', ports)).toBeFalsy() | ||
expect(isValidLocation('port:', ports)).toBeFalsy() | ||
expect(isValidLocation('port', ports)).toBeFalsy() | ||
}) | ||
test('ip', () => { | ||
expect(isValidLocation('ip:example.com', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:example', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:127.5.0.111', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:127.5.0.4111', ports)).toBeTruthy() // Host not IP. | ||
expect(isValidLocation('ip:[2561:1900:4545:0003:0200:F8FF:FE21:67CF]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[2260:F3A4:32CB:715D:5D11:D837:FC76:12FC]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[FE80::2045:FAEB:33AF:8374]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[::2045:FAEB:33AF:8374]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[FE80:2045:FAEB:33AF::]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[::11.22.33.44]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[F:F:F:F:F:F:192.168.0.1]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[2001:db8::123.123.123.123]', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[2001:db8::123.123.123.123]:55', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[2001:db8::123.123.123.123]:ab', ports)).toBeFalsy() | ||
expect(isValidLocation('ip:[::]:59', ports)).toBeTruthy() | ||
expect(isValidLocation('ip:[]:59', ports)).toBeFalsy() | ||
expect(isValidLocation('ip://', ports)).toBeFalsy() | ||
expect(isValidLocation('ip:', ports)).toBeFalsy() | ||
}) | ||
test('random', () => { | ||
expect(isValidLocation('file:', ports)).toBeFalsy() | ||
expect(isValidLocation('', ports)).toBeFalsy() | ||
}) | ||
}) |
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