-
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.
- Loading branch information
1 parent
8db7797
commit 653914c
Showing
5 changed files
with
237 additions
and
22 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
39 changes: 39 additions & 0 deletions
39
core/src/com/morganstanley/morphir/ir/advanced/Value.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,39 @@ | ||
package com.morganstanley.morphir.ir.advanced | ||
import com.morganstanley.morphir.ir.FQName | ||
|
||
object value { | ||
sealed abstract class Value[+X] | ||
object Value { | ||
type Lit = com.morganstanley.morphir.ir.advanced.value.Literal | ||
|
||
case class Literal[X](value: Lit, extra: X) extends Value[X] | ||
case class Constructor[X](fullyQualifiedName: FQName, extra: X) | ||
extends Value[X] | ||
} | ||
|
||
sealed abstract class Literal { | ||
def isBoolLiteral: Boolean = false | ||
def isCharLiteral: Boolean = false | ||
def isStringLiteral: Boolean = false | ||
def isIntLiteral: Boolean = false | ||
def isFloatLiteral: Boolean = false | ||
} | ||
|
||
object Literal { | ||
case class BoolLiteral(value: Boolean) extends Literal { | ||
override def isBoolLiteral: Boolean = true | ||
} | ||
case class CharLiteral(value: Char) extends Literal { | ||
override def isCharLiteral: Boolean = true | ||
} | ||
case class StringLiteral(value: String) extends Literal { | ||
override def isStringLiteral: Boolean = true | ||
} | ||
case class IntLiteral(value: Int) extends Literal { | ||
override def isIntLiteral: Boolean = true | ||
} | ||
case class FloatLiteral(value: Float) extends Literal { | ||
override def isFloatLiteral: Boolean = true | ||
} | ||
} | ||
} |
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
172 changes: 172 additions & 0 deletions
172
core/test/src/com/morganstanley/morphir/ir/advanced/ValueSpec.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,172 @@ | ||
package com.morganstanley.morphir.ir.advanced | ||
|
||
import zio.test._ | ||
import zio.test.Assertion._ | ||
import zio.test.environment._ | ||
|
||
object ValueSpec extends DefaultRunnableSpec { | ||
def spec = suite("ValueSpec")( | ||
suite("Literals")( | ||
suite("Given SUT is a BoolLiteral")( | ||
testM("Then SUT.isBoolLiteral should be true") { | ||
check(Gen.boolean) { input => | ||
val sut = value.Literal.BoolLiteral(input) | ||
assert(sut.isBoolLiteral)(isTrue) | ||
} | ||
}, | ||
testM("Then SUT.isCharLiteral should be false") { | ||
check(Gen.boolean) { input => | ||
val sut = value.Literal.BoolLiteral(input) | ||
assert(sut.isCharLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isFloatLiteral should be false") { | ||
check(Gen.boolean) { input => | ||
val sut = value.Literal.BoolLiteral(input) | ||
assert(sut.isFloatLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isIntLiteral should be false") { | ||
check(Gen.boolean) { input => | ||
val sut = value.Literal.BoolLiteral(input) | ||
assert(sut.isIntLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isStringLiteral should be false") { | ||
check(Gen.boolean) { input => | ||
val sut = value.Literal.BoolLiteral(input) | ||
assert(sut.isStringLiteral)(isFalse) | ||
} | ||
} | ||
), | ||
suite("Given SUT is a CharLiteral")( | ||
testM("Then SUT.isBoolLiteral should be false") { | ||
check(Gen.anyChar) { input => | ||
val sut = value.Literal.CharLiteral(input) | ||
assert(sut.isBoolLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isCharLiteral should be false") { | ||
check(Gen.anyChar) { input => | ||
val sut = value.Literal.CharLiteral(input) | ||
assert(sut.isCharLiteral)(isTrue) | ||
} | ||
}, | ||
testM("Then SUT.isFloatLiteral should be false") { | ||
check(Gen.anyChar) { input => | ||
val sut = value.Literal.CharLiteral(input) | ||
assert(sut.isFloatLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isIntLiteral should be false") { | ||
check(Gen.anyChar) { input => | ||
val sut = value.Literal.CharLiteral(input) | ||
assert(sut.isIntLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isStringLiteral should be false") { | ||
check(Gen.anyChar) { input => | ||
val sut = value.Literal.CharLiteral(input) | ||
assert(sut.isStringLiteral)(isFalse) | ||
} | ||
} | ||
), | ||
suite("Given SUT is a FloatLiteral")( | ||
testM("Then SUT.isBoolLiteral should be false") { | ||
check(Gen.anyFloat) { input => | ||
val sut = value.Literal.FloatLiteral(input) | ||
assert(sut.isBoolLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isCharLiteral should be false") { | ||
check(Gen.anyFloat) { input => | ||
val sut = value.Literal.FloatLiteral(input) | ||
assert(sut.isCharLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isFloatLiteral should be false") { | ||
check(Gen.anyFloat) { input => | ||
val sut = value.Literal.FloatLiteral(input) | ||
assert(sut.isFloatLiteral)(isTrue) | ||
} | ||
}, | ||
testM("Then SUT.isIntLiteral should be false") { | ||
check(Gen.anyFloat) { input => | ||
val sut = value.Literal.FloatLiteral(input) | ||
assert(sut.isIntLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isStringLiteral should be false") { | ||
check(Gen.anyFloat) { input => | ||
val sut = value.Literal.FloatLiteral(input) | ||
assert(sut.isStringLiteral)(isFalse) | ||
} | ||
} | ||
), | ||
suite("Given SUT is a IntLiteral")( | ||
testM("Then SUT.isBoolLiteral should be false") { | ||
check(Gen.anyInt) { input => | ||
val sut = value.Literal.IntLiteral(input) | ||
assert(sut.isBoolLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isCharLiteral should be false") { | ||
check(Gen.anyInt) { input => | ||
val sut = value.Literal.IntLiteral(input) | ||
assert(sut.isCharLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isFloatLiteral should be false") { | ||
check(Gen.anyInt) { input => | ||
val sut = value.Literal.IntLiteral(input) | ||
assert(sut.isFloatLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isIntLiteral should be false") { | ||
check(Gen.anyInt) { input => | ||
val sut = value.Literal.IntLiteral(input) | ||
assert(sut.isIntLiteral)(isTrue) | ||
} | ||
}, | ||
testM("Then SUT.isStringLiteral should be false") { | ||
check(Gen.anyInt) { input => | ||
val sut = value.Literal.IntLiteral(input) | ||
assert(sut.isStringLiteral)(isFalse) | ||
} | ||
} | ||
), | ||
suite("Given SUT is a StringLiteral")( | ||
testM("Then SUT.isBoolLiteral should be false") { | ||
check(Gen.anyString) { input => | ||
val sut = value.Literal.StringLiteral(input) | ||
assert(sut.isBoolLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isCharLiteral should be false") { | ||
check(Gen.anyString) { input => | ||
val sut = value.Literal.StringLiteral(input) | ||
assert(sut.isCharLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isFloatLiteral should be false") { | ||
check(Gen.anyString) { input => | ||
val sut = value.Literal.StringLiteral(input) | ||
assert(sut.isFloatLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isIntLiteral should be false") { | ||
check(Gen.anyString) { input => | ||
val sut = value.Literal.StringLiteral(input) | ||
assert(sut.isIntLiteral)(isFalse) | ||
} | ||
}, | ||
testM("Then SUT.isStringLiteral should be false") { | ||
check(Gen.anyString) { input => | ||
val sut = value.Literal.StringLiteral(input) | ||
assert(sut.isStringLiteral)(isTrue) | ||
} | ||
} | ||
) | ||
) | ||
) | ||
} |