From 8baa85fd4c3607a7b3cebf2518a930a3b8a924bf Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 9 Dec 2022 23:52:58 +0200 Subject: Add atom data type --- test/Spec.hs | 11 +++++++++++ test/TestUtils.hs | 3 ++- test/scripts/atom1.milch | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/scripts/atom1.milch (limited to 'test') diff --git a/test/Spec.hs b/test/Spec.hs index 4839ace..68e575c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -126,7 +126,18 @@ e2eTests = testGroup "e2e" [ let expectedLastAST = astRecord "Result/Ex" $ M.fromList [("value", astString "failed to read file: does-not-exist.txt")] + assertEqual "" expectedLastAST (last gotASTs), + + do let env = builtinEnv + script1 <- readFile "test/scripts/atom1.milch" + (gotASTs, gotState) <- expectSuccessL env $ runInlineScript "" script1 + + let expectedLastAST = astInteger 15 assertEqual "" expectedLastAST (last gotASTs) + + let expectedAtomMap = M.singleton (LAtomRef 1) (astInteger 15) + let gotAtomMap = stateAtomMap gotState + assertEqual "" expectedAtomMap gotAtomMap ] testGroup label xs = TestLabel label $ TestList $ map TestCase xs diff --git a/test/TestUtils.hs b/test/TestUtils.hs index ff53310..89bc6e6 100644 --- a/test/TestUtils.hs +++ b/test/TestUtils.hs @@ -20,7 +20,8 @@ testRunL env = runL LState { stateConfig = testConfig, stateEnv = env, stateDepth = 0, - statePure = Impure + statePure = Impure, + stateAtomMap = M.empty } expectSuccessL :: Env -> LContext a -> IO (a, LState) diff --git a/test/scripts/atom1.milch b/test/scripts/atom1.milch new file mode 100644 index 0000000..0ee6f8f --- /dev/null +++ b/test/scripts/atom1.milch @@ -0,0 +1,14 @@ +(import "core/common") + +(let state (atom! 10)) + +(let do-loop! (\![i n] + (match true + (lt? i n) (do (atom-update! inc state) + (do-loop! (inc i) n)) + otherwise unit))) + +(do-loop! 0 5) + +(atom-get! state) +; => 15 -- cgit v1.3