-
-
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 <[email protected]>
- Loading branch information
1 parent
2a803f4
commit 7fca10d
Showing
20 changed files
with
453 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,4 @@ ignore: | |
profiling: | ||
critical_files_paths: | ||
- src/character.reader.ts | ||
- src/code.reader.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
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 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`functional:CodeReader > iterator > should iterate over all code points 1`] = ` | ||
[ | ||
128525, | ||
128077, | ||
128640, | ||
10055, | ||
65039, | ||
10, | ||
] | ||
`; |
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,114 @@ | ||
/** | ||
* @file Functional Tests - CodeReader | ||
* @module vfile-reader/tests/functional/CodeReader | ||
*/ | ||
|
||
import type { Code } from '#src/types' | ||
import type { MockInstance } from '#tests/interfaces' | ||
import { read } from 'to-vfile' | ||
import type { VFile } from 'vfile' | ||
import Reader from '../abstract.reader' | ||
import TestSubject from '../code.reader' | ||
|
||
describe('functional:CodeReader', () => { | ||
let file: VFile | ||
let subject: TestSubject | ||
|
||
beforeAll(async () => { | ||
file = await read('__fixtures__/emojis.txt') | ||
subject = new TestSubject(file) | ||
}) | ||
|
||
describe('#peek', () => { | ||
let spy: MockInstance<Reader['peek']> | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(Reader.prototype, 'peek') | ||
}) | ||
|
||
it('should call Reader.prototype.peek', () => { | ||
// Arrange | ||
const k: number = 3 | ||
|
||
// Act | ||
subject.peek(k) | ||
|
||
// Expect | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy).toHaveBeenCalledWith(k) | ||
}) | ||
}) | ||
|
||
describe('#read', () => { | ||
let spy: MockInstance<Reader['read']> | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(Reader.prototype, 'read') | ||
}) | ||
|
||
it('should call Reader.prototype.read', () => { | ||
// Arrange | ||
const k: number = 0 | ||
|
||
// Act | ||
subject.read(k) | ||
|
||
// Expect | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy).toHaveBeenCalledWith(k) | ||
}) | ||
}) | ||
|
||
describe('#slice', () => { | ||
let spy: MockInstance<Reader['slice']> | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(Reader.prototype, 'slice') | ||
}) | ||
|
||
it('should call Reader.prototype.slice', () => { | ||
// Arrange | ||
const m: number = 1 | ||
|
||
// Act | ||
subject.slice(m) | ||
|
||
// Expect | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy).toHaveBeenCalledWith(m) | ||
}) | ||
}) | ||
|
||
describe('#stringify', () => { | ||
let spy: MockInstance<(typeof String)['fromCodePoint']> | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(String, 'fromCodePoint') | ||
}) | ||
|
||
it('should call String.fromCodePoint', () => { | ||
// Arrange | ||
const codes: Code[] = [subject.peek(0), subject.peek(1), subject.peek(13)] | ||
|
||
// Act | ||
subject.stringify(...codes) | ||
|
||
// Expect | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy).toHaveBeenCalledWith(...codes) | ||
}) | ||
}) | ||
|
||
describe('iterator', () => { | ||
it('should iterate over all code points', () => { | ||
// Arrange | ||
const codes: Code[] = [] | ||
|
||
// Act | ||
for (const code of subject) codes.push(code) | ||
|
||
// Expect | ||
expect(codes).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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,14 @@ | ||
/** | ||
* @file Type Tests - CodeReader | ||
* @module vfile-reader/tests/unit-d/CodeReader | ||
*/ | ||
|
||
import type { Code } from '#src/types' | ||
import type Reader from '../abstract.reader' | ||
import type TestSubject from '../code.reader' | ||
|
||
describe('unit-d:CodeReader', () => { | ||
it('should extend Reader<Code>', () => { | ||
expectTypeOf<TestSubject>().toMatchTypeOf<Reader<Code>>() | ||
}) | ||
}) |
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,32 @@ | ||
/** | ||
* @file Unit Tests - CodeReader | ||
* @module vfile-reader/tests/unit/CodeReader | ||
*/ | ||
|
||
import type { Offset } from '@flex-development/unist-util-types' | ||
import { read } from 'to-vfile' | ||
import TestSubject from '../code.reader' | ||
|
||
describe('unit:CodeReader', () => { | ||
let index: Offset | ||
let subject: TestSubject | ||
|
||
beforeAll(async () => { | ||
subject = new TestSubject(await read('__fixtures__/emojis.txt')) | ||
index = subject.index | ||
}) | ||
|
||
describe('#output', () => { | ||
it('should return current code point without changing position', () => { | ||
expect(subject.output).to.equal(subject.peek(0)) | ||
expect(subject.index).to.eq(index) | ||
}) | ||
}) | ||
|
||
describe('#previous', () => { | ||
it('should return previous code point without changing position', () => { | ||
expect(subject.previous).to.eq(subject.peek(-1)) | ||
expect(subject.index).to.eq(index) | ||
}) | ||
}) | ||
}) |
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.