diff options
| author | Jack | 2017-11-28 16:15:08 -0500 |
|---|---|---|
| committer | Adam Izraelevitz | 2017-11-28 18:16:57 -0800 |
| commit | d8e9fc3d84c06c546440b1ef821cd1e3626b62e6 (patch) | |
| tree | 8562e2f2508b8e29de0f590a7b5f8ed5322be8fc /src/test | |
| parent | 50a3641dd9700c1899198f13bc1362db78e25b79 (diff) | |
Refactor RenameMap to rename Components if their Module is renamed
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/firrtlTests/RenameMapSpec.scala | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/RenameMapSpec.scala b/src/test/scala/firrtlTests/RenameMapSpec.scala new file mode 100644 index 00000000..9d19bb72 --- /dev/null +++ b/src/test/scala/firrtlTests/RenameMapSpec.scala @@ -0,0 +1,74 @@ +// See LICENSE for license details. + +package firrtlTests + +import firrtl.RenameMap +import firrtl.annotations.{ + CircuitName, + ModuleName, + ComponentName +} + +class RenameMapSpec extends FirrtlFlatSpec { + val cir = CircuitName("Top") + val modA = ModuleName("A", cir) + val modB = ModuleName("B", cir) + val foo = ComponentName("foo", modA) + val bar = ComponentName("bar", modA) + val fizz = ComponentName("fizz", modA) + val fooB = ComponentName("foo", modB) + val barB = ComponentName("bar", modB) + + behavior of "RenameMap" + + it should "return None if it does not rename something" in { + val renames = RenameMap() + renames.get(modA) should be (None) + renames.get(foo) should be (None) + } + + it should "return a Seq of renamed things if it does rename something" in { + val renames = RenameMap() + renames.rename(foo, bar) + renames.get(foo) should be (Some(Seq(bar))) + } + + it should "allow something to be renamed to multiple things" in { + val renames = RenameMap() + renames.rename(foo, bar) + renames.rename(foo, fizz) + renames.get(foo) should be (Some(Seq(bar, fizz))) + } + + it should "allow something to be renamed to nothing (ie. deleted)" in { + val renames = RenameMap() + renames.rename(foo, Seq()) + renames.get(foo) should be (Some(Seq())) + } + + it should "return None if something is renamed to itself" in { + val renames = RenameMap() + renames.rename(foo, foo) + renames.get(foo) should be (None) + } + + it should "allow components to change module" in { + val renames = RenameMap() + renames.rename(foo, fooB) + renames.get(foo) should be (Some(Seq(fooB))) + } + + it should "rename components if their module is renamed" in { + val renames = RenameMap() + renames.rename(modA, modB) + renames.get(foo) should be (Some(Seq(fooB))) + renames.get(bar) should be (Some(Seq(barB))) + } + + it should "rename renamed components if the module of the target component is renamed" in { + val renames = RenameMap() + renames.rename(modA, modB) + renames.rename(foo, bar) + renames.get(foo) should be (Some(Seq(barB))) + } +} |
