(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestFormatJavaScriptForYAML(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | script string |
| 14 | expected []string |
| 15 | }{ |
| 16 | { |
| 17 | name: "empty string", |
| 18 | script: "", |
| 19 | expected: []string{}, |
| 20 | }, |
| 21 | { |
| 22 | name: "single line without empty lines", |
| 23 | script: "console.log('hello');", |
| 24 | expected: []string{ |
| 25 | " console.log('hello');\n", |
| 26 | }, |
| 27 | }, |
| 28 | { |
| 29 | name: "multiple lines without empty lines", |
| 30 | script: "const x = 1;\nconsole.log(x);", |
| 31 | expected: []string{ |
| 32 | " const x = 1;\n", |
| 33 | " console.log(x);\n", |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | name: "script with empty lines should skip them", |
| 38 | script: "const x = 1;\n\nconsole.log(x);\n\nreturn x;", |
| 39 | expected: []string{ |
| 40 | " const x = 1;\n", |
| 41 | " console.log(x);\n", |
| 42 | " return x;\n", |
| 43 | }, |
| 44 | }, |
| 45 | { |
| 46 | name: "script with only whitespace lines should skip them", |
| 47 | script: "const x = 1;\n \n\t\nconsole.log(x);", |
| 48 | expected: []string{ |
| 49 | " const x = 1;\n", |
| 50 | " console.log(x);\n", |
| 51 | }, |
| 52 | }, |
| 53 | { |
| 54 | name: "script with leading and trailing empty lines", |
| 55 | script: "\n\nconst x = 1;\nconsole.log(x);\n\n", |
| 56 | expected: []string{ |
| 57 | " const x = 1;\n", |
| 58 | " console.log(x);\n", |
| 59 | }, |
| 60 | }, |
| 61 | { |
| 62 | name: "script with indented code", |
| 63 | script: "if (true) {\n console.log('indented');\n}", |
| 64 | expected: []string{ |
| 65 | " if (true) {\n", |
| 66 | " console.log('indented');\n", |
| 67 | " }\n", |
nothing calls this directly
no test coverage detected