-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add TypeDescriptor for CUnion (#183)
* Add TypeDescriptor for CUnion Fixes #174 * chore: add unit tests for descriptor logic
- Loading branch information
1 parent
1fc1bf5
commit a33580c
Showing
20 changed files
with
150 additions
and
45 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
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
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
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
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
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,27 @@ | ||
package fr.hammons.slinc | ||
import types.* | ||
|
||
class TypeDescriptorSpec extends munit.FunSuite: | ||
case class A(a: CInt, b: CInt) derives Struct | ||
test("DescriptorOf[CUnion[(Int, Float, A)]] gives appropriate descriptor"): | ||
assertEquals( | ||
DescriptorOf[CUnion[(CInt, CFloat, A)]]: TypeDescriptor, | ||
CUnionDescriptor( | ||
Set(IntDescriptor, FloatDescriptor, summon[Struct[A]].descriptor) | ||
): TypeDescriptor | ||
) | ||
|
||
test( | ||
"DescriptorOf[CUnion[(CUnion[(Int, Float)], CUnion[(Int, Float)], A,A])]] doesn't double descriptors" | ||
): | ||
assertEquals( | ||
DescriptorOf[ | ||
CUnion[(CUnion[(Int, Float)], CUnion[(Int, Float)], A, A)] | ||
]: TypeDescriptor, | ||
CUnionDescriptor( | ||
Set( | ||
CUnionDescriptor(Set(IntDescriptor, FloatDescriptor)), | ||
summon[Struct[A]].descriptor | ||
) | ||
): TypeDescriptor | ||
) |
25 changes: 25 additions & 0 deletions
25
core/test/src/fr/hammons/slinc/modules/DescriptorSpec.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,25 @@ | ||
package fr.hammons.slinc.modules | ||
|
||
import fr.hammons.slinc.Slinc | ||
import fr.hammons.slinc.DescriptorOf | ||
import fr.hammons.slinc.types.CLongLong | ||
import fr.hammons.slinc.types.CInt | ||
import fr.hammons.slinc.types.CFloat | ||
import fr.hammons.slinc.CUnion | ||
import fr.hammons.slinc.Struct | ||
|
||
trait DescriptorSpec(val slinc: Slinc) extends munit.FunSuite: | ||
import slinc.dm | ||
case class A(a: CInt, b: CInt, c: CInt, d: CLongLong, e: CLongLong) | ||
derives Struct | ||
test("CUnionDescriptor.size gives the right size"): | ||
assertEquals( | ||
DescriptorOf[CUnion[(CInt, A, CFloat)]].size, | ||
DescriptorOf[A].size | ||
) | ||
|
||
test("CUnionDescriptor.alignment gives the right alignment"): | ||
assertEquals( | ||
DescriptorOf[CUnion[(CInt, A, CFloat)]].alignment, | ||
DescriptorOf[A].alignment | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fr.hammons.slinc.modules | ||
|
||
import fr.hammons.slinc.Slinc17 | ||
|
||
class Descriptor17Spec extends DescriptorSpec(Slinc17.default) |
Oops, something went wrong.