@@ -2,7 +2,8 @@ import { assertEquals } from "@std/assert";
22import { assertType } from "@std/testing/types" ;
33import { type Equal , testWithExamples } from "../_testutil.ts" ;
44import { is } from "../is/mod.ts" ;
5- import { asReadonly , asUnreadonly } from "./readonly.ts" ;
5+ import type { AsReadonly } from "../_annotation.ts" ;
6+ import { asReadonly , asUnreadonly , hasReadonly } from "./readonly.ts" ;
67
78Deno . test ( "asReadonly<T>" , async ( t ) => {
89 await t . step ( "returns a property named predicate function" , ( ) => {
@@ -155,3 +156,23 @@ Deno.test("asUnreadonly<T>", async (t) => {
155156 } ) ;
156157 } ) ;
157158} ) ;
159+
160+ Deno . test ( "hasReadonly<P>" , async ( t ) => {
161+ await t . step ( "returns true on AsReadonly<T> predicate" , ( ) => {
162+ const pred = asReadonly ( is . Number ) ;
163+ assertEquals ( hasReadonly ( pred ) , true ) ;
164+ } ) ;
165+
166+ await t . step ( "returns true on non AsReadonly<T> predicate" , ( ) => {
167+ const pred = is . Number ;
168+ assertEquals ( hasReadonly ( pred ) , false ) ;
169+ } ) ;
170+
171+ await t . step ( "predicated type is correct" , ( ) => {
172+ const pred = asReadonly ( is . Number ) ;
173+ type P = typeof pred ;
174+ if ( hasReadonly ( pred ) ) {
175+ assertType < Equal < typeof pred , P & AsReadonly > > ( true ) ;
176+ }
177+ } ) ;
178+ } ) ;
0 commit comments