1
+ import { bench } from "vitest" ;
1
2
import { parseRef , tsIntersectionOf , tsUnionOf } from "../src/utils.js" ;
2
3
3
4
describe ( "utils" , ( ) => {
@@ -48,11 +49,7 @@ describe("utils", () => {
48
49
[ "identity for unknown type" , [ "unknown" ] , "unknown" ] ,
49
50
[ "unknown for no types passed" , [ ] , "unknown" ] ,
50
51
[ "parentheses around types with union" , [ "4" , `string | number` ] , "4 & (string | number)" ] ,
51
- [
52
- "parentheses around types with intersection" ,
53
- [ "{ red: string }" , "{ blue: string } & { green: string }" ] ,
54
- "{ red: string } & ({ blue: string } & { green: string })" ,
55
- ] ,
52
+ [ "parentheses around types with intersection" , [ "{ red: string }" , "{ blue: string } & { green: string }" ] , "{ red: string } & ({ blue: string } & { green: string })" ] ,
56
53
] ;
57
54
58
55
tests . forEach ( ( [ name , input , output ] ) => {
@@ -64,19 +61,23 @@ describe("utils", () => {
64
61
65
62
describe ( "parseRef" , ( ) => {
66
63
it ( "basic" , ( ) => {
67
- expect ( parseRef ( "#/test/schema-object" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , "schema-object" ] } ) ;
64
+ expect ( parseRef ( "#/test/schema-object" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , "schema-object" ] } ) ;
68
65
} ) ;
69
66
70
67
it ( "double quote" , ( ) => {
71
- expect ( parseRef ( " #/test/\"" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\\"' ] } ) ;
68
+ expect ( parseRef ( ' #/test/"' ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\"' ] } ) ;
72
69
} ) ;
73
70
74
71
it ( "escaped double quote" , ( ) => {
75
- expect ( parseRef ( " #/test/\\\"" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\\"' ] } ) ;
72
+ expect ( parseRef ( ' #/test/\\"' ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\"' ] } ) ;
76
73
} ) ;
77
74
78
75
it ( "tilde escapes" , ( ) => {
79
- expect ( parseRef ( "#/test/~1~0" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , "/~" ] } ) ;
76
+ expect ( parseRef ( "#/test/~1~0" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , "/~" ] } ) ;
77
+ } ) ;
78
+
79
+ it ( "js-yaml $ref" , ( ) => {
80
+ expect ( parseRef ( 'components["schemas"]["SchemaObject"]' ) ) . toStrictEqual ( { filename : "." , path : [ "components" , "schemas" , "SchemaObject" ] } ) ;
80
81
} ) ;
81
82
} ) ;
82
- } ) ;
83
+ } ) ;
0 commit comments