|
1 | 1 | import { describe, expect, it } from 'vitest';
|
2 | 2 |
|
3 |
| -import { transformCodeSamplesToGuideMethods } from '../snippets.js'; |
4 |
| -import { SnippetSamples } from '../types.js'; |
| 3 | +import { parseCodeSamples } from '../snippets.js'; |
| 4 | +import { CodeSamples } from '../types.js'; |
5 | 5 |
|
6 | 6 | describe('init', () => {
|
7 | 7 | it('parses a multi line import', () => {
|
8 | 8 | expect(
|
9 |
| - JSON.parse( |
10 |
| - transformCodeSamplesToGuideMethods({ |
11 |
| - csharp: { |
12 |
| - foo: { |
13 |
| - default: ` |
| 9 | + JSON.stringify( |
| 10 | + parseCodeSamples({ |
| 11 | + foo: { |
| 12 | + default: ` |
14 | 13 | // Initialize the client
|
15 | 14 | var client = new QuerySuggestionsClient(
|
16 | 15 | new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")
|
@@ -40,53 +39,26 @@ var response = await client.CreateConfigAsync(
|
40 | 39 | );
|
41 | 40 | // >LOG
|
42 | 41 | `,
|
43 |
| - }, |
44 | 42 | },
|
45 |
| - } as unknown as SnippetSamples), |
| 43 | + } as unknown as CodeSamples), |
| 44 | + null, |
| 45 | + 2, |
46 | 46 | ),
|
47 | 47 | ).toMatchInlineSnapshot(`
|
48 |
| - { |
49 |
| - "csharp": { |
50 |
| - "foo": { |
51 |
| - "default": "var response = await client.CreateConfigAsync( |
52 |
| - new ConfigurationWithIndex |
53 |
| - { |
54 |
| - IndexName = "<YOUR_INDEX_NAME>", |
55 |
| - SourceIndices = new List<SourceIndex> |
56 |
| - { |
57 |
| - new SourceIndex |
58 |
| - { |
59 |
| - IndexName = "<YOUR_INDEX_NAME>", |
60 |
| - Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
61 |
| - Generate = new List<List<string>> |
62 |
| - { |
63 |
| - new List<string> { "facetA", "facetB" }, |
64 |
| - new List<string> { "facetC" }, |
65 |
| - }, |
66 |
| - }, |
67 |
| - }, |
68 |
| - Languages = new Languages(new List<string> { "french" }), |
69 |
| - Exclude = new List<string> { "test" }, |
| 48 | + "{ |
| 49 | + "foo": { |
| 50 | + "default": "\\n // Initialize the client\\nvar client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n " |
70 | 51 | }
|
71 |
| - );", |
72 |
| - }, |
73 |
| - "init": { |
74 |
| - "default": "var client = new QuerySuggestionsClient( |
75 |
| - new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
76 |
| - );", |
77 |
| - }, |
78 |
| - }, |
79 |
| - } |
| 52 | + }" |
80 | 53 | `);
|
81 | 54 | });
|
82 | 55 |
|
83 | 56 | it('parses a single line import', () => {
|
84 | 57 | expect(
|
85 |
| - JSON.parse( |
86 |
| - transformCodeSamplesToGuideMethods({ |
87 |
| - csharp: { |
88 |
| - foo: { |
89 |
| - default: ` |
| 58 | + JSON.stringify( |
| 59 | + parseCodeSamples({ |
| 60 | + foo: { |
| 61 | + default: ` |
90 | 62 | // Initialize the client
|
91 | 63 | var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"));
|
92 | 64 |
|
@@ -114,53 +86,28 @@ var response = await client.CreateConfigAsync(
|
114 | 86 | );
|
115 | 87 | // >LOG
|
116 | 88 | `,
|
117 |
| - }, |
118 | 89 | },
|
119 |
| - } as unknown as SnippetSamples), |
| 90 | + } as unknown as CodeSamples), |
| 91 | + null, |
| 92 | + 2, |
120 | 93 | ),
|
121 | 94 | ).toMatchInlineSnapshot(`
|
122 |
| - { |
123 |
| - "csharp": { |
124 |
| - "foo": { |
125 |
| - "default": "var response = await client.CreateConfigAsync( |
126 |
| - new ConfigurationWithIndex |
127 |
| - { |
128 |
| - IndexName = "<YOUR_INDEX_NAME>", |
129 |
| - SourceIndices = new List<SourceIndex> |
130 |
| - { |
131 |
| - new SourceIndex |
132 |
| - { |
133 |
| - IndexName = "<YOUR_INDEX_NAME>", |
134 |
| - Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
135 |
| - Generate = new List<List<string>> |
136 |
| - { |
137 |
| - new List<string> { "facetA", "facetB" }, |
138 |
| - new List<string> { "facetC" }, |
139 |
| - }, |
140 |
| - }, |
141 |
| - }, |
142 |
| - Languages = new Languages(new List<string> { "french" }), |
143 |
| - Exclude = new List<string> { "test" }, |
| 95 | + "{ |
| 96 | + "foo": { |
| 97 | + "default": "\\n // Initialize the client\\nvar client = new QuerySuggestionsClient(new Client(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\"));\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n " |
144 | 98 | }
|
145 |
| - );", |
146 |
| - }, |
147 |
| - "init": { |
148 |
| - "default": "var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"));", |
149 |
| - }, |
150 |
| - }, |
151 |
| - } |
| 99 | + }" |
152 | 100 | `);
|
153 | 101 | });
|
154 | 102 | });
|
155 | 103 |
|
156 | 104 | describe('initialize', () => {
|
157 | 105 | it("doesn't stop at `client`", () => {
|
158 | 106 | expect(
|
159 |
| - JSON.parse( |
160 |
| - transformCodeSamplesToGuideMethods({ |
161 |
| - csharp: { |
162 |
| - foo: { |
163 |
| - default: ` |
| 107 | + JSON.stringify( |
| 108 | + parseCodeSamples({ |
| 109 | + foo: { |
| 110 | + default: ` |
164 | 111 | // Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ
|
165 | 112 | var client = new QuerySuggestionsClient(
|
166 | 113 | new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")
|
@@ -190,43 +137,17 @@ var response = await client.CreateConfigAsync(
|
190 | 137 | );
|
191 | 138 | // >LOG
|
192 | 139 | `,
|
193 |
| - }, |
194 | 140 | },
|
195 |
| - } as unknown as SnippetSamples), |
| 141 | + } as unknown as CodeSamples), |
| 142 | + null, |
| 143 | + 2, |
196 | 144 | ),
|
197 | 145 | ).toMatchInlineSnapshot(`
|
198 |
| - { |
199 |
| - "csharp": { |
200 |
| - "foo": { |
201 |
| - "default": "var response = await client.CreateConfigAsync( |
202 |
| - new ConfigurationWithIndex |
203 |
| - { |
204 |
| - IndexName = "<YOUR_INDEX_NAME>", |
205 |
| - SourceIndices = new List<SourceIndex> |
206 |
| - { |
207 |
| - new SourceIndex |
208 |
| - { |
209 |
| - IndexName = "<YOUR_INDEX_NAME>", |
210 |
| - Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
211 |
| - Generate = new List<List<string>> |
212 |
| - { |
213 |
| - new List<string> { "facetA", "facetB" }, |
214 |
| - new List<string> { "facetC" }, |
215 |
| - }, |
216 |
| - }, |
217 |
| - }, |
218 |
| - Languages = new Languages(new List<string> { "french" }), |
219 |
| - Exclude = new List<string> { "test" }, |
| 146 | + "{ |
| 147 | + "foo": { |
| 148 | + "default": "\\n // Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ\\nvar client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n " |
220 | 149 | }
|
221 |
| - );", |
222 |
| - }, |
223 |
| - "init": { |
224 |
| - "default": "var client = new QuerySuggestionsClient( |
225 |
| - new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
226 |
| - );", |
227 |
| - }, |
228 |
| - }, |
229 |
| - } |
| 150 | + }" |
230 | 151 | `);
|
231 | 152 | });
|
232 | 153 | });
|
0 commit comments