-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding rest of ModuleModule and test (#62)
* adding rest of ModuleModule
- Loading branch information
1 parent
f0a018d
commit 648db65
Showing
3 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
morphir-ir/shared/src/test/scala/zio/morphir/ir/ModuleModuleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package zio.morphir.ir | ||
|
||
import zio.morphir.ir.ModuleModule.{Definition, Specification} | ||
import zio.{Chunk, ZEnvironment} | ||
import zio.morphir.ir.TypeModule.Definition.{CustomType, TypeAlias} | ||
import zio.morphir.ir.TypeModule.Specification.OpaqueTypeSpecification | ||
import zio.morphir.ir.TypeModule.Constructors | ||
import zio.morphir.syntax.AllSyntax | ||
import zio.morphir.testing.MorphirBaseSpec | ||
import zio.test.* | ||
|
||
object ModuleModuleSpec extends MorphirBaseSpec with AllSyntax { | ||
val items = Map { | ||
Name("type") -> Chunk((Name("var"), defineVariable("var1"))) | ||
Name("rainbow") -> Chunk((Name("red"), defineVariable("red"))) | ||
} | ||
|
||
val typeAlias = Documented( | ||
"doc", | ||
TypeAlias(Chunk(Name.fromString("hello")), defineVariable("type1")) | ||
) | ||
|
||
val customType = Documented( | ||
"doc", | ||
CustomType(Chunk(Name.fromString("world")), AccessControlled.publicAccess(Constructors(items))) | ||
) | ||
|
||
val definitionTypes = Map { | ||
Name("hello") -> AccessControlled.publicAccess(typeAlias) | ||
Name("world") -> AccessControlled.publicAccess(customType) | ||
} | ||
|
||
val definitionValues = Map { | ||
Name("val") -> AccessControlled.publicAccess( | ||
ValueModule.Definition.fromLiteral(string("string")) | ||
) | ||
} | ||
|
||
val moduleDef = Definition(definitionTypes, definitionValues) | ||
|
||
val specTypes = Map { | ||
Name("hello") -> Documented( | ||
"doc", | ||
OpaqueTypeSpecification(Chunk(Name("name1")), ZEnvironment.empty) | ||
) | ||
Name("world") -> Documented( | ||
"doc", | ||
OpaqueTypeSpecification(Chunk(Name("name2")), ZEnvironment.empty) | ||
) | ||
} | ||
|
||
val specValues = Map { | ||
Name("spec1") -> ValueModule.Specification( | ||
Chunk( | ||
(Name("type1"), defineVariable("Float")), | ||
(Name("type2"), defineVariable("Decimal")) | ||
), | ||
defineVariable("WholeNumbers") | ||
) | ||
} | ||
|
||
val moduleSpec = Specification(specTypes, specValues) | ||
|
||
def spec = suite("Type")( | ||
suite("Module Definition")( | ||
test("Can be turned to Specification") { | ||
// val expected = Specification(types = Map{ | ||
// Name("hello") -> typeAlias.map(_.toSpecification) | ||
// Name("world") -> customType.map(_.toSpecification) | ||
// }, | ||
// Map{ | ||
// Name("val") -> ValueModule.Definition.fromLiteral(string("string")).toSpecification | ||
// } | ||
// ) | ||
// assertTrue(moduleDef.toSpecification == expected) | ||
// todo add when TypeModule toSpec is added | ||
assertTrue(1 == 1) | ||
}, | ||
test("Can look up values") { | ||
val result = moduleDef.lookupValue(Name("val")) | ||
assertTrue(result.isDefined && result.get == ValueModule.Definition.fromLiteral(string("string"))) | ||
}, | ||
test("Can be erased") { | ||
assertTrue(moduleDef.eraseAttributes == Definition.empty) | ||
}, | ||
test("Can collect all references") { | ||
assertTrue( | ||
moduleDef.collectTypeReferences.size == 0 && | ||
moduleDef.collectValueReferences.size == 0 && | ||
moduleDef.collectValueReferences.size == 0 | ||
) | ||
} | ||
), | ||
suite("Module Specification")( | ||
test("Can look up values") { | ||
val result = moduleSpec.lookupValue(Name("spec1")) | ||
assertTrue( | ||
result.isDefined && result.get.inputs.size == 2 && result.get.output == defineVariable("WholeNumbers") | ||
) | ||
}, | ||
test("Can look up types") { | ||
val result = moduleSpec.lookupType(Name("world")) | ||
assertTrue( | ||
result.isDefined && !moduleSpec.lookupType(Name("notHere")).isDefined | ||
) | ||
}, | ||
test("Can be erased") { | ||
assertTrue(moduleSpec.eraseAttributes == Specification.empty) | ||
} | ||
) | ||
) | ||
} |