MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / RunEffectRefactorTest

Function RunEffectRefactorTest

internal/effecttest/refactor_runner.go:115–251  ·  view source on GitHub ↗

RunEffectRefactorTest executes a single Effect refactor baseline test case. It creates a fourslash test instance, collects refactor inventory and application results for the selection specified by a "// refactor:" comment, and generates a *.refactors.txt baseline.

(t *testing.T, version bundledeffect.EffectVersion, testFile string)

Source from the content-addressed store, hash-verified

113// It creates a fourslash test instance, collects refactor inventory and application
114// results for the selection specified by a "// refactor:" comment, and generates a *.refactors.txt baseline.
115func RunEffectRefactorTest(t *testing.T, version bundledeffect.EffectVersion, testFile string) {
116 AcquireProgram()
117 defer ReleaseProgram()
118
119 // Read the test file
120 content, err := os.ReadFile(testFile)
121 if err != nil {
122 t.Fatal("Failed to read test file:", err)
123 }
124
125 // Parse the "// refactor:" comment marker (comment is preserved in source)
126 rc := parseRefactorComment(string(content))
127 sourceContent := string(content)
128
129 // Parse test file into units (handles @filename directives)
130 defaultFileName := tspath.GetBaseFileName(testFile)
131 units := parseTestUnits(sourceContent, defaultFileName)
132
133 // Build fourslash content with @filename directives
134 var sb strings.Builder
135 currentDirectory := "/.src"
136
137 // Check if a tsconfig is provided
138 hasTsConfig := false
139 for _, unit := range units {
140 unitName := tspath.GetNormalizedAbsolutePath(unit.name, currentDirectory)
141 if strings.HasSuffix(strings.ToLower(unitName), "tsconfig.json") || strings.HasSuffix(strings.ToLower(unitName), "jsconfig.json") {
142 hasTsConfig = true
143 break
144 }
145 }
146
147 // Inject default tsconfig if none was provided
148 if !hasTsConfig {
149 sb.WriteString("// @filename: ")
150 sb.WriteString(tspath.GetNormalizedAbsolutePath("tsconfig.json", currentDirectory))
151 sb.WriteString("\n")
152 sb.WriteString(DefaultTsConfig)
153 sb.WriteString("\n")
154 }
155
156 // Collect test file paths for later use
157 var testFileNames []string
158
159 // Add all test units as fourslash files
160 for _, unit := range units {
161 unitName := tspath.GetNormalizedAbsolutePath(unit.name, currentDirectory)
162 sb.WriteString("// @filename: ")
163 sb.WriteString(unitName)
164 sb.WriteString("\n")
165 sb.WriteString(unit.content)
166 sb.WriteString("\n")
167
168 // Track non-config files
169 if !strings.HasSuffix(strings.ToLower(unitName), "tsconfig.json") && !strings.HasSuffix(strings.ToLower(unitName), "jsconfig.json") {
170 testFileNames = append(testFileNames, unitName)
171 }
172 }

Callers 2

TestEffectRefactorsFunction · 0.92
TestEffectV3RefactorsFunction · 0.92

Calls 6

AcquireProgramFunction · 0.85
ReleaseProgramFunction · 0.85
parseRefactorCommentFunction · 0.85
parseTestUnitsFunction · 0.85
DoRefactorBaselineFunction · 0.85
StringMethod · 0.45

Tested by 2

TestEffectRefactorsFunction · 0.74
TestEffectV3RefactorsFunction · 0.74