-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |