Skip to content

Commit

Permalink
[autofix][insert-type] add passing annotate exports tests
Browse files Browse the repository at this point in the history
Summary: This commit adds all the tests from annotate exports that can be performed with insert-type.

Reviewed By: panagosg7

Differential Revision: D16035039

fbshipit-source-id: 016b5723c0f275148085d2c9ebc0e042767297e2
  • Loading branch information
Andre Kuhlenschmidt authored and facebook-github-bot committed Jul 4, 2019
1 parent de679c5 commit f796b60
Show file tree
Hide file tree
Showing 98 changed files with 1,114 additions and 62 deletions.
13 changes: 13 additions & 0 deletions tests/autofix-boolean-literals/.flowconfig
@@ -0,0 +1,13 @@
[ignore]

[include]

[libs]

[lints]

[options]
experimental.types_first=true
experimental.well_formed_exports=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-boolean-literals/.testconfig
@@ -0,0 +1 @@
shell: test.sh
5 changes: 5 additions & 0 deletions tests/autofix-boolean-literals/a.js
@@ -0,0 +1,5 @@
// @flow

declare var cond: boolean;

module.exports = () => (cond ? true : false);
8 changes: 8 additions & 0 deletions tests/autofix-boolean-literals/autofix-boolean-literals.exp
@@ -0,0 +1,8 @@
> cat a.js
// @flow

declare var cond: boolean;

module.exports = (): boolean => (cond ? true : false);
> flow status
No errors!
10 changes: 10 additions & 0 deletions tests/autofix-boolean-literals/test.sh
@@ -0,0 +1,10 @@
#!/bin/bash

assert_ok "$FLOW" autofix insert-type --in-place a.js 5 20
assert_ok "$FLOW" force-recheck a.js

echo "> cat a.js"
cat a.js

echo "> flow status"
assert_ok "$FLOW" status
13 changes: 13 additions & 0 deletions tests/autofix-class/.flowconfig
@@ -0,0 +1,13 @@
[ignore]

[include]

[libs]

[lints]

[options]
experimental.types_first=true
experimental.well_formed_exports=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-class/.testconfig
@@ -0,0 +1 @@
shell: test.sh
8 changes: 8 additions & 0 deletions tests/autofix-class/a.js
@@ -0,0 +1,8 @@
// @flow

class C {}
// XYZXYZ
export default class {
array = [];
num = 1;
}
31 changes: 31 additions & 0 deletions tests/autofix-class/autofix-class.exp
@@ -0,0 +1,31 @@
> cat a.js
// @flow

class C {}
// XYZXYZ
export default class {
array: Array<empty> = [];
num: number = 1;
}
> cat b.js
// @flow

class C {
m(): number {
return 1;
}
}
module.exports = C;
> cat c.js
// @flow

class A {
f: ((x: string) => string) = (x: string) => x;
}

module.exports = {
a: A,
b: (x: string): string => x,
};
> flow status
No errors!
8 changes: 8 additions & 0 deletions tests/autofix-class/b.js
@@ -0,0 +1,8 @@
// @flow

class C {
m() {
return 1;
}
}
module.exports = C;
10 changes: 10 additions & 0 deletions tests/autofix-class/c.js
@@ -0,0 +1,10 @@
// @flow

class A {
f = (x: string) => x;
}

module.exports = {
a: A,
b: (x: string) => x,
};
19 changes: 19 additions & 0 deletions tests/autofix-class/test.sh
@@ -0,0 +1,19 @@
#!/bin/bash

assert_ok "$FLOW" autofix insert-type --in-place a.js 6 3 6 14
assert_ok "$FLOW" autofix insert-type --in-place a.js 7 3 7 11
echo "> cat a.js"
cat a.js

assert_ok "$FLOW" autofix insert-type --in-place b.js 4 6
echo "> cat b.js"
cat b.js

assert_ok "$FLOW" autofix insert-type --in-place c.js 4 3 4 24
assert_ok "$FLOW" autofix insert-type --in-place c.js 9 17
echo "> cat c.js"
cat c.js

assert_ok "$FLOW" force-recheck {a,b,c}.js
echo "> flow status"
assert_ok "$FLOW" status
13 changes: 13 additions & 0 deletions tests/autofix-dotFlow/.flowconfig
@@ -0,0 +1,13 @@
[ignore]

[include]

[libs]

[lints]

[options]
experimental.types_first=true
experimental.well_formed_exports=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-dotFlow/.testconfig
@@ -0,0 +1 @@
shell: test.sh
3 changes: 3 additions & 0 deletions tests/autofix-dotFlow/a.js
@@ -0,0 +1,3 @@
// @flow

module.exports = () => 1;
3 changes: 3 additions & 0 deletions tests/autofix-dotFlow/a.js.flow
@@ -0,0 +1,3 @@
// @flow

module.exports = () => 1;
10 changes: 10 additions & 0 deletions tests/autofix-dotFlow/autofix-dotFlow.exp
@@ -0,0 +1,10 @@
> cat a.js
// @flow

module.exports = (): number => 1;
> cat a.js.flow
// @flow

module.exports = (): number => 1;
> flow status
No errors!
Empty file.
13 changes: 13 additions & 0 deletions tests/autofix-dotFlow/test.sh
@@ -0,0 +1,13 @@
#!/bin/bash

assert_ok "$FLOW" autofix insert-type --in-place a.js 3 20
echo "> cat a.js"
cat a.js

assert_ok "$FLOW" autofix insert-type --in-place a.js.flow 3 20
echo "> cat a.js.flow"
cat a.js.flow

assert_ok "$FLOW" force-recheck a.js a.js.flow
echo "> flow status"
assert_ok "$FLOW" status
16 changes: 16 additions & 0 deletions tests/autofix-fbt/.flowconfig
@@ -0,0 +1,16 @@
[ignore]

[include]

[libs]
lib

[lints]

[options]
no_flowlib=false
facebook.fbt=FbtElement
experimental.well_formed_exports=true
experimental.types_first=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-fbt/.testconfig
@@ -0,0 +1 @@
shell: test.sh
6 changes: 6 additions & 0 deletions tests/autofix-fbt/a.js
@@ -0,0 +1,6 @@
// @flow

const React = require("react");

const foo = () => <fbt />;
module.exports = foo();
9 changes: 9 additions & 0 deletions tests/autofix-fbt/autofix-fbt.exp
@@ -0,0 +1,9 @@
> cat a.js
// @flow

const React = require("react");

const foo = () => <fbt />;
module.exports = (foo(): FbtResultBase);
> flow status
No errors!
3 changes: 3 additions & 0 deletions tests/autofix-fbt/lib/fbt.js
@@ -0,0 +1,3 @@
// @flow
declare type FbtElement = FbtResultBase;
declare class FbtResultBase {}
9 changes: 9 additions & 0 deletions tests/autofix-fbt/test.sh
@@ -0,0 +1,9 @@
#!/bin/bash

assert_ok "$FLOW" autofix insert-type --in-place a.js 6 18 6 23
assert_ok "$FLOW" force-recheck a.js

echo "> cat a.js"
cat a.js
echo "> flow status"
assert_ok "$FLOW" status
13 changes: 13 additions & 0 deletions tests/autofix-function/.flowconfig
@@ -0,0 +1,13 @@
[ignore]

[include]

[libs]

[lints]

[options]
experimental.types_first=true
experimental.well_formed_exports=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-function/.testconfig
@@ -0,0 +1 @@
shell: test.sh
5 changes: 5 additions & 0 deletions tests/autofix-function/a.js
@@ -0,0 +1,5 @@
// @flow

export function f() {
return 1;
}
14 changes: 14 additions & 0 deletions tests/autofix-function/autofix-function.exp
@@ -0,0 +1,14 @@
> cat a.js
// @flow

export function f(): number {
return 1;
}
> cat b.js
// @flow

const functionArray = (): Array<(x: number) => number> => ([(x: number) => x])

module.exports = functionArray;
> flow status
No errors!
5 changes: 5 additions & 0 deletions tests/autofix-function/b.js
@@ -0,0 +1,5 @@
// @flow

const functionArray = () => ([(x: number) => x])

module.exports = functionArray;
14 changes: 14 additions & 0 deletions tests/autofix-function/test.sh
@@ -0,0 +1,14 @@
#!/bin/bash

assert_ok "$FLOW" autofix insert-type --in-place a.js 3 20
assert_ok "$FLOW" force-recheck a.js
echo "> cat a.js"
cat a.js

assert_ok "$FLOW" autofix insert-type --in-place b.js 3 25
assert_ok "$FLOW" force-recheck b.js
echo "> cat b.js"
cat b.js

echo "> flow status"
assert_ok "$FLOW" status
14 changes: 14 additions & 0 deletions tests/autofix-hard-coded-fixes/.flowconfig
@@ -0,0 +1,14 @@
[ignore]

[include]

[libs]

[lints]

[options]
no_flowlib=false
experimental.types_first=true
experimental.well_formed_exports=true

[strict]
1 change: 1 addition & 0 deletions tests/autofix-hard-coded-fixes/.testconfig
@@ -0,0 +1 @@
shell: test.sh
17 changes: 17 additions & 0 deletions tests/autofix-hard-coded-fixes/any-in-union.js
@@ -0,0 +1,17 @@
// @flow

const React = require('react');

declare var x1: { f: number } | any;
declare var x2: any | { f: number };
declare var x3: any | { f: number } | { node: React.Node };
declare var x4: { f: number } | any | { node: React.Node };
declare var x5: { f: number } | { node: React.Node } | any;

module.exports = [
() => x1,
() => x2,
() => x3,
() => x4,
() => x5,
];
4 changes: 4 additions & 0 deletions tests/autofix-hard-coded-fixes/any-to-flowfixme-no-strict.js
@@ -0,0 +1,4 @@
// @flow

declare var x1: { f: number } | any;
module.exports = () => x1;
@@ -0,0 +1,4 @@
// @flow strict-local

declare var x1: { f: number } | any;
module.exports = () => x1;
4 changes: 4 additions & 0 deletions tests/autofix-hard-coded-fixes/any-to-flowfixme-strict.js
@@ -0,0 +1,4 @@
// @flow strict

declare var x1: { f: number } | any;
module.exports = () => x1;

0 comments on commit f796b60

Please sign in to comment.