-
-
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.
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
366deb3
commit 97c894b
Showing
19 changed files
with
491 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,5 @@ ignore: | |
- '!src/index.ts' | ||
|
||
profiling: | ||
critical_files_paths: [] | ||
critical_files_paths: | ||
- src/location.ts |
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
Empty file.
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,49 @@ | ||
/** | ||
* @file Fixtures - hrt | ||
* @module fixtures/hrt | ||
* @see https://codewars.com/kata/52685f7382004e774f0001f7 | ||
*/ | ||
|
||
/** | ||
* Given a non-negative integer, `seconds`, the functions returns the time in a | ||
* human-readable format (`HH:MM:SS`). | ||
* | ||
* @example | ||
* hrt(0) // '00:00:00' | ||
* @example | ||
* hrt(60) // '00:01:00' | ||
* @example | ||
* hrt(359999) // '99:59:59' | ||
* | ||
* @param {number} seconds - Time in seconds | ||
* @return {string} Time in human-readable format (`HH:MM:SS`) | ||
*/ | ||
const hrt = (seconds: number): string => { | ||
/** | ||
* {@linkcode seconds} in human-readable format. | ||
* | ||
* @var {string} formatted | ||
*/ | ||
let formatted: string = '' | ||
|
||
// convert seconds to human-readable time format | ||
for (const converter of [3600, 60, 1]) { | ||
/** | ||
* {@linkcode seconds} in hours, minutes, or seconds. | ||
* | ||
* @const {number} time | ||
*/ | ||
const time: number = seconds / converter | 0 | ||
|
||
// update formatted time | ||
formatted += time < 10 ? `0${time}` : time | ||
if (converter !== 1) formatted += ':' | ||
|
||
// remove converted seconds from total seconds | ||
seconds -= time * converter | ||
} | ||
|
||
return formatted | ||
} | ||
|
||
export default hrt |
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,9 @@ | ||
/** | ||
* @file Test Setup - faker | ||
* @module tests/setup/faker | ||
* @see https://github.com/faker-js/faker | ||
*/ | ||
|
||
import { faker } from '@faker-js/faker' | ||
|
||
global.faker = faker |
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,6 @@ | ||
/** | ||
* @file Entry Point - Test Setup | ||
* @module tests/setup | ||
*/ | ||
|
||
import './faker' |
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,12 @@ | ||
/** | ||
* @file E2E Tests - api | ||
* @module vfile-location/tests/e2e/api | ||
*/ | ||
|
||
import * as testSubject from '../index' | ||
|
||
describe('e2e:vfile-location', () => { | ||
it('should expose public api', () => { | ||
expect(testSubject).to.have.keys(['Location']) | ||
}) | ||
}) |
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,130 @@ | ||
/** | ||
* @file Unit Tests - Location | ||
* @module vfile-location/tests/unit/Location | ||
*/ | ||
|
||
import type { Point } from '#src/interfaces' | ||
import type { Times } from '@flex-development/tutils' | ||
import type { Offset } from '@flex-development/unist-util-types' | ||
import { read } from 'to-vfile' | ||
import type { VFile } from 'vfile' | ||
import TestSubject from '../location' | ||
|
||
describe('unit:Location', () => { | ||
let fi: string | ||
let file: VFile | ||
let length: number | ||
let points: Times<6, Point> | ||
let pts: Times<5, Point> | ||
let start: Point | ||
|
||
beforeAll(async () => { | ||
file = await read('__fixtures__/hrt.ts') | ||
|
||
points = [ | ||
{ column: 1, line: 1, offset: 0 }, | ||
...(pts = [ | ||
start = { column: 1, line: 21, offset: 474 }, | ||
{ column: 13, line: 30, offset: 707 }, | ||
{ column: 42, line: 40, offset: 1014 }, | ||
{ column: 2, line: 47, offset: 1124 }, | ||
{ column: 1, line: 50, offset: length = String(file).length } | ||
]) | ||
] | ||
|
||
fi = String(file).slice(start.offset) | ||
}) | ||
|
||
describe('#offset', () => { | ||
let subject: TestSubject | ||
let sub: TestSubject | ||
|
||
beforeAll(() => { | ||
subject = new TestSubject(file) | ||
sub = new TestSubject(fi, start) | ||
}) | ||
|
||
it('should return -1 if point.column < 1', () => { | ||
expect(subject.offset({ column: 0, line: 1 })).to.eq(-1) | ||
}) | ||
|
||
it('should return -1 if point.column is not found', () => { | ||
expect(subject.offset({ column: 40, line: 2 })).to.eq(-1) | ||
}) | ||
|
||
it('should return -1 if point.line < 1', () => { | ||
expect(subject.offset({ column: 1, line: 0 })).to.eq(-1) | ||
}) | ||
|
||
it('should return -1 if point.line > total number of lines', () => { | ||
expect(subject.offset({ column: 1, line: 100 })).to.eq(-1) | ||
}) | ||
|
||
it('should return -1 if point is nil', () => { | ||
;[, null].forEach(offset => expect(subject.offset(offset)).to.eq(-1)) | ||
}) | ||
|
||
it('should return index of character in source file', () => { | ||
points.forEach(point => expect(subject.offset(point)).to.eq(point.offset)) | ||
}) | ||
|
||
it('should return index of character in source file (relative)', () => { | ||
pts.forEach(point => expect(sub.offset(point)).to.eq(point.offset)) | ||
}) | ||
}) | ||
|
||
describe('#point', () => { | ||
let subject: TestSubject | ||
let sub: TestSubject | ||
|
||
beforeAll(() => { | ||
subject = new TestSubject(file) | ||
sub = new TestSubject(fi, start) | ||
}) | ||
|
||
it('should return invalid point if offset < 0', () => { | ||
// Arrange | ||
const offset: Offset = faker.number.int({ | ||
max: -1, | ||
min: Number.NEGATIVE_INFINITY | ||
}) | ||
|
||
// Act + Expect | ||
expect(subject.point(offset)).to.eql({ column: -1, line: -1, offset }) | ||
}) | ||
|
||
it('should return invalid point if offset > source file length', () => { | ||
// Arrange | ||
const offset: Offset = faker.number.int({ min: length + 1 }) | ||
|
||
// Act + Expect | ||
expect(subject.point(offset)).to.eql({ column: -1, line: -1, offset }) | ||
}) | ||
|
||
it('should return invalid point if offset is a float', () => { | ||
// Arrange | ||
const offset: Offset = faker.number.float({ max: length, min: 0 }) | ||
|
||
// Act + Expect | ||
expect(subject.point(offset)).to.eql({ column: -1, line: -1, offset }) | ||
}) | ||
|
||
it('should return invalid point if offset is nil', () => { | ||
;[, null].forEach(offset => { | ||
expect(subject.point(offset)).to.eql({ | ||
column: -1, | ||
line: -1, | ||
offset: -1 | ||
}) | ||
}) | ||
}) | ||
|
||
it('should return place in source file', () => { | ||
points.forEach(point => expect(subject.point(point.offset)).to.eql(point)) | ||
}) | ||
|
||
it('should return place in source file (relative)', () => { | ||
pts.forEach(point => expect(sub.point(point.offset)).to.eql(point)) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.