Skip to content

Commit

Permalink
refactor: move core features from @parser into @core
Browse files Browse the repository at this point in the history
  • Loading branch information
mindplay-dk authored and norskeld committed Aug 15, 2023
1 parent eabde0b commit 741bf0a
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/@helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export function testSuccess<T, P extends Parser<unknown>>(input: string, value:
should.matchState(actual, expected)
}

export const expectedCore = ['run', 'tryRun'] as const

export const expectedCombinators = [
'attempt',
'chainl',
Expand Down Expand Up @@ -104,9 +106,7 @@ export const expectedParsers = [
'oneOf',
'regexp',
'rest',
'run',
'string',
'tryRun',
'ustring',
'whitespace',
'whole'
Expand Down
33 changes: 33 additions & 0 deletions src/__tests__/core.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as p from '@parsers'
import { describe, expectTypeOf, it } from '@testing'
import { Result, Success } from '@types'

describe('run', () => {
const { run } = p

it('run should have correct inferred signature', () => {
expectTypeOf<typeof run>().returns.toMatchTypeOf<{ with: (input: string) => Result<unknown> }>()
expectTypeOf<typeof run<string>>().returns.toMatchTypeOf<{
with: (input: string) => Result<string>
}>()
expectTypeOf<typeof run<string>>().returns.not.toMatchTypeOf<{
with: (input: string) => Result<number>
}>()
})
})

describe('tryRun', () => {
const { tryRun } = p

it('tryRun should have correct inferred signature', () => {
expectTypeOf<typeof tryRun>().returns.toMatchTypeOf<{
with: (input: string) => Success<unknown>
}>()
expectTypeOf<typeof tryRun<string>>().returns.toMatchTypeOf<{
with: (input: string) => Success<string>
}>()
expectTypeOf<typeof tryRun<string>>().returns.not.toMatchTypeOf<{
with: (input: string) => Success<number>
}>()
})
})
8 changes: 8 additions & 0 deletions src/__tests__/core.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as exposed from '@core'
import { should, expectedCore, describe, it } from '@testing'

describe('parsers exports', () => {
it('should expose parsers', () => {
should.expose(exposed, ...expectedCore)
})
})
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as exposed from '@lib'
import { should, expectedParsers, expectedCombinators, describe, it } from '@testing'
import { should, expectedCore, expectedParsers, expectedCombinators, describe, it } from '@testing'

describe('index exports', () => {
it('should re-export core', () => {
should.expose(exposed, ...expectedCore)
})

it('should re-export combinators', () => {
should.expose(exposed, ...expectedCombinators)
})
Expand Down
32 changes: 1 addition & 31 deletions src/__tests__/parsers.spec-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as p from '@parsers'
import { describe, expectTypeOf, it } from '@testing'
import { Parser, SucceedingParser, Result, Success } from '@types'
import { Parser, SucceedingParser } from '@types'

type UnknownParser = Parser<unknown>
type NullParser = Parser<null>
Expand Down Expand Up @@ -154,20 +154,6 @@ describe('rest', () => {
})
})

describe('run', () => {
const { run } = p

it('run should have correct inferred signature', () => {
expectTypeOf<typeof run>().returns.toMatchTypeOf<{ with: (input: string) => Result<unknown> }>()
expectTypeOf<typeof run<string>>().returns.toMatchTypeOf<{
with: (input: string) => Result<string>
}>()
expectTypeOf<typeof run<string>>().returns.not.toMatchTypeOf<{
with: (input: string) => Result<number>
}>()
})
})

describe('string', () => {
const { string, ustring } = p

Expand All @@ -184,22 +170,6 @@ describe('string', () => {
})
})

describe('tryRun', () => {
const { tryRun } = p

it('tryRun should have correct inferred signature', () => {
expectTypeOf<typeof tryRun>().returns.toMatchTypeOf<{
with: (input: string) => Success<unknown>
}>()
expectTypeOf<typeof tryRun<string>>().returns.toMatchTypeOf<{
with: (input: string) => Success<string>
}>()
expectTypeOf<typeof tryRun<string>>().returns.not.toMatchTypeOf<{
with: (input: string) => Success<number>
}>()
})
})

describe('whitespace', () => {
const { whitespace } = p

Expand Down
2 changes: 2 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@core/run'
export * from '@core/tryRun'
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/parsers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@core' // TODO keep this here for BC? or move to a dedicated core export?
export * from '@parsers/any'
export * from '@parsers/defer'
export * from '@parsers/eof'
Expand All @@ -9,7 +10,5 @@ export * from '@parsers/numbers'
export * from '@parsers/oneOf'
export * from '@parsers/regexp'
export * from '@parsers/rest'
export * from '@parsers/run'
export * from '@parsers/tryRun'
export * from '@parsers/string'
export * from '@parsers/whitespace'
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"paths": {
"@combinators": ["src/combinators"],
"@combinators/*": ["src/combinators/*"],
"@core": ["src/core"],
"@core/*": ["src/core/*"],
"@lib": ["src"],
"@lib/*": ["src/*"],
"@parsers": ["src/parsers"],
Expand Down

0 comments on commit 741bf0a

Please sign in to comment.