@@ -22,14 +22,13 @@ mod tests {
22
22
23
23
use super :: * ;
24
24
use crate :: {
25
- init_pnp_manifest, load_pnp_manifest, resolve_to_unqualified,
25
+ init_pnp_manifest, load_pnp_manifest, parse_bare_identifier , resolve_to_unqualified,
26
26
resolve_to_unqualified_via_manifest, ResolutionHost ,
27
27
} ;
28
28
29
29
#[ test]
30
30
fn example ( ) {
31
- let manifest
32
- = load_pnp_manifest ( "data/pnp-yarn-v3.cjs" ) . unwrap ( ) ;
31
+ let manifest = load_pnp_manifest ( "data/pnp-yarn-v3.cjs" ) . unwrap ( ) ;
33
32
34
33
let host = ResolutionHost {
35
34
find_pnp_manifest : Box :: new ( move |_| Ok ( Some ( manifest. clone ( ) ) ) ) ,
@@ -51,16 +50,16 @@ mod tests {
51
50
Ok ( Resolution :: Resolved ( _path, _subpath) ) => {
52
51
// path = "/path/to/lodash.zip"
53
52
// subpath = "cloneDeep"
54
- } ,
53
+ }
55
54
Ok ( Resolution :: Skipped ) => {
56
55
// This is returned when the PnP resolver decides that it shouldn't
57
56
// handle the resolution for this particular specifier. In that case,
58
57
// the specifier should be forwarded to the default resolver.
59
- } ,
58
+ }
60
59
Err ( _err) => {
61
60
// An error happened during the resolution. Falling back to the default
62
61
// resolver isn't recommended.
63
- } ,
62
+ }
64
63
} ;
65
64
}
66
65
@@ -110,23 +109,24 @@ mod tests {
110
109
match resolution {
111
110
Ok ( Resolution :: Resolved ( path, _subpath) ) => {
112
111
assert_eq ! ( path. to_string_lossy( ) , test. expected, "{}" , test. it) ;
113
- } ,
112
+ }
114
113
Ok ( Resolution :: Skipped ) => {
115
114
assert_eq ! ( specifier, & test. expected, "{}" , test. it) ;
116
- } ,
115
+ }
117
116
Err ( err) => {
118
117
assert_eq ! ( test. expected, "error!" , "{}: {}" , test. it, err. to_string( ) ) ;
119
- } ,
118
+ }
120
119
}
121
-
122
120
}
123
121
}
124
122
}
125
123
126
124
#[ test]
127
125
fn test_edge_case_one_pkg_cached_and_unplugged ( ) {
128
126
let manifest = {
129
- let manifest_json_path = std:: env:: current_dir ( ) . unwrap ( ) . join ( "./data/edge_case_manifest_state.json" ) ;
127
+ let manifest_json_path = std:: env:: current_dir ( )
128
+ . unwrap ( )
129
+ . join ( "./data/edge_case_manifest_state.json" ) ;
130
130
let manifest_content = fs:: read_to_string ( & manifest_json_path) . unwrap ( ) ;
131
131
let mut manifest = serde_json:: from_str :: < Manifest > ( & manifest_content) . unwrap ( ) ;
132
132
init_pnp_manifest ( & mut manifest, manifest_json_path) ;
@@ -149,4 +149,34 @@ mod tests {
149
149
}
150
150
}
151
151
}
152
+
153
+ #[ test]
154
+ fn test_parse_single_package_name ( ) {
155
+ let parsed = parse_bare_identifier ( "pkg" ) ;
156
+ assert_eq ! ( parsed, Ok ( ( "pkg" . to_string( ) , None ) ) ) ;
157
+ }
158
+
159
+ #[ test]
160
+ fn test_parse_scoped_package_name ( ) {
161
+ let parsed = parse_bare_identifier ( "@scope/pkg" ) ;
162
+ assert_eq ! ( parsed, Ok ( ( "@scope/pkg" . to_string( ) , None ) ) ) ;
163
+ }
164
+
165
+ #[ test]
166
+ fn test_parse_package_name_with_long_subpath ( ) {
167
+ let parsed = parse_bare_identifier ( "pkg/a/b/c/index.js" ) ;
168
+ assert_eq ! (
169
+ parsed,
170
+ Ok ( ( "pkg" . to_string( ) , Some ( "a/b/c/index.js" . to_string( ) ) ) )
171
+ ) ;
172
+ }
173
+
174
+ #[ test]
175
+ fn test_parse_scoped_package_with_long_subpath ( ) {
176
+ let parsed = parse_bare_identifier ( "@scope/pkg/a/b/c/index.js" ) ;
177
+ assert_eq ! (
178
+ parsed,
179
+ Ok ( ( "@scope/pkg" . to_string( ) , Some ( "a/b/c/index.js" . to_string( ) ) ) )
180
+ ) ;
181
+ }
152
182
}
0 commit comments