spec :: Spec
spec =
  describe "expandHome" $ do
    it "expands bare ~ to the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~"
      dir `shouldBe` home

    it "reflects changes to HOME" $
      bracket (Posix.getEnv "HOME") (\home -> Posix.putEnv ("HOME=" ++ fromMaybe "" home)) $ \_ -> do
        Posix.putEnv "HOME=foo"
        dir <- expandHome "~"
        dir `shouldBe` "foo"

    it "expands ~/$path to $path in the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~/foo"
      dir `shouldBe` home </> "foo"

    it "expands ~$user to the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name)
      dir `shouldBe` home

    it "expands ~$user/$path to $path in the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name ++ "/foo")
      dir `shouldBe` home </> "foo"

    it "is 'id' for other absolute patterns" $
      expandHome "/foo/bar~" `shouldReturn` "/foo/bar~"

    it "is 'id' for other relative patterns" $
      expandHome "baz/qu~ux" `shouldReturn` "baz/qu~ux"
spec :: Spec
spec =
  describe "expandHome" $ do
    it "expands bare ~ to the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~"
      dir `shouldBe` home

    it "reflects changes to HOME" $
      bracket (Posix.getEnv "HOME") (\home -> Posix.putEnv ("HOME=" ++ fromMaybe "" home)) $ \_ -> do
        Posix.putEnv "HOME=foo"
        dir <- expandHome "~"
        dir `shouldBe` "foo"

    it "expands ~/$path to $path in the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~/foo"
      dir `shouldBe` home </> "foo"

    it "expands ~$user to the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name)
      dir `shouldBe` home

    it "expands ~$user/$path to $path in the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name ++ "/foo")
      dir `shouldBe` home </> "foo"

    it "is 'id' for other absolute patterns" $
      expandHome "/foo/bar~" `shouldReturn` "/foo/bar~"

    it "is 'id' for other relative patterns" $
      expandHome "baz/qu~ux" `shouldReturn` "baz/qu~ux"
spec =
  describe "expandHome" $ do
    it "expands bare ~ to the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~"
      dir `shouldBe` home

    it "reflects changes to HOME" $
      bracket (Posix.getEnv "HOME") (\home -> Posix.putEnv ("HOME=" ++ fromMaybe "" home)) $ \_ -> do
        Posix.putEnv "HOME=foo"
        dir <- expandHome "~"
        dir `shouldBe` "foo"

    it "expands ~/$path to $path in the user home directory" $ do
      home <- getHomeDirectory
      dir <- expandHome "~/foo"
      dir `shouldBe` home </> "foo"

    it "expands ~$user to the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name)
      dir `shouldBe` home

    it "expands ~$user/$path to $path in the $user user home directory" $ do
      name <- getName
      home <- getHome
      dir <- expandHome ("~" ++ name ++ "/foo")
      dir `shouldBe` home </> "foo"

    it "is 'id' for other absolute patterns" $
      expandHome "/foo/bar~" `shouldReturn` "/foo/bar~"

    it "is 'id' for other relative patterns" $
      expandHome "baz/qu~ux" `shouldReturn` "baz/qu~ux"