Skip to content

Commit

Permalink
Update some tests (prettier#13176)
Browse files Browse the repository at this point in the history
* Revert "Disable a test (prettier#13159)"

This reverts commit 26cf77a.

* remove a test case
  • Loading branch information
liuxingbaoyu authored and medikoo committed Jan 16, 2024
1 parent aa46a07 commit 931aa69
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 19 deletions.
2 changes: 0 additions & 2 deletions tests/config/format-test.js
Expand Up @@ -55,8 +55,6 @@ const espreeDisabledTests = new Set(
[
// These tests only work for `babel`
"comments-closure-typecast",
// Unknown reason https://github.com/babel/babel/pull/14779#discussion_r928137651
"strings",
].map((directory) => path.join(__dirname, "../format/js", directory))
);
const acornDisabledTests = espreeDisabledTests;
Expand Down
44 changes: 44 additions & 0 deletions tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -65,6 +65,50 @@ const loremIpsumFooBazBar2 =
================================================================================
`;

exports[`non-octal-eight-and-nine.js [acorn] format 1`] = `
"Invalid escape sequence (3:3)
1 | // https://github.com/babel/babel/pull/11852
2 |
> 3 | "\\8","\\9";
| ^
4 | () => {
5 | "use strict";
6 | "\\8", "\\9";"
`;
exports[`non-octal-eight-and-nine.js [espree] format 1`] = `
"Invalid escape sequence (3:3)
1 | // https://github.com/babel/babel/pull/11852
2 |
> 3 | "\\8","\\9";
| ^
4 | () => {
5 | "use strict";
6 | "\\8", "\\9";"
`;
exports[`non-octal-eight-and-nine.js - {"trailingComma":"all"} [acorn] format 1`] = `
"Invalid escape sequence (3:3)
1 | // https://github.com/babel/babel/pull/11852
2 |
> 3 | "\\8","\\9";
| ^
4 | () => {
5 | "use strict";
6 | "\\8", "\\9";"
`;
exports[`non-octal-eight-and-nine.js - {"trailingComma":"all"} [espree] format 1`] = `
"Invalid escape sequence (3:3)
1 | // https://github.com/babel/babel/pull/11852
2 |
> 3 | "\\8","\\9";
| ^
4 | () => {
5 | "use strict";
6 | "\\8", "\\9";"
`;
exports[`non-octal-eight-and-nine.js - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
Expand Down
15 changes: 13 additions & 2 deletions tests/format/js/strings/jsfmt.spec.js
@@ -1,2 +1,13 @@
run_spec(import.meta, ["babel", "flow"]);
run_spec(import.meta, ["babel", "flow"], { trailingComma: "all" });
run_spec(import.meta, ["babel", "flow"], {
errors: {
acorn: ["non-octal-eight-and-nine.js"],
espree: ["non-octal-eight-and-nine.js"],
},
});
run_spec(import.meta, ["babel", "flow"], {
trailingComma: "all",
errors: {
acorn: ["non-octal-eight-and-nine.js"],
espree: ["non-octal-eight-and-nine.js"],
},
});
Expand Up @@ -114,9 +114,6 @@ parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
// valid JSX
<in T>() => {}</in>;

type Covariant<out T> = {
x: T;
}
Expand Down Expand Up @@ -180,12 +177,9 @@ declare class StateNode<TContext, in out TEvent extends { type: string }> {
}

=====================================output=====================================
// valid JSX
<in T>() => {}</in>;

type Covariant<out T> = { x: T };
type Contravariant<in T> = { f: (x: T) => void };
type Invariant<in out T> = { f: (x: T) => T };
type Covariant<out T> = { x: T; };
type Contravariant<in T> = { f: (x: T) => void; };
type Invariant<in out T> = { f: (x: T) => T; };
type T10<out T> = T;
type T11<in T> = keyof T;
type T12<out T, out K extends keyof T> = T[K];
Expand Down Expand Up @@ -231,3 +225,111 @@ exports[`with-jsx.tsx [typescript] format 1`] = `
4 | type Covariant<out T> = {
5 | x: T;"
`;

exports[`with-jsx.tsx format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type Covariant<out T> = {
x: T;
}
type Contravariant<in T> = {
f: (x: T) => void;
}
type Invariant<in out T> = {
f: (x: T) => T;
}
type T10<out T> = T;
type T11<in T> = keyof T;
type T12<out T, out K extends keyof T> = T[K];
type T13<in out T> = T[keyof T];

type Covariant1<in T> = {
x: T;
}

type Contravariant1<out T> = keyof T;

type Contravariant2<out T> = {
f: (x: T) => void;
}

type Invariant1<in T> = {
f: (x: T) => T;
}

type Invariant2<out T> = {
f: (x: T) => T;
}
type Foo1<in T> = {
x: T;
f: FooFn1<T>;
}

type Foo2<out T> = {
x: T;
f: FooFn2<T>;
}

type Foo3<in out T> = {
x: T;
f: FooFn3<T>;
}

type T21<in out T> = T;

interface Baz<out T> {}
interface Baz<in T> {}

interface Parent<out A> {
child: Child<A> | null;
parent: Parent<A> | null;
}

declare class StateNode<TContext, in out TEvent extends { type: string }> {
_storedEvent: TEvent;
_action: ActionObject<TEvent>;
_state: StateNode<TContext, any>;
}

=====================================output=====================================
type Covariant<out T> = { x: T };
type Contravariant<in T> = { f: (x: T) => void };
type Invariant<in out T> = { f: (x: T) => T };
type T10<out T> = T;
type T11<in T> = keyof T;
type T12<out T, out K extends keyof T> = T[K];
type T13<in out T> = T[keyof T];

type Covariant1<in T> = { x: T };

type Contravariant1<out T> = keyof T;

type Contravariant2<out T> = { f: (x: T) => void };

type Invariant1<in T> = { f: (x: T) => T };

type Invariant2<out T> = { f: (x: T) => T };
type Foo1<in T> = { x: T; f: FooFn1<T> };

type Foo2<out T> = { x: T; f: FooFn2<T> };

type Foo3<in out T> = { x: T; f: FooFn3<T> };

type T21<in out T> = T;

interface Baz<out T> {}
interface Baz<in T> {}

interface Parent<out A> { child: Child<A> | null; parent: Parent<A> | null }

declare class StateNode<TContext, in out TEvent extends { type: string }> {
_storedEvent: TEvent;
_action: ActionObject<TEvent>;
_state: StateNode<TContext, any>;
}

================================================================================
`;
4 changes: 1 addition & 3 deletions tests/format/typescript/optional-variance/jsfmt.spec.js
@@ -1,3 +1 @@
run_spec(import.meta, ["typescript"], {
errors: { typescript: ["with-jsx.tsx"] },
});
run_spec(import.meta, ["typescript"]);
3 changes: 0 additions & 3 deletions tests/format/typescript/optional-variance/with-jsx.tsx
@@ -1,6 +1,3 @@
// valid JSX
<in T>() => {}</in>;

type Covariant<out T> = {
x: T;
}
Expand Down

0 comments on commit 931aa69

Please sign in to comment.