Skip to content

Commit f952c87

Browse files
committed
unit test cleanup
1 parent 22ea862 commit f952c87

File tree

4 files changed

+36
-47
lines changed

4 files changed

+36
-47
lines changed

packages/router-core/tests/new-process-route-tree.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { describe, expect, it } from 'vitest'
22
import { findRouteMatch, processRouteTree } from '../src/new-process-route-tree'
33
import type { AnyRoute, RouteMask } from '../src'
44

5-
// import { createLRUCache } from '../src/lru-cache'
6-
// import { processRouteTree as oldProcessRouteTree } from './old-process-route-tree'
7-
// import { matchPathname } from './old-path'
8-
// import big from '../src/Untitled-4.json'
9-
105
function makeTree(routes: Array<string>) {
116
return processRouteTree({
127
id: '__root__',

packages/router-core/tests/optional-path-params-clean.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { describe, expect, it } from 'vitest'
22
import { interpolatePath } from '../src/path'
33
import {
4+
SEGMENT_TYPE_OPTIONAL_PARAM,
5+
SEGMENT_TYPE_PATHNAME,
46
findSingleMatch,
57
parseSegment,
68
processRouteTree,
7-
SEGMENT_TYPE_OPTIONAL_PARAM,
8-
SEGMENT_TYPE_PATHNAME,
9-
type SegmentKind,
109
} from '../src/new-process-route-tree'
10+
import type { SegmentKind } from '../src/new-process-route-tree'
1111

1212
describe('Optional Path Parameters - Clean Comprehensive Tests', () => {
1313
describe('Optional Dynamic Parameters {-$param}', () => {
@@ -23,18 +23,18 @@ describe('Optional Path Parameters - Clean Comprehensive Tests', () => {
2323

2424
const parsePathname = (to: string | undefined) => {
2525
let cursor = 0
26-
const data = new Uint16Array(6)
26+
let data
2727
const path = to ?? ''
2828
const segments: Array<PathSegment> = []
2929
while (cursor < path.length) {
3030
const start = cursor
31-
parseSegment(path, start, data)
32-
const end = data[5]!
31+
data = parseSegment(path, start, data)
32+
const end = data[5]
3333
cursor = end + 1
34-
const type = data[0] as SegmentKind
35-
const value = path.substring(data[2]!, data[3])
34+
const type = data[0]
35+
const value = path.substring(data[2], data[3])
3636
const prefix = path.substring(start, data[1])
37-
const suffix = path.substring(data[4]!, end)
37+
const suffix = path.substring(data[4], end)
3838
const segment: PathSegment = {
3939
type,
4040
value,

packages/router-core/tests/optional-path-params.test.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
import { describe, expect, it } from 'vitest'
22
import { interpolatePath } from '../src/path'
33
import {
4-
findSingleMatch,
5-
parseSegment,
6-
processRouteTree,
74
SEGMENT_TYPE_OPTIONAL_PARAM,
85
SEGMENT_TYPE_PARAM,
96
SEGMENT_TYPE_PATHNAME,
107
SEGMENT_TYPE_WILDCARD,
11-
type SegmentKind,
8+
findSingleMatch,
9+
parseSegment,
10+
processRouteTree,
1211
} from '../src/new-process-route-tree'
12+
import type { SegmentKind } from '../src/new-process-route-tree'
1313

1414
describe('Optional Path Parameters', () => {
15+
type PathSegment = {
16+
type: SegmentKind
17+
value: string
18+
prefixSegment?: string
19+
suffixSegment?: string
20+
}
1521
type ParsePathnameTestScheme = Array<{
1622
name: string
1723
to: string | undefined
18-
expected: Array<any>
24+
expected: Array<PathSegment>
1925
}>
2026

2127
describe('parsePathname with optional params', () => {
22-
type PathSegment = {
23-
type: SegmentKind
24-
value: string
25-
prefixSegment?: string
26-
suffixSegment?: string
27-
// Indicates if there is a static segment after this required/optional param
28-
hasStaticAfter?: boolean
29-
}
30-
3128
const parsePathname = (to: string | undefined) => {
3229
let cursor = 0
33-
const data = new Uint16Array(6)
30+
let data
3431
const path = to ?? ''
3532
const segments: Array<PathSegment> = []
3633
while (cursor < path.length) {
3734
const start = cursor
38-
parseSegment(path, start, data)
39-
const end = data[5]!
35+
data = parseSegment(path, start, data)
36+
const end = data[5]
4037
cursor = end + 1
41-
const type = data[0] as SegmentKind
42-
const value = path.substring(data[2]!, data[3])
38+
const type = data[0]
39+
const value = path.substring(data[2], data[3])
4340
const prefix = path.substring(start, data[1])
44-
const suffix = path.substring(data[4]!, end)
41+
const suffix = path.substring(data[4], end)
4542
const segment: PathSegment = {
4643
type,
4744
value,

packages/router-core/tests/path.test.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import {
77
trimPathLeft,
88
} from '../src/path'
99
import {
10-
findSingleMatch,
11-
parseSegment,
12-
processRouteTree,
13-
SEGMENT_TYPE_OPTIONAL_PARAM,
1410
SEGMENT_TYPE_PARAM,
1511
SEGMENT_TYPE_PATHNAME,
1612
SEGMENT_TYPE_WILDCARD,
17-
type SegmentKind,
13+
findSingleMatch,
14+
parseSegment,
15+
processRouteTree,
1816
} from '../src/new-process-route-tree'
17+
import type { SegmentKind } from '../src/new-process-route-tree'
1918

2019
describe.each([{ basepath: '/' }, { basepath: '/app' }, { basepath: '/app/' }])(
2120
'removeTrailingSlash with basepath $basepath',
@@ -823,24 +822,22 @@ describe('parsePathname', () => {
823822
value: string
824823
prefixSegment?: string
825824
suffixSegment?: string
826-
// Indicates if there is a static segment after this required/optional param
827-
hasStaticAfter?: boolean
828825
}
829826

830827
const parsePathname = (to: string | undefined) => {
831828
let cursor = 0
832-
const data = new Uint16Array(6)
829+
let data
833830
const path = to ?? ''
834831
const segments: Array<PathSegment> = []
835832
while (cursor < path.length) {
836833
const start = cursor
837-
parseSegment(path, start, data)
838-
const end = data[5]!
834+
data = parseSegment(path, start, data)
835+
const end = data[5]
839836
cursor = end + 1
840-
const type = data[0] as SegmentKind
841-
const value = path.substring(data[2]!, data[3])
837+
const type = data[0]
838+
const value = path.substring(data[2], data[3])
842839
const prefix = path.substring(start, data[1])
843-
const suffix = path.substring(data[4]!, end)
840+
const suffix = path.substring(data[4], end)
844841
const segment: PathSegment = {
845842
type,
846843
value,

0 commit comments

Comments
 (0)