-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate tests from deno.land to JSR (#651)
- Loading branch information
1 parent
5aac3e6
commit 550691e
Showing
5 changed files
with
152 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Composer, type Context } from "../src/mod.ts"; | ||
import { | ||
assertType, | ||
describe, | ||
type IsExact, | ||
type IsMutuallyAssignable, | ||
it, | ||
} from "./deps.test.ts"; | ||
|
||
describe("ctx.has* checks", () => { | ||
it("should narrow down types", () => { | ||
const c = new Composer<Context & { state: 1 }>(); | ||
c.use((ctx) => { | ||
assertType<IsExact<typeof ctx.state, 1>>(true); | ||
if (ctx.has(":contact")) { | ||
assertType< | ||
IsExact<typeof ctx.msg.contact.phone_number, string> | ||
>(true); | ||
assertType<IsExact<typeof ctx.state, 1>>(true); | ||
} | ||
if (ctx.hasText("123")) { | ||
assertType< | ||
IsMutuallyAssignable< | ||
typeof ctx.match, | ||
string | RegExpMatchArray | ||
> | ||
>(true); | ||
} | ||
if (ctx.hasCommand("123")) { | ||
assertType<IsMutuallyAssignable<typeof ctx.match, string>>( | ||
true, | ||
); | ||
} | ||
if (ctx.hasChatType("private")) { | ||
assertType<IsExact<typeof ctx.chat.type, "private">>(true); | ||
} | ||
if (ctx.hasGameQuery("123")) { | ||
assertType< | ||
IsExact< | ||
typeof ctx.callbackQuery.game_short_name, | ||
string | ||
> | ||
>(true); | ||
} | ||
if (ctx.hasInlineQuery("123")) { | ||
assertType<IsExact<typeof ctx.inlineQuery.id, string>>( | ||
true, | ||
); | ||
} | ||
}); | ||
c.command("c", (ctx) => { | ||
assertType<IsMutuallyAssignable<typeof ctx.match, string>>(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,34 @@ export { | |
assertRejects, | ||
assertStringIncludes, | ||
assertThrows, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
export { | ||
afterEach, | ||
beforeEach, | ||
describe, | ||
it, | ||
} from "https://deno.land/[email protected]/testing/bdd.ts"; | ||
export { | ||
type Spy, | ||
spy, | ||
type Stub, | ||
stub, | ||
} from "https://deno.land/[email protected]/testing/mock.ts"; | ||
export { | ||
assertType, | ||
type IsExact, | ||
} from "https://deno.land/[email protected]/testing/types.ts"; | ||
} from "jsr:@std/assert"; | ||
export { afterEach, beforeEach, describe, it } from "jsr:@std/testing/bdd"; | ||
export { type Spy, spy, type Stub, stub } from "jsr:@std/testing/mock"; | ||
export { assertType, type IsExact } from "jsr:@std/testing/types"; | ||
|
||
/** | ||
* Checks if the actual type `A` is assignable to the expected type `E`, and | ||
* vice versa. | ||
* | ||
* ```ts | ||
* // false because E is not assignable to A | ||
* type P = IsMutuallyAssignable<string & RegExpMatchArray, string>; | ||
* // false because A is not assignable to E | ||
* type Q = IsMutuallyAssignable<string | RegExpMatchArray, string>; | ||
* // true | ||
* type R = IsMutuallyAssignable<string | (string & RegExpMatchArray), string>; | ||
* ``` | ||
*/ | ||
export type IsMutuallyAssignable<A, E> = [E] extends [A] | ||
? [A] extends [E] ? true : false | ||
: false; | ||
|
||
/** | ||
* Collects a potentially async iterator of `Uint8Array` objects into a single | ||
* array. | ||
* | ||
* @param data a stream of byte chunks | ||
*/ | ||
export async function convertToUint8Array( | ||
data: Iterable<Uint8Array> | AsyncIterable<Uint8Array>, | ||
) { | ||
|