1+ import { bench } from "vitest" ;
12import { parseRef , tsIntersectionOf , tsUnionOf } from "../src/utils.js" ;
23
34describe ( "utils" , ( ) => {
@@ -48,11 +49,7 @@ describe("utils", () => {
4849 [ "identity for unknown type" , [ "unknown" ] , "unknown" ] ,
4950 [ "unknown for no types passed" , [ ] , "unknown" ] ,
5051 [ "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 })" ] ,
5653 ] ;
5754
5855 tests . forEach ( ( [ name , input , output ] ) => {
@@ -64,19 +61,23 @@ describe("utils", () => {
6461
6562 describe ( "parseRef" , ( ) => {
6663 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" ] } ) ;
6865 } ) ;
6966
7067 it ( "double quote" , ( ) => {
71- expect ( parseRef ( " #/test/\"" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\\"' ] } ) ;
68+ expect ( parseRef ( ' #/test/"' ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\"' ] } ) ;
7269 } ) ;
7370
7471 it ( "escaped double quote" , ( ) => {
75- expect ( parseRef ( " #/test/\\\"" ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\\"' ] } ) ;
72+ expect ( parseRef ( ' #/test/\\"' ) ) . toStrictEqual ( { filename : "." , path : [ "test" , '\\"' ] } ) ;
7673 } ) ;
7774
7875 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" ] } ) ;
8081 } ) ;
8182 } ) ;
82- } ) ;
83+ } ) ;
0 commit comments