|
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({ |
| 9 | + JSON.stringify( |
| 10 | + parseCodeSamples({ |
11 | 11 | csharp: { |
12 | 12 | foo: { |
13 | 13 | default: ` |
@@ -42,48 +42,28 @@ var response = await client.CreateConfigAsync( |
42 | 42 | `, |
43 | 43 | }, |
44 | 44 | }, |
45 | | - } as unknown as SnippetSamples), |
| 45 | + } as unknown as CodeSamples), |
| 46 | + null, |
| 47 | + 2, |
46 | 48 | ), |
47 | 49 | ).toMatchInlineSnapshot(` |
48 | | - { |
| 50 | + "{ |
49 | 51 | "csharp": { |
50 | 52 | "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" }, |
70 | | - } |
71 | | - );", |
| 53 | + "default": "var 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);" |
72 | 54 | }, |
73 | 55 | "init": { |
74 | | - "default": "var client = new QuerySuggestionsClient( |
75 | | - new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
76 | | - );", |
77 | | - }, |
78 | | - }, |
79 | | - } |
| 56 | + "default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);" |
| 57 | + } |
| 58 | + } |
| 59 | + }" |
80 | 60 | `); |
81 | 61 | }); |
82 | 62 |
|
83 | 63 | it('parses a single line import', () => { |
84 | 64 | expect( |
85 | | - JSON.parse( |
86 | | - transformCodeSamplesToGuideMethods({ |
| 65 | + JSON.stringify( |
| 66 | + parseCodeSamples({ |
87 | 67 | csharp: { |
88 | 68 | foo: { |
89 | 69 | default: ` |
@@ -116,48 +96,30 @@ var response = await client.CreateConfigAsync( |
116 | 96 | `, |
117 | 97 | }, |
118 | 98 | }, |
119 | | - } as unknown as SnippetSamples), |
| 99 | + } as unknown as CodeSamples), |
| 100 | + null, |
| 101 | + 2, |
120 | 102 | ), |
121 | 103 | ).toMatchInlineSnapshot(` |
122 | | - { |
| 104 | + "{ |
123 | 105 | "csharp": { |
124 | 106 | "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" }, |
144 | | - } |
145 | | - );", |
| 107 | + "default": "var 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);" |
146 | 108 | }, |
147 | 109 | "init": { |
148 | | - "default": "var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"));", |
149 | | - }, |
150 | | - }, |
151 | | - } |
| 110 | + "default": "var client = new QuerySuggestionsClient(new Client(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\"));" |
| 111 | + } |
| 112 | + } |
| 113 | + }" |
152 | 114 | `); |
153 | 115 | }); |
154 | 116 | }); |
155 | 117 |
|
156 | 118 | describe('initialize', () => { |
157 | 119 | it("doesn't stop at `client`", () => { |
158 | 120 | expect( |
159 | | - JSON.parse( |
160 | | - transformCodeSamplesToGuideMethods({ |
| 121 | + JSON.stringify( |
| 122 | + parseCodeSamples({ |
161 | 123 | csharp: { |
162 | 124 | foo: { |
163 | 125 | default: ` |
@@ -192,41 +154,21 @@ var response = await client.CreateConfigAsync( |
192 | 154 | `, |
193 | 155 | }, |
194 | 156 | }, |
195 | | - } as unknown as SnippetSamples), |
| 157 | + } as unknown as CodeSamples), |
| 158 | + null, |
| 159 | + 2, |
196 | 160 | ), |
197 | 161 | ).toMatchInlineSnapshot(` |
198 | | - { |
| 162 | + "{ |
199 | 163 | "csharp": { |
200 | 164 | "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" }, |
220 | | - } |
221 | | - );", |
| 165 | + "default": "var 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);" |
222 | 166 | }, |
223 | 167 | "init": { |
224 | | - "default": "var client = new QuerySuggestionsClient( |
225 | | - new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
226 | | - );", |
227 | | - }, |
228 | | - }, |
229 | | - } |
| 168 | + "default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);" |
| 169 | + } |
| 170 | + } |
| 171 | + }" |
230 | 172 | `); |
231 | 173 | }); |
232 | 174 | }); |
0 commit comments