Skip to content

Commit

Permalink
add tests to printing Scala code - fix extra space after package decl…
Browse files Browse the repository at this point in the history
…aration
  • Loading branch information
lemastero committed Apr 30, 2024
1 parent 8ea4c25 commit 4b76a54
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
6 changes: 4 additions & 2 deletions agda2scala.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ common warnings
library
hs-source-dirs: src
exposed-modules: Agda.Compiler.Scala.Backend
Agda.Compiler.Scala.Expr
Agda.Compiler.Scala.ScalaExpr
Agda.Compiler.Scala.AgdaToScalaExpr
Agda.Compiler.Scala.PrintScalaExpr
Paths_agda2scala
autogen-modules: Paths_agda2scala
build-depends: base >= 4.10 && < 4.20,
Expand All @@ -55,7 +57,7 @@ test-suite agda2scala-test
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: ScalaBackendTest.hs
main-is: Main.hs
build-depends: base >=4.10 && < 4.20,
Agda >= 2.6.4 && < 2.6.5,
HUnit >= 1.6.2.0,
Expand Down
19 changes: 19 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Main (main) where

import Test.HUnit (
Test(..)
, failures
, runTestTT
)
import System.Exit ( exitFailure , exitSuccess )

import PrintScalaExprTest ( printScalaTests )
import ScalaBackendTest ( backendTests )

allTests :: Test
allTests = TestList [ backendTests , printScalaTests ]

main :: IO ()
main = do
result <- runTestTT allTests
if (failures result) > 0 then exitFailure else exitSuccess
27 changes: 27 additions & 0 deletions test/PrintScalaExprTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module PrintScalaExprTest ( printScalaTests ) where

import Test.HUnit ( Test(..), assertEqual )
import Agda.Compiler.Scala.PrintScalaExpr (
printSealedTrait
, printCaseObject
, printPackage
)

testPrintCaseObject :: Test
testPrintCaseObject = TestCase
(assertEqual "printCaseObject" (printCaseObject "Color" "Light") "case object Light extends Color")

testPrintSealedTrait :: Test
testPrintSealedTrait = TestCase
(assertEqual "printSealedTrait" (printSealedTrait "Color") "sealed trait Color")

testPrintPackage :: Test
testPrintPackage = TestCase
(assertEqual "printPackage" (printPackage "adts") "package adts")

printScalaTests :: Test
printScalaTests = TestList [
TestLabel "printCaseObject" testPrintCaseObject
, TestLabel "printSealedTrait" testPrintSealedTrait
, TestLabel "printPackage" testPrintPackage
]
20 changes: 5 additions & 15 deletions test/ScalaBackendTest.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
module Main (main) where
module ScalaBackendTest ( backendTests ) where

import Agda.Compiler.Scala.Backend ( scalaBackend', defaultOptions )
import Test.HUnit (
Test(..)
, assertEqual
, failures
, runTestTT)
import System.Exit ( exitFailure , exitSuccess )
import Test.HUnit ( Test(..), assertEqual )
import Agda.Compiler.Backend ( isEnabled )
import Agda.Compiler.Scala.Backend ( scalaBackend', defaultOptions )

testIsEnabled :: Test
testIsEnabled = TestCase
(assertEqual "isEnabled" (isEnabled scalaBackend' defaultOptions) True)

tests :: Test
tests = TestList [TestLabel "scalaBackend" testIsEnabled]

main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then exitFailure else exitSuccess
backendTests :: Test
backendTests = TestList [TestLabel "scalaBackend" testIsEnabled]

0 comments on commit 4b76a54

Please sign in to comment.