dataframe-0.3.0.2: tests/Functions.hs
{-# LANGUAGE OverloadedStrings #-}
module Functions where
import Control.Exception
import Test.HUnit
import DataFrame.Functions (sanitize)
import qualified Data.Text as T
-- Test cases for the sanitize function
sanitizeIdentifiers :: Test
sanitizeIdentifiers = TestList
[ TestCase $ assertEqual "Reserved word 'Data' should become '_data_'"
"_data_" (sanitize "Data")
, TestCase $ assertEqual "Spaces should become underscores"
"my_data" (sanitize "My Data")
, TestCase $ assertEqual "Punctuation and parentheses should be handled"
"distance_km_h" (sanitize "Distance (km/h)")
, TestCase $ assertEqual "Leading digit should be wrapped"
"_0_age_" (sanitize "0 Age")
, TestCase $ assertEqual "Valid camelCase should be unchanged"
"camelCaseStr" (sanitize "camelCaseStr")
, TestCase $ assertEqual "Valid camelCase with invalid characters mixed in"
"camelcase_str" (sanitize "camelCase$Str")
, TestCase $ assertEqual "Valid snake_case should remain unchanged"
"snake_case_str" (sanitize "snake_case_str")
, TestCase $ assertEqual "Leading digit with snake_case should be wrapped"
"_12_snake_case_" (sanitize "12_snake_case")
, TestCase $ assertEqual "All symbols should become underscores"
"_____" (sanitize "***")
]
tests :: [Test]
tests = pure $ TestLabel "sanitizeIdentifiers" sanitizeIdentifiers