File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,19 @@ use std::path::Path;
77
88static VALIDATOR : Lazy < Set < Mmap > > = Lazy :: new ( || {
99 let path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "purls.fst" ) ;
10+ load_fst ( & path)
11+ } ) ;
12+
13+ fn load_fst ( path : & Path ) -> Set < Mmap > {
1014 let file = File :: open ( path) . expect ( "Failed to open FST file" ) ;
1115 let mmap = unsafe { Mmap :: map ( & file) . expect ( "Failed to mmap FST file" ) } ;
1216 Set :: new ( mmap) . expect ( "Failed to load FST from mmap" )
13- } ) ;
17+ }
1418
1519pub fn validate ( packageurl : & str ) -> bool {
1620 let trimmed_packageurl = packageurl. trim_end_matches ( "/" ) ;
1721 VALIDATOR . contains ( trimmed_packageurl)
1822}
23+
24+ #[ cfg( test) ]
25+ mod validate_tests;
Original file line number Diff line number Diff line change 1+ use super :: * ;
2+ use std:: path:: Path ;
3+
4+ #[ test]
5+ fn test_validate_with_custom_file ( ) {
6+ let test_path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/data/test_purls.fst" ) ;
7+ let validator = load_fst ( & test_path) ;
8+
9+ assert ! ( validator. contains( "pkg:nuget/FluentUtils.EnumExtensions" ) ) ;
10+ assert ! ( !validator. contains( "pkg:example/nonexistent" ) ) ;
11+ }
You can’t perform that action at this time.
0 commit comments