MCPcopy Index your code
hub / github.com/github/gh-aw / TestWriteJavaScriptToYAML

Function TestWriteJavaScriptToYAML

pkg/workflow/js_test.go:156–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func TestWriteJavaScriptToYAML(t *testing.T) {
157 tests := []struct {
158 name string
159 script string
160 expected string
161 }{
162 {
163 name: "empty string",
164 script: "",
165 expected: "",
166 },
167 {
168 name: "single line without empty lines",
169 script: "console.log('hello');",
170 expected: " console.log('hello');\n",
171 },
172 {
173 name: "multiple lines without empty lines",
174 script: "const x = 1;\nconsole.log(x);",
175 expected: " const x = 1;\n console.log(x);\n",
176 },
177 {
178 name: "script with empty lines should skip them",
179 script: "const x = 1;\n\nconsole.log(x);\n\nreturn x;",
180 expected: " const x = 1;\n console.log(x);\n return x;\n",
181 },
182 {
183 name: "script with only whitespace lines should skip them",
184 script: "const x = 1;\n \n\t\nconsole.log(x);",
185 expected: " const x = 1;\n console.log(x);\n",
186 },
187 {
188 name: "script with leading and trailing empty lines",
189 script: "\n\nconst x = 1;\nconsole.log(x);\n\n",
190 expected: " const x = 1;\n console.log(x);\n",
191 },
192 {
193 name: "script with indented code",
194 script: "if (true) {\n console.log('indented');\n}",
195 expected: " if (true) {\n console.log('indented');\n }\n",
196 },
197 {
198 name: "complex script with mixed content",
199 script: "// Comment\nconst github = require('@actions/github');\n\nconst token = process.env.GITHUB_TOKEN;\n\n// Another comment\nif (token) {\n console.log('Token found');\n}\n",
200 expected: " const github = require('@actions/github');\n const token = process.env.GITHUB_TOKEN;\n if (token) {\n console.log('Token found');\n }\n",
201 },
202 {
203 name: "script with only single-line comments should produce empty result",
204 script: "// First comment\n// Second comment\n//Third comment",
205 expected: "",
206 },
207 {
208 name: "script with block comments",
209 script: "/* Block comment */\nconst x = 1;\n/* Another\n multiline\n comment */\nreturn x;",
210 expected: " const x = 1;\n return x;\n",
211 },
212 {
213 name: "script with comments inside strings should preserve them",

Callers

nothing calls this directly

Calls 4

WriteJavaScriptToYAMLFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected