Skip to content

Commit

Permalink
Add unit tests for cpp file selection
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffany1618 committed Jul 25, 2023
1 parent 57c040c commit 1ec2cb9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
69 changes: 64 additions & 5 deletions compiler/lib/test/codegen/CppWriter/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import fpp.compiler.codegen._
import CppDoc._

object Program extends LineUtils {
val includeHeader = List(
Line.blank,
line("#include \"C.hpp\"")
)

val cppDoc = CppDoc(
description = "CppDoc test",
Expand All @@ -10,13 +14,17 @@ object Program extends LineUtils {
members = List(
Member.Lines(
lines = Lines(
content = List(
Line.blank,
line("#include \"C.hpp\"")
),
content = includeHeader,
output = Lines.Cpp
)
),
Member.Lines(
lines = Lines(
content = includeHeader,
output = Lines.Cpp,
cppFile = Some("Other")
)
),
Member.Namespace(
namespace = Namespace(
name = "N",
Expand Down Expand Up @@ -80,7 +88,10 @@ object Program extends LineUtils {
)
),
retType = Type("void"),
body = Nil
body = Nil,
CppDoc.Function.NonSV,
CppDoc.Function.NonConst,
Some("Other")
)
),
)
Expand Down Expand Up @@ -178,6 +189,44 @@ object Program extends LineUtils {
)
)
)
),
Member.Namespace(
namespace = Namespace(
name = "M",
members = List(
Member.Class(
CppDoc.Class(
comment = None,
name = "M",
superclassDecls = None,
members = List(
Class.Member.Lines(
lines = Lines(
content = CppDocHppWriter.writeAccessTag("public")
)
),
Class.Member.Constructor(
constructor = Class.Constructor(
comment = Some("This is line 1.\n\nThis is line 3."),
params = Nil,
initializers = Nil,
body = lines("// line1\n// line2"),
Some("Other")
)
),
Class.Member.Destructor(
Class.Destructor(
comment = Some("This is line 1.\nThis is line 2."),
body = lines("// Body line 1\n// Body line 2"),
Class.Destructor.Virtual,
Some("Other")
)
),
)
)
)
)
)
)
)
)
Expand All @@ -203,3 +252,13 @@ object cpp {
}

}

object otherCpp {

def main(args: Array[String]): Unit = {
val output = CppDocCppWriter.visitCppDoc(Program.cppDoc, Some("Other"))
output.map(Line.write(Line.stdout) _)
()
}

}
3 changes: 3 additions & 0 deletions compiler/lib/test/codegen/CppWriter/otherCpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

scala otherCpp
3 changes: 2 additions & 1 deletion compiler/lib/test/codegen/CppWriter/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ cpp_doc_ok()
{
./hpp > C.hpp && \
./cpp > C.cpp && \
gcc -c C.cpp
./otherCpp > Other.cpp && \
gcc -c C.cpp Other.cpp
}

tests="
Expand Down

0 comments on commit 1ec2cb9

Please sign in to comment.