quebex

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/quebex.git

 1-- SPDX-FileCopyrightText: 2026 Sören Tempel <soeren+git@soeren-tempel.net>
 2--
 3-- SPDX-License-Identifier: GPL-3.0-only
 4{-# LANGUAGE OverloadedStrings #-}
 5
 6module KTest (ktestTests) where
 7
 8import Data.Binary (decode, encode)
 9import Data.ByteString.Lazy qualified as BL
10import Data.KTest
11import Test.Tasty
12import Test.Tasty.HUnit
13
14rawDecode :: FilePath -> IO (KTest, BL.ByteString)
15rawDecode fp = do
16  content <- BL.readFile fp
17  pure (decode content, content)
18
19------------------------------------------------------------------------
20
21ktestTests :: TestTree
22ktestTests =
23  testGroup
24    "KTest"
25    [ testCase "single-variable.ktest" $ do
26        (ktest, content) <- rawDecode "test/testdata/single-variable.ktest"
27
28        let expected =
29              KTest
30                { ktArgs = ["shift-test.bc"],
31                  ktObjs =
32                    [ KTestObj
33                        { objName = "x",
34                          objBytes = "\NUL\NUL\NUL\NUL"
35                        }
36                    ]
37                }
38
39        ktest @?= expected
40        encode expected @?= content,
41      testCase "multiple-variables.ktest" $ do
42        (ktest, content) <- rawDecode "test/testdata/multiple-variables.ktest"
43
44        let expected =
45              KTest
46                { ktArgs = ["main.bc"],
47                  ktObjs =
48                    [ KTestObj "first" "\NUL\NUL\NUL@",
49                      KTestObj "second" "\SOH\NUL\NUL@"
50                    ]
51                }
52
53        ktest @?= expected
54        encode expected @?= content
55    ]