all repos

tyess @ master

chess in typst

tyess/tests/errors.typ (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
what's creamy, 27 days ago
1
#import "../game.typ": apply-moves
2
#import "testutil.typ": assert-eq
3
4
// Queen blocked by own pawn on d2
5
#assert-eq(apply-moves(("Qd3",)).last().error, "Qd3: illegal move")
6
#assert-eq(apply-moves(("qd3",)).last().error, "qd3: illegal move")
7
8
// knight can't reach e4 from g8
9
#let st = apply-moves(("e4", "e5", "Nc3", "c6", "Ne4")).last()
10
#assert-eq(st.error, "Ne4: illegal move")
11
12
// pawn move to occupied square
13
#let st = apply-moves(("e4", "e5", "e4")).last()
14
#assert-eq(st.error, "e4: illegal move")
15
16
// bishop capture with no target
17
#let st = apply-moves(("d4", "d5", "Bxe5")).last()
18
#assert-eq(st.error, "Bxe5: illegal move")
19
20
// eook on h1 after castling
21
#let st = apply-moves(("e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "O-O", "Rh1")).last()
22
#assert-eq(st.error, "Rh1: illegal move")
23
24
// moving while in check without addressing it
25
#let st = apply-moves(("e4", "e5", "Qh5", "a6", "Qe5", "a5")).last()
26
#assert-eq(st.error, "a5: illegal move")
27
28
// error clears on next valid move
29
#let st = apply-moves(("zzz", "e4")).last()
30
#assert-eq(st.error, none)