Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support string interpolation within Lists, nested Lists #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Data/Configurator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ flatten roots files = foldM doPath H.empty roots
Nothing -> return m
Just ds -> foldM (directive pfx (worth f)) m ds

directive pfx _ m (Bind name (String value)) = do
v <- interpolate pfx value m
return $! H.insert (T.append pfx name) (String v) m
directive pfx _ m (Bind name value) =
return $! H.insert (T.append pfx name) value m
directive pfx _ m (Bind name value) = do
vs <- interpStrings value
return $! H.insert (T.append pfx name) vs m
where
interpStrings (List vs) = List <$> mapM interpStrings vs
interpStrings (String v) = String <$> interpolate pfx v m
interpStrings v = return v
directive pfx f m (Group name xs) = foldM (directive pfx' f) m xs
where pfx' = T.concat [pfx, name, "."]
directive pfx f m (Import path) =
Expand Down
12 changes: 8 additions & 4 deletions tests/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ interpTest :: Assertion
interpTest =
withLoad "pathological.cfg" $ \cfg -> do
home <- getEnv "HOME"

cfgHome <- lookup cfg "ba"
assertEqual "home interp" (Just home) cfgHome

lookup cfg "xsinterp" >>=
assertEqual "nested home interp" (Just [[home]])

scopedInterpTest :: Assertion
scopedInterpTest = withLoad "interp.cfg" $ \cfg -> do
home <- getEnv "HOME"
Expand Down Expand Up @@ -195,7 +199,7 @@ reloadTest =
subscribe cfg "dongly" $ \ _ _ -> putMVar dongly ()
subscribe cfg "wongly" $ \ _ _ -> putMVar wongly ()
L.appendFile f "\ndongly = 1"
r1 <- takeMVarTimeout 2000 dongly
assertEqual "notify happened" r1 (Just ())
r2 <- takeMVarTimeout 2000 wongly
assertEqual "notify not happened" r2 Nothing
r1 <- takeMVarTimeout 5000 dongly
assertEqual "notify happened" (Just ()) r1
r2 <- takeMVarTimeout 5000 wongly
assertEqual "notify not happened" Nothing r2
2 changes: 2 additions & 0 deletions tests/resources/pathological.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ag { q-e { i_u9 { a=false}}}

ba = "$(HOME)"

xsinterp = [["$(HOME)"]]

xs = [1,2,3]

c = "x"