aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Properties/Focus.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Properties/Focus.hs')
-rw-r--r--tests/Properties/Focus.hs74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/Properties/Focus.hs b/tests/Properties/Focus.hs
new file mode 100644
index 0000000..865dc72
--- /dev/null
+++ b/tests/Properties/Focus.hs
@@ -0,0 +1,74 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module Properties.Focus where
+
+import Test.QuickCheck
+import Instances
+import Utils
+
+import XMonad.StackSet hiding (filter)
+
+import Data.Maybe (fromJust)
+
+-- ---------------------------------------------------------------------
+-- rotating focus
+--
+
+-- master/focus
+--
+-- The tiling order, and master window, of a stack is unaffected by focus changes.
+--
+prop_focus_left_master (SizedPositive n) (x::T) =
+ index (applyN (Just n) focusUp x) == index x
+prop_focus_right_master (SizedPositive n) (x::T) =
+ index (applyN (Just n) focusDown x) == index x
+prop_focus_master_master (SizedPositive n) (x::T) =
+ index (applyN (Just n) focusMaster x) == index x
+
+prop_focusWindow_master (NonNegative n) (x :: T) =
+ case peek x of
+ Nothing -> True
+ Just _ -> let s = index x
+ i = n `mod` length s
+ in index (focusWindow (s !! i) x) == index x
+
+-- shifting focus is trivially reversible
+prop_focus_left (x :: T) = (focusUp (focusDown x)) == x
+prop_focus_right (x :: T) = (focusDown (focusUp x)) == x
+
+-- focus master is idempotent
+prop_focusMaster_idem (x :: T) = focusMaster x == focusMaster (focusMaster x)
+
+-- focusWindow actually leaves the window focused...
+prop_focusWindow_works (n :: NonNegative Int) (x :: T) =
+ case peek x of
+ Nothing -> True
+ Just _ -> let s = index x
+ i = fromIntegral n `mod` length s
+ in (focus . fromJust . stack . workspace . current) (focusWindow (s !! i) x) == (s !! i)
+
+-- rotation through the height of a stack gets us back to the start
+prop_focus_all_l (x :: T) = (foldr (const focusUp) x [1..n]) == x
+ where n = length (index x)
+prop_focus_all_r (x :: T) = (foldr (const focusDown) x [1..n]) == x
+ where n = length (index x)
+
+-- prop_rotate_all (x :: T) = f (f x) == f x
+-- f x' = foldr (\_ y -> rotate GT y) x' [1..n]
+
+-- focus is local to the current workspace
+prop_focus_down_local (x :: T) = hidden_spaces (focusDown x) == hidden_spaces x
+prop_focus_up_local (x :: T) = hidden_spaces (focusUp x) == hidden_spaces x
+
+prop_focus_master_local (x :: T) = hidden_spaces (focusMaster x) == hidden_spaces x
+
+prop_focusWindow_local (n :: NonNegative Int) (x::T ) =
+ case peek x of
+ Nothing -> True
+ Just _ -> let s = index x
+ i = fromIntegral n `mod` length s
+ in hidden_spaces (focusWindow (s !! i) x) == hidden_spaces x
+
+-- On an invalid window, the stackset is unmodified
+prop_focusWindow_identity (x::T ) = do
+ n <- arbitrary `suchThat` \n' -> not $ n' `member` x
+ return $ focusWindow n x == x