Skip to content

Commit

Permalink
refactor: move tuple parser test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mistlog committed Feb 27, 2021
1 parent e25837e commit 8e0ecb2
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 116 deletions.
88 changes: 0 additions & 88 deletions test/__snapshots__/parser.test.tsx.snap
Expand Up @@ -682,94 +682,6 @@ Object {
}
`;

exports[`TupleType 1`] = `
Object {
"items": Array [
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
],
"kind": "TupleType",
}
`;

exports[`TupleType: readonly 1`] = `
Object {
"kind": "ReadonlyTuple",
"operand": Object {
"items": Array [
Object {
"kind": "StringType",
"value": "string",
},
Object {
"kind": "NumberType",
"value": "number",
},
],
"kind": "TupleType",
},
}
`;

exports[`TupleType: rest 1`] = `
Object {
"items": Array [
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "RestType",
"param": Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
},
],
"kind": "TupleType",
}
`;

exports[`TupleType: with infer 1`] = `
Object {
"items": Array [
Object {
"kind": "InferType",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "InferType",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
],
"kind": "TupleType",
}
`;

exports[`TypeArrowFunctionExpression 1`] = `
Object {
"body": Object {
Expand Down
28 changes: 0 additions & 28 deletions test/parser.test.tsx
Expand Up @@ -399,34 +399,6 @@ test("TypeCallExpression: empty", () => {
expect(ast).toMatchSnapshot();
})

test("TupleType", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[protocol, rest]`);
saveAST(ast, "TupleType.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: rest", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[protocol, ...rest]`);
saveAST(ast, "TupleType-Rest.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: readonly", () => {
const parser = ReactPeg.render(<OperatorType />);
const ast = parser.parse(`readonly [string, number]`);
saveAST(ast, "TupleType-Readonly.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: with infer", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[infer protocol, infer rest]`);
saveAST(ast, "TupleType-Infer.json");
expect(ast).toMatchSnapshot();
})

test("TypeFile", () => {
const parser = ReactPeg.render(<TypeFile />);
const ast = parser.parse(`
Expand Down
89 changes: 89 additions & 0 deletions test/parser/__snapshots__/tuple.test.tsx.snap
@@ -0,0 +1,89 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parser: tuple TupleType 1`] = `
Object {
"items": Array [
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
],
"kind": "TupleType",
}
`;

exports[`parser: tuple TupleType: readonly 1`] = `
Object {
"kind": "ReadonlyTuple",
"operand": Object {
"items": Array [
Object {
"kind": "StringType",
"value": "string",
},
Object {
"kind": "NumberType",
"value": "number",
},
],
"kind": "TupleType",
},
}
`;

exports[`parser: tuple TupleType: rest 1`] = `
Object {
"items": Array [
Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "RestType",
"param": Object {
"kind": "TypeReference",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
},
],
"kind": "TupleType",
}
`;

exports[`parser: tuple TupleType: with infer 1`] = `
Object {
"items": Array [
Object {
"kind": "InferType",
"typeName": Object {
"kind": "Identifier",
"name": "protocol",
},
},
Object {
"kind": "InferType",
"typeName": Object {
"kind": "Identifier",
"name": "rest",
},
},
],
"kind": "TupleType",
}
`;
33 changes: 33 additions & 0 deletions test/parser/tuple.test.tsx
@@ -0,0 +1,33 @@
import { ReactPeg } from "react-peg";
import { TupleType, OperatorType } from "../../src";
import { saveAST } from "../common";

describe("parser: tuple", () => {
test("TupleType", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[protocol, rest]`);
saveAST(ast, "TupleType.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: rest", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[protocol, ...rest]`);
saveAST(ast, "TupleType-Rest.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: readonly", () => {
const parser = ReactPeg.render(<OperatorType />);
const ast = parser.parse(`readonly [string, number]`);
saveAST(ast, "TupleType-Readonly.json");
expect(ast).toMatchSnapshot();
})

test("TupleType: with infer", () => {
const parser = ReactPeg.render(<TupleType />);
const ast = parser.parse(`[infer protocol, infer rest]`);
saveAST(ast, "TupleType-Infer.json");
expect(ast).toMatchSnapshot();
})
})

0 comments on commit 8e0ecb2

Please sign in to comment.