summaryrefslogtreecommitdiff
path: root/features
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2018-08-29 22:49:20 -0700
committerGitHub <noreply@github.com>2018-08-29 22:49:20 -0700
commit67339d896aa65d75272b80134a8128276c8c6a0f (patch)
tree09eb145ffcbaf89d873c89e8346ee8d38a88ebbe /features
parent29dd9bb233e149cae62a2277020074f8fec1eec8 (diff)
parent800dd7677276f9e425c5db37b3e31e56ab1dad32 (diff)
Merge pull request #23 from dickmao/fix-castling-legality
Add tests for castling legality and ics response handling.
Diffstat (limited to 'features')
-rw-r--r--features/castling.feature7
-rw-r--r--features/ics.feature5
-rw-r--r--features/step-definitions/emacs-chess-steps.el47
-rw-r--r--features/support/env.el43
4 files changed, 102 insertions, 0 deletions
diff --git a/features/castling.feature b/features/castling.feature
new file mode 100644
index 0000000..8cbcf02
--- /dev/null
+++ b/features/castling.feature
@@ -0,0 +1,7 @@
+Scenario: e1-b1 is misinterpreted as O-O-O when it should be illegal
+ Given game with fen "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/R3KBNR w KQkq -"
+ Then the move "e1-b1" is illegal
+
+Scenario: e8-b8 is misinterpreted as O-O-O when it should be illegal
+ Given game with fen "r3kbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq -"
+ Then the move "e8-b8" is illegal
diff --git a/features/ics.feature b/features/ics.feature
new file mode 100644
index 0000000..5a49dfe
--- /dev/null
+++ b/features/ics.feature
@@ -0,0 +1,5 @@
+Scenario: Echo area should indicate opponent ran out of time.
+ Given ics session
+ When new game
+ And opponent forfeits on time
+ Then I should see message "Your opponent has forfeited the game on time"
diff --git a/features/step-definitions/emacs-chess-steps.el b/features/step-definitions/emacs-chess-steps.el
new file mode 100644
index 0000000..5e1b6cc
--- /dev/null
+++ b/features/step-definitions/emacs-chess-steps.el
@@ -0,0 +1,47 @@
+;; This file contains your project specific step definitions. All
+;; files in this directory whose names end with "-steps.el" will be
+;; loaded automatically by Ecukes.
+
+(Given "^ics session$"
+ (lambda ()
+ (let ((test-fn (expand-file-name (make-temp-name "test-fifo") (or small-temporary-file-directory temporary-file-directory))))
+ (setq test-fifo (start-process-shell-command "test-fifo" nil (format "mkfifo %s && cat >> %s" test-fn test-fn)))
+ (process-send-string test-fifo "login:\n")
+ (process-send-string test-fifo "Logging you in as \"GuestME\"\n")
+ (process-send-string test-fifo "fics% \n")
+ (sleep-for 3)
+ (chess-ics "nowhere.org" 5000 nil nil "sh" "-c" (format "cat %s" test-fn))
+
+ )))
+
+(When "^new game$"
+ (lambda ()
+ (process-send-string test-fifo (format "{Game 42 (GuestYOU vs. GuestME) Creating unrated blitz match.}\n"))
+ (process-send-string test-fifo (format "<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 23 GuestYOU GuestME -1 5 5 39 39 300 300 1 none (0:00) none 1 0 0\n"))
+ (process-send-string test-fifo (format "<12> rnbqkbnr pppppppp -------- -------- --P----- -------- PP-PPPPP RNBQKBNR B 2 1 1 1 1 0 23 GuestYOU GuestME 1 5 5 39 39 300 300 1 P/c2-c4 (0:00) c4 1 0 0\n"))
+ (process-send-string test-fifo (format "<12> rnbqkbnr pppp-ppp -------- ----p--- --P----- -------- PP-PPPPP RNBQKBNR W 4 1 1 1 1 0 23 GuestYOU GuestME -1 5 5 39 39 300 300 2 P/e7-e5 (0:00) e5 1 1 0\n"))
+ (sleep-for 3)
+ )
+ )
+
+(When "^opponent forfeits on time$"
+ (lambda ()
+ (process-send-string test-fifo (format "{Game 42 (GuestYOU vs. GuestME) GuestYOU forfeits on time} 0-1\n"))
+ (sleep-for 3)
+ ))
+
+(Given "^game with fen \"\\(.+\\)\"$"
+ (lambda (fen)
+ (let ((game (chess-game-create (chess-fen-to-pos fen))) objects)
+ (setq test-display (car (chess-create-modules (list '(chess-plain))
+ 'chess--create-display
+ game t t))))))
+
+(Then "^the move \"\\([a-h][1-8]\\)-\\([a-h][1-8]\\)\" is illegal$"
+ (lambda (source target)
+ (let ((position (chess-display-position test-display)))
+ (assert (null (chess-ply-create position nil
+ (chess-coord-to-index source)
+ (chess-coord-to-index target)))))))
+
+
diff --git a/features/support/env.el b/features/support/env.el
new file mode 100644
index 0000000..58ed42f
--- /dev/null
+++ b/features/support/env.el
@@ -0,0 +1,43 @@
+(require 'f)
+
+(defvar emacs-chess-support-path
+ (f-dirname load-file-name))
+
+(defvar emacs-chess-features-path
+ (f-parent emacs-chess-support-path))
+
+(defvar emacs-chess-root-path
+ (f-parent emacs-chess-features-path))
+
+(add-to-list 'load-path emacs-chess-root-path)
+
+(require 'chess-ics)
+(require 'espuds)
+(require 'ert)
+(require 'cl)
+
+(Setup
+ (defvar test-display nil)
+ (defvar test-fifo nil)
+)
+
+(Before
+ ;; Before each scenario is run
+ )
+
+(After
+ ;; After each scenario is run
+ (when test-display
+ (chess-module-destroy test-display)
+ (setq test-display nil))
+ (when (process-status "*chess-ics*")
+ (delete-process "*chess-ics*"))
+ (when test-fifo
+ (process-send-eof test-fifo)
+ (delete-process test-fifo)
+ (setq test-fifo nil))
+)
+
+(Teardown
+ ;; After when everything has been run
+ )