|
| 1 | +import sgf from "sabaki__sgf"; |
| 2 | + |
| 3 | +const genIdString = ((id) => () => "id_" + (id++))(0); |
| 4 | + |
| 5 | +// =============== |
| 6 | +// Basic Functions |
| 7 | +// =============== |
| 8 | + |
| 9 | +// $ExpectType Generator<SGFToken, void, any> || Generator<SGFToken, void, unknown> |
| 10 | +sgf.tokenizeIter("foo"); |
| 11 | + |
| 12 | +// $ExpectType SGFToken[] |
| 13 | +const tokens = sgf.tokenize("foo"); |
| 14 | + |
| 15 | +// $ExpectType Generator<SGFToken, void, any> || Generator<SGFToken, void, unknown> |
| 16 | +sgf.tokenizeBufferIter(Buffer.from("foo")); |
| 17 | + |
| 18 | +// $ExpectType SGFToken[] |
| 19 | +sgf.tokenizeBuffer(Buffer.from("foo")); |
| 20 | + |
| 21 | +// $ExpectType NodeObject<number>[] |
| 22 | +const nodes1 = sgf.parseTokens(tokens); |
| 23 | +// $ExpectType number |
| 24 | +nodes1[0].id; |
| 25 | +// $ExpectType Partial<Record<Property, string[]>> |
| 26 | +nodes1[0].data; |
| 27 | +// $ExpectType number | null |
| 28 | +nodes1[0].parentId; |
| 29 | +// $ExpectType NodeObject<number>[] |
| 30 | +nodes1[0].children; |
| 31 | + |
| 32 | +// $ExpectType NodeObject<string>[] |
| 33 | +const nodes2 = sgf.parseTokens(tokens, { |
| 34 | + getId: genIdString, |
| 35 | +}); |
| 36 | +// $ExpectType string |
| 37 | +nodes2[0].id; |
| 38 | +// $ExpectType Partial<Record<Property, string[]>> |
| 39 | +nodes2[0].data; |
| 40 | +// $ExpectType string | null |
| 41 | +nodes2[0].parentId; |
| 42 | +// $ExpectType NodeObject<string>[] |
| 43 | +nodes2[0].children; |
| 44 | + |
| 45 | +// $ExpectType NodeObject<number>[] |
| 46 | +sgf.parse("foo"); |
| 47 | + |
| 48 | +// $ExpectType NodeObject<string>[] |
| 49 | +sgf.parse("foo", { |
| 50 | + getId: genIdString, |
| 51 | +}); |
| 52 | + |
| 53 | +// $ExpectType NodeObject<number>[] |
| 54 | +sgf.parseBuffer(Buffer.from("foo")); |
| 55 | + |
| 56 | +// $ExpectType NodeObject<string>[] |
| 57 | +sgf.parseBuffer(Buffer.from("foo"), { |
| 58 | + getId: genIdString, |
| 59 | +}); |
| 60 | + |
| 61 | +// $ExpectType NodeObject<number>[] |
| 62 | +sgf.parseFile("foo"); |
| 63 | + |
| 64 | +// $ExpectType NodeObject<string>[] |
| 65 | +sgf.parseFile("foo", { |
| 66 | + getId: genIdString, |
| 67 | +}); |
| 68 | + |
| 69 | +// $ExpectType string |
| 70 | +sgf.stringify(nodes1); |
| 71 | + |
| 72 | +// ================ |
| 73 | +// Helper Functions |
| 74 | +// ================ |
| 75 | + |
| 76 | +// $ExpectType string |
| 77 | +const escaped = sgf.escapeString("foo"); |
| 78 | + |
| 79 | +// $ExpectType string |
| 80 | +sgf.unescapeString(escaped); |
| 81 | + |
| 82 | +// $ExpectType Vertex |
| 83 | +const vertex = sgf.parseVertex("foo"); |
| 84 | + |
| 85 | +// $ExpectType string |
| 86 | +sgf.stringifyVertex(vertex); |
| 87 | + |
| 88 | +// $ExpectType Vertex[] |
| 89 | +sgf.parseCompressedVertices("foo"); |
| 90 | + |
| 91 | +// $ExpectType Dates[] | null |
| 92 | +const dates = sgf.parseDates("foo"); |
| 93 | + |
| 94 | +// $ExpectType string |
| 95 | +sgf.stringifyDates(dates ?? []); |
0 commit comments