diff options
| author | jackkoenig | 2016-09-20 16:12:59 -0700 |
|---|---|---|
| committer | jackkoenig | 2016-09-21 20:18:06 -0700 |
| commit | 7e5aef460e089b3dfd53ddd181f9384cc25145d7 (patch) | |
| tree | d4642495686b50476d6569ebbc522d2d10923a9e /src/test/scala/cookbook/UInt2Bundle.scala | |
| parent | b18e98ba2d058c7dd24f96f005486b70c856aeca (diff) | |
Add Cookbook tests
These tests are intended to be the examples in the Chisel3 Wiki Cookbook.
Diffstat (limited to 'src/test/scala/cookbook/UInt2Bundle.scala')
| -rw-r--r-- | src/test/scala/cookbook/UInt2Bundle.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/scala/cookbook/UInt2Bundle.scala b/src/test/scala/cookbook/UInt2Bundle.scala new file mode 100644 index 00000000..fbf7fe8a --- /dev/null +++ b/src/test/scala/cookbook/UInt2Bundle.scala @@ -0,0 +1,30 @@ +// See LICENSE for license details. + +package cookbook + +import chisel3._ + +/* ### How do I create a Bundle from a UInt? + * + * On an instance of the Bundle, call the method fromBits with the UInt as the argument + */ +class UInt2Bundle extends CookbookTester(0) { + // Example + class MyBundle extends Bundle { + val foo = UInt(width = 4) + val bar = UInt(width = 4) + } + val uint = UInt(0xb4) + val bundle = (new MyBundle).fromBits(uint) + printf(p"$bundle") // Bundle(foo -> 11, bar -> 4) + + // Test + assert(bundle.foo === UInt(0xb)) + assert(bundle.bar === UInt(0x4)) +} + +class UInt2BundleSpec extends CookbookSpec { + "UInt2Bundle" should "work" in { + assertTesterPasses { new UInt2Bundle } + } +} |
