Skip to content

Commit

Permalink
add: utils test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol committed Jan 19, 2025
1 parent e88bc8e commit af26d16
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/Codegen/UtilsSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{-# LANGUAGE OverloadedStrings #-}

module Codegen.UtilsSpec (spec) where

import qualified Codegen.Utils as CU
import qualified Data.ByteString.Short as BS
import qualified LLVM.AST as AST
import qualified Test.Hspec as H

spec :: H.Spec
spec = H.describe "Codegen.Utils" $ do
H.describe "stringToByteString" $ do
H.it "should convert empty string" $ do
CU.stringToByteString "" `H.shouldBe` BS.empty

H.it "should convert ASCII string" $ do
CU.stringToByteString "hello" `H.shouldBe` BS.pack [104, 101, 108, 108, 111]

H.it "should convert string with special characters" $ do
CU.stringToByteString "hello\n\t" `H.shouldBe` BS.pack [104, 101, 108, 108, 111, 10, 9]

H.describe "byteStringToString" $ do
H.it "should convert empty bytestring" $ do
CU.byteStringToString BS.empty `H.shouldBe` ""

H.it "should convert ASCII bytestring" $ do
CU.byteStringToString (BS.pack [104, 101, 108, 108, 111]) `H.shouldBe` "hello"

H.it "should convert bytestring with special characters" $ do
CU.byteStringToString (BS.pack [104, 101, 108, 108, 111, 10, 9]) `H.shouldBe` "hello\n\t"

H.describe "nameToString" $ do
H.it "should convert named identifier" $ do
CU.nameToString (AST.Name "test") `H.shouldBe` "test"

H.it "should convert unnamed identifier" $ do
CU.nameToString (AST.UnName 42) `H.shouldBe` "42"

H.it "should convert empty named identifier" $ do
CU.nameToString (AST.Name "") `H.shouldBe` ""

H.it "should handle special characters in named identifier" $ do
CU.nameToString (AST.Name "_test.123") `H.shouldBe` "_test.123"

0 comments on commit af26d16

Please # to comment.