aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-09 23:52:58 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-09 23:52:58 +0200
commit8baa85fd4c3607a7b3cebf2518a930a3b8a924bf (patch)
tree20b98351aca4edc8635e34b96d779bcecd9d8e19 /test
parent8ba98a86805c886719057f9df0d5a74c58c6dabd (diff)
Add atom data type
Diffstat (limited to 'test')
-rw-r--r--test/Spec.hs11
-rw-r--r--test/TestUtils.hs3
-rw-r--r--test/scripts/atom1.milch14
3 files changed, 27 insertions, 1 deletions
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 "<test>" 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