Skip to content

Commit

Permalink
test: add various new testcases, some skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Jun 2, 2023
1 parent 11f6ce5 commit a73df3f
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/findReplace/testcases/bugs_nestedForOfVarToConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const input = `
for (var x of [1, 2, 3]) {
for (var y of [4, 5, 6]) {
print(x, y)
}
}
`

export const find = `
for (var $a of $b) $body
`

export const replace = `
for (const $a of $b) $body
`

export const expectedReplace = `
for (const x of [1, 2, 3]) {
for (const y of [4, 5, 6]) {
print(x, y)
}
}
`

export const skip = true
25 changes: 25 additions & 0 deletions test/findReplace/testcases/classMatching.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const input = `
class Everything<A> extends Base<A, string> implements Foo<A>, Bar {
}
`

export const find = `
class $A<$$B> extends $C<$$D> implements $$E {
}
`

export const expectedFind = [
{
arrayCaptures: {
$$B: ['A'],
$$D: ['A', 'string'],
$$E: ['Foo<A>', 'Bar'],
},
captures: {
$A: 'Everything',
$C: 'Base',
},
node: 'class Everything<A> extends Base<A, string> implements Foo<A>, Bar {\n}',
},
]
34 changes: 34 additions & 0 deletions test/findReplace/testcases/findPromiseMethodCalls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const input = `
function foo(thing) {
thing.then(() => blah).finally(() => done)
return thing.then(
value => value * 2,
error => logged(error)
).catch(error => blah)
}
`

export const find = `
$Or($a.then($handleValue), $a.then($handleValue, $handleError), $a.catch($handleError), $a.finally($handleFinally))
`

export const expectedFind = [
{
arrayCaptures: {
$$args: ['error => blah'],
},
captures: {
$a: 'thing.then(\n value => value * 2,\n error => logged(error)\n )',
},
node: 'thing.then(\n value => value * 2,\n error => logged(error)\n ).catch(error => blah)',
},
{
arrayCaptures: {
$$args: ['value => value * 2', 'error => logged(error)'],
},
captures: {
$a: 'thing',
},
node: 'thing.then(\n value => value * 2,\n error => logged(error)\n )',
},
]
25 changes: 25 additions & 0 deletions test/findReplace/testcases/maybeSuperClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const input = `
class Cls {
}
`

export const find = `
class $A extends $Maybe<$C> {
}
`

export const expectedFind = [
{
arrayCaptures: {
$$B: ['A'],
},
captures: {
$A: 'Cls',
$C: 'Base',
},
node: 'class Cls<A> extends Base {\n}',
},
]

export const skip = true
25 changes: 25 additions & 0 deletions test/findReplace/testcases/maybeSuperTypeParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const input = `
class Cls<A> extends Base {
}
`

export const find = `
class $A<$$B> extends $C<$Maybe<$D>> {
}
`

export const expectedFind = [
{
arrayCaptures: {
$$B: ['A'],
},
captures: {
$A: 'Cls',
$C: 'Base',
},
node: 'class Cls<A> extends Base {\n}',
},
]

export const skip = true
15 changes: 15 additions & 0 deletions test/findReplace/testcases/rewriteNextAppImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const input = `
import App from 'next/app'
`

export const find = `
import $App from 'next/app'
`

export const replace = `
import { App as $App } from 'next'
`

export const expectedReplace = `
import { App } from 'next'
`
19 changes: 19 additions & 0 deletions test/findReplace/testcases/varToConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const input = `
var a = 1
var b: number = 2
var [c, d] = f
`

export const find = `
var $a = $b
`

export const replace = `
const $a = $b
`

export const expectedReplace = `
const a = 1
const b: number = 2
const [c, d] = f
`

0 comments on commit a73df3f

Please sign in to comment.