Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move tuple parser test cases
- Loading branch information
Showing
4 changed files
with
122 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}) | ||
}) |