@@ -134,4 +134,155 @@ class EditAlgTest extends FunSuite {
134
134
case Log (_) => false
135
135
})
136
136
}
137
+
138
+ test(" applyUpdate for scala-cli using lib" ) {
139
+ val repo = Repo (" edit-alg" , " test-4" )
140
+ val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
141
+ val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
142
+ val mainSc = repoDir / " main.sc"
143
+ val update = (" org.typelevel" .g % " cats-effect" .a % " 3.5.2" %> " 3.5.4" ).single
144
+
145
+ val state = MockState .empty
146
+ .copy(execCommands = true )
147
+ .initGitRepo(
148
+ repoDir,
149
+ mainSc ->
150
+ """
151
+ |//> using scala "3.4.2"
152
+ |//> using jvm "temurin:21"
153
+ |//> using lib "org.typelevel::cats-effect:3.5.2"
154
+ |println("Hello!")
155
+ |""" .stripMargin
156
+ )
157
+ .flatMap(editAlg.applyUpdate(data, update).runS)
158
+ .unsafeRunSync()
159
+
160
+ val expected = MockState .empty.copy(
161
+ execCommands = true ,
162
+ trace = Vector (
163
+ Cmd .gitGrep(repoDir, update.currentVersion.value),
164
+ Cmd (" read" , mainSc.pathAsString),
165
+ Cmd .gitGrep(repoDir, update.groupId.value),
166
+ Cmd (" read" , mainSc.pathAsString),
167
+ Cmd (" read" , mainSc.pathAsString),
168
+ Cmd (" write" , mainSc.pathAsString),
169
+ Cmd .gitStatus(repoDir),
170
+ Cmd .gitCommit(repoDir, " Update cats-effect to 3.5.4" ),
171
+ Cmd .gitLatestSha1(repoDir)
172
+ ),
173
+ files = Map (
174
+ mainSc ->
175
+ """
176
+ |//> using scala "3.4.2"
177
+ |//> using jvm "temurin:21"
178
+ |//> using lib "org.typelevel::cats-effect:3.5.4"
179
+ |println("Hello!")
180
+ |""" .stripMargin
181
+ )
182
+ )
183
+
184
+ assertEquals(state, expected)
185
+ }
186
+
187
+ test(" applyUpdate for scala-cli using dep" ) {
188
+ val repo = Repo (" edit-alg" , " test-5" )
189
+ val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
190
+ val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
191
+ val mainSc = repoDir / " main.sc"
192
+ val update = (" org.typelevel" .g % " cats-effect" .a % " 3.5.2" %> " 3.5.4" ).single
193
+
194
+ val state = MockState .empty
195
+ .copy(execCommands = true )
196
+ .initGitRepo(
197
+ repoDir,
198
+ mainSc ->
199
+ """
200
+ |//> using scala "3.4.2"
201
+ |//> using jvm "temurin:21"
202
+ |//> using dep "org.typelevel::cats-effect:3.5.2"
203
+ |//> using test.dep "org.scalameta::munit:1.0.0"
204
+ |println("Hello!")
205
+ |""" .stripMargin
206
+ )
207
+ .flatMap(editAlg.applyUpdate(data, update).runS)
208
+ .unsafeRunSync()
209
+
210
+ val expected = MockState .empty.copy(
211
+ execCommands = true ,
212
+ trace = Vector (
213
+ Cmd .gitGrep(repoDir, update.currentVersion.value),
214
+ Cmd (" read" , mainSc.pathAsString),
215
+ Cmd .gitGrep(repoDir, update.groupId.value),
216
+ Cmd (" read" , mainSc.pathAsString),
217
+ Cmd (" read" , mainSc.pathAsString),
218
+ Cmd (" write" , mainSc.pathAsString),
219
+ Cmd .gitStatus(repoDir),
220
+ Cmd .gitCommit(repoDir, " Update cats-effect to 3.5.4" ),
221
+ Cmd .gitLatestSha1(repoDir)
222
+ ),
223
+ files = Map (
224
+ mainSc ->
225
+ """
226
+ |//> using scala "3.4.2"
227
+ |//> using jvm "temurin:21"
228
+ |//> using dep "org.typelevel::cats-effect:3.5.4"
229
+ |//> using test.dep "org.scalameta::munit:1.0.0"
230
+ |println("Hello!")
231
+ |""" .stripMargin
232
+ )
233
+ )
234
+
235
+ assertEquals(state, expected)
236
+ }
237
+
238
+ test(" applyUpdate for scala-cli using test.dep" ) {
239
+ val repo = Repo (" edit-alg" , " test-6" )
240
+ val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
241
+ val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
242
+ val mainSc = repoDir / " main.sc"
243
+ val update = (" org.scalameta" .g % " munit" .a % " 0.7.29" %> " 1.0.0" ).single
244
+
245
+ val state = MockState .empty
246
+ .copy(execCommands = true )
247
+ .initGitRepo(
248
+ repoDir,
249
+ mainSc ->
250
+ """
251
+ |//> using scala "3.4.2"
252
+ |//> using jvm "temurin:21"
253
+ |//> using dep "org.typelevel::cats-effect:3.5.4"
254
+ |//> using test.dep "org.scalameta::munit:0.7.29"
255
+ |println("Hello!")
256
+ |""" .stripMargin
257
+ )
258
+ .flatMap(editAlg.applyUpdate(data, update).runS)
259
+ .unsafeRunSync()
260
+
261
+ val expected = MockState .empty.copy(
262
+ execCommands = true ,
263
+ trace = Vector (
264
+ Cmd .gitGrep(repoDir, update.currentVersion.value),
265
+ Cmd (" read" , mainSc.pathAsString),
266
+ Cmd .gitGrep(repoDir, update.groupId.value),
267
+ Cmd (" read" , mainSc.pathAsString),
268
+ Cmd (" read" , mainSc.pathAsString),
269
+ Cmd (" write" , mainSc.pathAsString),
270
+ Cmd .gitStatus(repoDir),
271
+ Cmd .gitCommit(repoDir, " Update munit to 1.0.0" ),
272
+ Cmd .gitLatestSha1(repoDir)
273
+ ),
274
+ files = Map (
275
+ mainSc ->
276
+ """
277
+ |//> using scala "3.4.2"
278
+ |//> using jvm "temurin:21"
279
+ |//> using dep "org.typelevel::cats-effect:3.5.4"
280
+ |//> using test.dep "org.scalameta::munit:1.0.0"
281
+ |println("Hello!")
282
+ |""" .stripMargin
283
+ )
284
+ )
285
+
286
+ assertEquals(state, expected)
287
+ }
137
288
}
0 commit comments