about summary refs log tree commit diff stats
path: root/chessboard.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-07 22:27:30 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-07 23:07:58 -0700
commit01aeedd9dc75f2f51ee62af9d54bb8a8a4f639e8 (patch)
treeeaed82f920ed3c4fdaa31c457659cd4aa3249df1 /chessboard.mu
parent6e6988580bc10c464b12d00ed3587704d682a8ae (diff)
downloadmu-01aeedd9dc75f2f51ee62af9d54bb8a8a4f639e8.tar.gz
1305
Diffstat (limited to 'chessboard.mu')
-rw-r--r--chessboard.mu81
1 files changed, 79 insertions, 2 deletions
diff --git a/chessboard.mu b/chessboard.mu
index d9ed4618..78d28038 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -183,7 +183,12 @@ recipe read-file [
   stdin:address:channel <- next-ingredient
   c:character, stdin:address:channel <- read stdin:address:channel
   {
-    q-pressed?:boolean <- equal c:character, 81:literal  # 'q'
+    q-pressed?:boolean <- equal c:character, 81:literal  # 'Q'
+    break-unless q-pressed?:boolean
+    reply -1:literal
+  }
+  {
+    q-pressed?:boolean <- equal c:character, 113:literal  # 'q'
     break-unless q-pressed?:boolean
     reply -1:literal
   }
@@ -201,7 +206,12 @@ recipe read-rank [
   stdin:address:channel <- next-ingredient
   c:character, stdin:address:channel <- read stdin:address:channel
   {
-    q-pressed?:boolean <- equal c:character, 81:literal  # 'q'
+    q-pressed?:boolean <- equal c:character, 81:literal  # 'Q'
+    break-unless q-pressed?:boolean
+    reply -1:literal
+  }
+  {
+    q-pressed?:boolean <- equal c:character, 113:literal  # 'q'
     break-unless q-pressed?:boolean
     reply -1:literal
   }
@@ -316,3 +326,70 @@ F read-move-blocking: routine failed to terminate on newline]
     test: reached end
   ]
 ]
+
+scenario read-move-quit [
+  run [
+    1:address:channel <- init-channel 2:literal
+    2:integer/routine <- start-running read-move:recipe, 1:address:channel
+    # 'read-move' is waiting for input
+    wait-for-routine 2:integer
+    3:integer <- routine-state 2:integer/id
+    4:boolean/waiting? <- equal 3:integer/routine-state, 2:literal/waiting
+    assert 4:boolean/waiting?, [
+F read-move-quit: routine failed to pause after coming up (before any keys were pressed)]
+    # press 'q'
+    1:address:channel <- write 1:address:channel, 113:literal  # 'q'
+    restart 2:integer/routine
+    # 'read-move' completes
+    wait-for-routine 2:integer
+    3:integer <- routine-state 2:integer/id
+    4:boolean/completed? <- equal 3:integer/routine-state, 1:literal/completed
+    assert 4:boolean/completed?, [
+F read-move-quit: routine failed to terminate on 'q']
+    trace [test], [reached end]
+  ]
+  trace-should-contain [
+    test: reached end
+  ]
+]
+
+scenario read-move-illegal-file [
+  run [
+    hide-warnings
+    1:address:channel <- init-channel 2:literal
+    2:integer/routine <- start-running read-move:recipe, 1:address:channel
+    # 'read-move' is waiting for input
+    wait-for-routine 2:integer
+    3:integer <- routine-state 2:integer/id
+    4:boolean/waiting? <- equal 3:integer/routine-state, 2:literal/waiting
+    assert 4:boolean/waiting?, [
+F read-move-file: routine failed to pause after coming up (before any keys were pressed)]
+    1:address:channel <- write 1:address:channel, 50:literal  # '2'
+    restart 2:integer/routine
+    wait-for-routine 2:integer
+  ]
+  trace-should-contain [
+    warn: file too low
+  ]
+]
+
+scenario read-move-illegal-rank [
+  run [
+    hide-warnings
+    1:address:channel <- init-channel 2:literal
+    2:integer/routine <- start-running read-move:recipe, 1:address:channel
+    # 'read-move' is waiting for input
+    wait-for-routine 2:integer
+    3:integer <- routine-state 2:integer/id
+    4:boolean/waiting? <- equal 3:integer/routine-state, 2:literal/waiting
+    assert 4:boolean/waiting?, [
+F read-move-file: routine failed to pause after coming up (before any keys were pressed)]
+    1:address:channel <- write 1:address:channel, 97:literal  # 'a'
+    1:address:channel <- write 1:address:channel, 97:literal  # 'a'
+    restart 2:integer/routine
+    wait-for-routine 2:integer
+  ]
+  trace-should-contain [
+    warn: rank too high
+  ]
+]