Skip to content

Commit 40babe5

Browse files
committed
minor refactorings to support platform agnostic paths
1 parent 0fdc51e commit 40babe5

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/tests/Find-MarkdownImages.Tests.ps1

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Describe "Find-MarkdownImages" {
1717
Context "Basic image detection" {
1818
It "Should include external images by default" {
1919
# arrange
20-
$markdownFile = "TestDrive:\external.md"
20+
$markdownFile = Join-Path "TestDrive:" "external.md"
2121
$markdownContent = @(
2222
"# Test Post"
2323
""
@@ -38,7 +38,7 @@ Describe "Find-MarkdownImages" {
3838

3939
It "Should exclude external images when -ExcludeExternal is used" {
4040
# arrange
41-
$markdownFile = "TestDrive:\external-exclude.md"
41+
$markdownFile = Join-Path "TestDrive:" "external-exclude.md"
4242
$markdownContent = @(
4343
"# Test Post"
4444
""
@@ -61,7 +61,7 @@ Describe "Find-MarkdownImages" {
6161

6262
It "Should return an empty array if there are no images" {
6363
# arrange
64-
$markdownFile = "TestDrive:\no-images.md"
64+
$markdownFile = Join-Path "TestDrive:" "no-images.md"
6565
$markdownContent = "# Test Post"
6666
Set-MarkdownFile $markdownFile $markdownContent
6767

@@ -75,7 +75,7 @@ Describe "Find-MarkdownImages" {
7575

7676
It "Should find images with alt text only" {
7777
# arrange
78-
$markdownFile = "TestDrive:\basic.md"
78+
$markdownFile = Join-Path "TestDrive:" "basic.md"
7979
$markdownContent = @(
8080
"# Test Post"
8181
""
@@ -98,7 +98,7 @@ Describe "Find-MarkdownImages" {
9898

9999
It "Should find images with alt text and title" {
100100
# arrange
101-
$markdownFile = "TestDrive:\with-title.md"
101+
$markdownFile = Join-Path "TestDrive:" "with-title.md"
102102
$markdownContent = @(
103103
"# Test Post"
104104
""
@@ -120,7 +120,7 @@ Describe "Find-MarkdownImages" {
120120

121121
It "Should find multiple images in the same file" {
122122
# arrange
123-
$markdownFile = "TestDrive:\multiple.md"
123+
$markdownFile = Join-Path "TestDrive:" "multiple.md"
124124
$markdownContent = @(
125125
"# Test Post"
126126
""
@@ -156,7 +156,7 @@ Describe "Find-MarkdownImages" {
156156
}
157157
It "Should resolve relative paths correctly" {
158158
# arrange
159-
$markdownFile = "TestDrive:\relative.md"
159+
$markdownFile = Join-Path "TestDrive:" "relative.md"
160160
$markdownContent = @(
161161
""
162162
"![Relative image](./subfolder/test-image2.jpg)"
@@ -175,8 +175,8 @@ Describe "Find-MarkdownImages" {
175175

176176
It "Should handle absolute paths" {
177177
# arrange
178-
$markdownFile = "TestDrive:\absolute.md"
179-
$absolutePath = (Get-Item "TestDrive:\absolute-image.gif").FullName
178+
$markdownFile = Join-Path "TestDrive:" "absolute.md"
179+
$absolutePath = (Get-Item (Join-Path "TestDrive:" "absolute-image.gif")).FullName
180180
$markdownContent = @(
181181
""
182182
"![Absolute image]($absolutePath)"
@@ -195,9 +195,9 @@ Describe "Find-MarkdownImages" {
195195
It "Should handle parent directory references" {
196196
# arrange
197197
# Create a markdown file in a subdirectory
198-
$subDir = "TestDrive:\subdir"
198+
$subDir = Join-Path "TestDrive:" "subdir"
199199
New-Item -Path $subDir -ItemType Directory -Force
200-
$markdownFile = "$subDir\parent-ref.md"
200+
$markdownFile = Join-Path $subDir "parent-ref.md"
201201
$markdownContent = @(
202202
""
203203
"![Parent image](../test-image1.png)"
@@ -223,7 +223,7 @@ Describe "Find-MarkdownImages" {
223223

224224
It "Should resolve absolute image in the attachments directory" {
225225
# arrange
226-
$markdownFile = Join-Path "TestDrive" "attachments.md"
226+
$markdownFile = Join-Path "TestDrive:" "attachments.md"
227227
$markdownContent = @(
228228
""
229229
"![Image in attachments](test-attachment1.png)"
@@ -241,7 +241,7 @@ Describe "Find-MarkdownImages" {
241241

242242
It "Should resolve absolute image with subfolder relative to the attachments directory" {
243243
# arrange
244-
$markdownFile = Join-Path "TestDrive" "attachments-subfolder.md"
244+
$markdownFile = Join-Path "TestDrive:" "attachments-subfolder.md"
245245
$markdownContent = @(
246246
""
247247
"![Image in subfolder](subfolder/test-attachment2.jpg)"
@@ -259,7 +259,7 @@ Describe "Find-MarkdownImages" {
259259

260260
It "Should find images in subfolders of the attachments directory when markdown does not specify a subfolder" {
261261
# arrange
262-
$markdownFile = Join-Path "TestDrive" "attachments-subfolder.md"
262+
$markdownFile = Join-Path "TestDrive:" "attachments-subfolder.md"
263263
$markdownContent = @(
264264
""
265265
"![Image in subfolder](test-attachment2.jpg)" # this is in the subfolder
@@ -277,7 +277,7 @@ Describe "Find-MarkdownImages" {
277277

278278
It "Should use folder of file if attachments directory is not specified" {
279279
# arrange
280-
$markdownFile = "TestDrive:\relative-path.md"
280+
$markdownFile = Join-Path "TestDrive:" "relative-path.md"
281281
$markdownContent = @(
282282
""
283283
"![Image with relative path](test-attachment1.png)"
@@ -321,7 +321,7 @@ Describe "Find-MarkdownImages" {
321321
Context "Filtering and validation" {
322322
It "Should skip images that are already web hosted (HTTP/HTTPS)" {
323323
# arrange
324-
$markdownFile = "TestDrive:\with-urls.md"
324+
$markdownFile = Join-Path "TestDrive:" "with-urls.md"
325325
$markdownContent = @(
326326
""
327327
"![Local image](test-image1.png)"
@@ -340,7 +340,7 @@ Describe "Find-MarkdownImages" {
340340

341341
It "Should skip non-existent files" {
342342
# arrange
343-
$markdownFile = "TestDrive:\missing-files.md"
343+
$markdownFile = Join-Path "TestDrive:" "missing-files.md"
344344
$markdownContent = @(
345345
""
346346
"![Existing image](test-image1.png)"
@@ -360,7 +360,7 @@ Describe "Find-MarkdownImages" {
360360

361361
It "Should handle empty alt text" {
362362
# arrange
363-
$markdownFile = "TestDrive:\empty-alt.md"
363+
$markdownFile = Join-Path "TestDrive:" "empty-alt.md"
364364
$markdownContent = @(
365365
""
366366
"![](test-image1.png)"
@@ -380,10 +380,10 @@ Describe "Find-MarkdownImages" {
380380
Context "Edge cases and special characters" {
381381
It "Should handle images with spaces in filenames" {
382382
# arrange
383-
$imageWithSpaces = "TestDrive:\image with spaces.png"
383+
$imageWithSpaces = Join-Path "TestDrive:" "image with spaces.png"
384384
Set-Content -Path $imageWithSpaces -Value "fake content"
385-
386-
$markdownFile = "TestDrive:\spaces.md"
385+
386+
$markdownFile = Join-Path "TestDrive:" "spaces.md"
387387
$markdownContent = @(
388388
""
389389
"![Image with spaces](image with spaces.png)"
@@ -400,7 +400,7 @@ Describe "Find-MarkdownImages" {
400400

401401
It "Should handle special characters in alt text" {
402402
# arrange
403-
$markdownFile = "TestDrive:\special-chars.md"
403+
$markdownFile = Join-Path "TestDrive:" "special-chars.md"
404404
$markdownContent = @(
405405
""
406406
"![Alt with `"quotes`" and 'apostrophes'](test-image1.png)"
@@ -417,7 +417,7 @@ Describe "Find-MarkdownImages" {
417417

418418
It "Should handle markdown files with no images" {
419419
# arrange
420-
$markdownFile = "TestDrive:\no-images.md"
420+
$markdownFile = Join-Path "TestDrive:" "no-images.md"
421421
$markdownContent = @(
422422
"# Test Post"
423423
""
@@ -436,7 +436,7 @@ Describe "Find-MarkdownImages" {
436436
Context "Return object structure" {
437437
It "Should return objects with all expected properties" {
438438
# arrange
439-
$markdownFile = "TestDrive:\properties.md"
439+
$markdownFile = Join-Path "TestDrive:" "properties.md"
440440
$markdownContent = @(
441441
""
442442
"![Test Alt](test-image1.png `"Test Title`")"
@@ -523,7 +523,7 @@ Describe "Find-MarkdownImages" {
523523
It "Should handle <Name>" -TestCases $obsidianTestCases {
524524
param($Name, $Content, $ExpectedCount, $ExpectedAltText, $ExpectedFileName, $ExpectedOriginal)
525525
# arrange
526-
$markdownFile = "TestDrive:\obsidian-test.md"
526+
$markdownFile = Join-Path "TestDrive:" "obsidian-test.md"
527527
Set-MarkdownFile $markdownFile $Content
528528

529529
# act
@@ -551,7 +551,7 @@ Describe "Find-MarkdownImages" {
551551

552552
It "Should skip Obsidian images with HTTP URLs" {
553553
# arrange
554-
$markdownFile = "TestDrive:\obsidian-urls.md"
554+
$markdownFile = Join-Path "TestDrive:" "obsidian-urls.md"
555555
$markdownContent = @(
556556
"![[test-image1.png|Local image]]",
557557
"![[http://example.com/image.jpg|HTTP image]]",
@@ -569,7 +569,7 @@ Describe "Find-MarkdownImages" {
569569

570570
It "Should skip non-existent Obsidian images" {
571571
# arrange
572-
$markdownFile = "TestDrive:\obsidian-missing.md"
572+
$markdownFile = Join-Path "TestDrive:" "obsidian-missing.md"
573573
$markdownContent = @(
574574
"![[test-image1.png|Existing image]]",
575575
"![[does-not-exist.jpg|Missing image]]",
@@ -589,7 +589,7 @@ Describe "Find-MarkdownImages" {
589589
It "Should not find embedded markdown content" {
590590
# arrange
591591
# obsidian can link content from an external file as an embedded markdown block
592-
$markdownFile = "TestDrive:\obsidian-embedded.md"
592+
$markdownFile = Join-Path "TestDrive:" "obsidian-embedded.md"
593593
$markdownContent = "![[Embedded Markdown Page|Title]]"
594594
Set-MarkdownFile $markdownFile $markdownContent
595595

@@ -651,7 +651,7 @@ Describe "Find-MarkdownImages" {
651651
It "Should handle <Name>" -TestCases $mixedFormatTestCases {
652652
param($Name, $Content, $ExpectedCount, $ExpectedAltTexts, $ExpectedTitles)
653653
# arrange
654-
$markdownFile = "TestDrive:\mixed-format-test.md"
654+
$markdownFile = Join-Path "TestDrive:" "mixed-format-test.md"
655655
Set-MarkdownFile $markdownFile $Content
656656

657657
# act

src/tests/_TestHelpers.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ function Set-MarkdownFile($path, $content) {
44
Set the content of a markdown file
55
#>
66
# resolve path
7-
$path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path)
8-
$Folder = [System.IO.Path]::GetDirectoryName($path)
7+
$resolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path)
8+
$Folder = [System.IO.Path]::GetDirectoryName($resolvedPath)
99
if (-not (Test-Path -Path $Folder)) {
1010
New-Item -ItemType Directory -Path $Folder -Force | Out-Null
1111
}
12-
Set-Content -Path $path -Value $content
12+
Set-Content -Path $resolvedPath -Value $content
1313
}
1414

1515
function New-BlogPost($id) {

0 commit comments

Comments
 (0)