2017-05-31 13:24:43 +02:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module PrettyTests (tests) where
|
|
|
|
|
2019-03-17 22:47:38 +01:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
|
|
|
import Test.Tasty.TH
|
2017-05-31 13:24:43 +02:00
|
|
|
|
2019-03-17 22:47:38 +01:00
|
|
|
import Nix.Expr
|
|
|
|
import Nix.Pretty
|
2017-05-31 13:24:43 +02:00
|
|
|
|
|
|
|
case_indented_antiquotation :: Assertion
|
|
|
|
case_indented_antiquotation = do
|
2019-03-17 22:47:38 +01:00
|
|
|
assertPretty (mkIndentedStr 0 "echo $foo") "''echo $foo''"
|
|
|
|
assertPretty (mkIndentedStr 0 "echo ${foo}") "''echo ''${foo}''"
|
2017-05-31 13:24:43 +02:00
|
|
|
|
|
|
|
case_string_antiquotation :: Assertion
|
|
|
|
case_string_antiquotation = do
|
2019-03-17 22:47:38 +01:00
|
|
|
assertPretty (mkStr "echo $foo") "\"echo \\$foo\""
|
|
|
|
assertPretty (mkStr "echo ${foo}") "\"echo \\${foo}\""
|
2017-05-31 13:24:43 +02:00
|
|
|
|
2018-04-20 02:05:20 +02:00
|
|
|
case_function_params :: Assertion
|
|
|
|
case_function_params =
|
2019-03-17 22:47:38 +01:00
|
|
|
assertPretty (mkFunction (mkParamset [] True) (mkInt 3)) "{ ... }:\n 3"
|
2018-04-20 02:05:20 +02:00
|
|
|
|
2018-04-22 16:06:57 +02:00
|
|
|
case_paths :: Assertion
|
|
|
|
case_paths = do
|
2019-03-17 22:47:38 +01:00
|
|
|
assertPretty (mkPath False "~/test.nix") "~/test.nix"
|
|
|
|
assertPretty (mkPath False "/test.nix") "/test.nix"
|
|
|
|
assertPretty (mkPath False "./test.nix") "./test.nix"
|
2018-04-22 16:06:57 +02:00
|
|
|
|
2017-05-31 13:24:43 +02:00
|
|
|
tests :: TestTree
|
|
|
|
tests = $testGroupGenerator
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
assertPretty :: NExpr -> String -> Assertion
|
2019-03-17 22:47:38 +01:00
|
|
|
assertPretty e s =
|
|
|
|
assertEqual ("When pretty-printing " ++ show e) s . show $ prettyNix e
|