summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/OptionBundle.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests/OptionBundle.scala')
-rw-r--r--src/test/scala/chiselTests/OptionBundle.scala62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/test/scala/chiselTests/OptionBundle.scala b/src/test/scala/chiselTests/OptionBundle.scala
deleted file mode 100644
index 628e117d..00000000
--- a/src/test/scala/chiselTests/OptionBundle.scala
+++ /dev/null
@@ -1,62 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-
-package chiselTests
-
-import chisel3._
-import chisel3.stage.ChiselStage
-import chisel3.testers.BasicTester
-
-class OptionBundle(val hasIn: Boolean) extends Bundle {
- val in = if (hasIn) {
- Some(Input(Bool()))
- } else {
- None
- }
- val out = Output(Bool())
-}
-
-class OptionBundleModule(val hasIn: Boolean) extends Module {
- val io = IO(new OptionBundle(hasIn))
- if (hasIn) {
- io.out := io.in.get
- } else {
- io.out := false.B
- }
-}
-
-class SomeOptionBundleTester(expected: Boolean) extends BasicTester {
- val mod = Module(new OptionBundleModule(true))
- mod.io.in.get := expected.asBool
- assert(mod.io.out === expected.asBool)
- stop()
-}
-
-class NoneOptionBundleTester() extends BasicTester {
- val mod = Module(new OptionBundleModule(false))
- assert(mod.io.out === false.B)
- stop()
-}
-
-class InvalidOptionBundleTester() extends BasicTester {
- val mod = Module(new OptionBundleModule(false))
- mod.io.in.get := true.B
- assert(false.B)
- stop()
-}
-
-class OptionBundleSpec extends ChiselFlatSpec with Utils {
- "A Bundle with an Option field" should "work properly if the Option field is not None" in {
- assertTesterPasses { new SomeOptionBundleTester(true) }
- assertTesterPasses { new SomeOptionBundleTester(false) }
- }
-
- "A Bundle with an Option field" should "compile if the Option field is None" in {
- assertTesterPasses { new NoneOptionBundleTester() }
- }
-
- "A Bundle with an Option field" should "assert out accessing a None Option field" in {
- a[Exception] should be thrownBy extractCause[Exception] {
- ChiselStage.elaborate { new InvalidOptionBundleTester() }
- }
- }
-}