@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
33import {
44 claimWorkspaceBasenameLookup ,
55 needsWorkspaceBasenameLookup ,
6+ pickStrippedWorkspaceMatch ,
67 pickWorkspaceBasenameMatch ,
78 stripRepeatedWorkspacePrefix ,
89} from "./workspaceBasenameLookup" ;
@@ -112,3 +113,39 @@ describe("stripRepeatedWorkspacePrefix", () => {
112113 expect ( stripRepeatedWorkspacePrefix ( "physics" , "/school/physics" ) ) . toBeNull ( ) ;
113114 } ) ;
114115} ) ;
116+
117+ describe ( "pickStrippedWorkspaceMatch" , ( ) => {
118+ const file = ( path : string ) => ( { path, kind : "file" as const } ) ;
119+
120+ it ( "opens the stripped path when only it exists" , ( ) => {
121+ expect (
122+ pickStrippedWorkspaceMatch ( "physics/notes/a.md" , "notes/a.md" , "/school/physics" , [
123+ file ( "notes/a.md" ) ,
124+ ] ) ,
125+ ) . toBe ( "notes/a.md" ) ;
126+ } ) ;
127+
128+ it ( "keeps the literal path when a real nested folder exists" , ( ) => {
129+ expect (
130+ pickStrippedWorkspaceMatch ( "physics/notes/a.md" , "notes/a.md" , "/school/physics" , [
131+ file ( "notes/a.md" ) ,
132+ file ( "physics/notes/a.md" ) ,
133+ ] ) ,
134+ ) . toBeNull ( ) ;
135+ } ) ;
136+
137+ it ( "matches casing loosely only on Windows" , ( ) => {
138+ const entries = [ file ( "Notes/a.md" ) ] ;
139+ expect (
140+ pickStrippedWorkspaceMatch (
141+ "physics\\notes\\a.md" ,
142+ "notes/a.md" ,
143+ "C:\\school\\physics" ,
144+ entries ,
145+ ) ,
146+ ) . toBe ( "Notes/a.md" ) ;
147+ expect (
148+ pickStrippedWorkspaceMatch ( "physics/notes/a.md" , "notes/a.md" , "/school/physics" , entries ) ,
149+ ) . toBeNull ( ) ;
150+ } ) ;
151+ } ) ;
0 commit comments