parseTestUnits parses a test file into multiple test units based on @filename directives.
(content string, defaultFileName string)
| 62 | |
| 63 | // parseTestUnits parses a test file into multiple test units based on @filename directives. |
| 64 | func parseTestUnits(content string, defaultFileName string) []*testUnit { |
| 65 | lines := lineDelimiter.Split(content, -1) |
| 66 | |
| 67 | var units []*testUnit |
| 68 | var currentContent strings.Builder |
| 69 | var currentFileName string |
| 70 | |
| 71 | for _, line := range lines { |
| 72 | if testMetaData := optionRegex.FindStringSubmatch(line); testMetaData != nil { |
| 73 | metaDataName := strings.ToLower(testMetaData[1]) |
| 74 | if metaDataName == "filename" { |
| 75 | // Save the current file if we have one |
| 76 | if currentFileName != "" && currentContent.Len() > 0 { |
| 77 | units = append(units, &testUnit{ |
| 78 | name: currentFileName, |
| 79 | content: currentContent.String(), |
| 80 | }) |
| 81 | } |
| 82 | // Start new file |
| 83 | currentFileName = strings.TrimSpace(testMetaData[2]) |
| 84 | currentContent.Reset() |
| 85 | continue |
| 86 | } |
| 87 | } |
| 88 | // Add line to current file content |
| 89 | if currentContent.Len() > 0 { |
| 90 | currentContent.WriteRune('\n') |
| 91 | } |
| 92 | currentContent.WriteString(line) |
| 93 | } |
| 94 | |
| 95 | // Handle the final file |
| 96 | if currentFileName != "" { |
| 97 | units = append(units, &testUnit{ |
| 98 | name: currentFileName, |
| 99 | content: currentContent.String(), |
| 100 | }) |
| 101 | } else if currentContent.Len() > 0 { |
| 102 | // Single file test |
| 103 | units = append(units, &testUnit{ |
| 104 | name: defaultFileName, |
| 105 | content: currentContent.String(), |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | return units |
| 110 | } |
| 111 | |
| 112 | // DefaultTsConfig is the default tsconfig content injected when a test does not provide one. |
| 113 | // It enables the Effect language service plugin with default diagnostic severities. |