Skip to content

Commit 63cf0a1

Browse files
committed
chore: add tests for transforms
1 parent 6aedec4 commit 63cf0a1

File tree

9 files changed

+55
-184
lines changed

9 files changed

+55
-184
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
- uses: VirtusLab/scala-cli-setup@v0.1.20
2121
with:
2222
jvm: temurin:1.${{ matrix.jvm }}
23-
apps: mill
24-
- run: mill j${{ matrix.jvm }}.benchmarks.test -f1 -wi 2 -i 2 -o j${{ matrix.jvm }}-${{ matrix.os }}.bench -rff j${{ matrix.jvm }}-${{ matrix.os }}.json -rf json .*${{ matrix.benchmark }}${{ matrix.jit }}.*
23+
- run: ./mill j${{ matrix.jvm }}.benchmarks.test -f1 -wi 2 -i 2 -o j${{ matrix.jvm }}-${{ matrix.os }}.bench -rff j${{ matrix.jvm }}-${{ matrix.os }}.json -rf json .*${{ matrix.benchmark }}${{ matrix.jit }}.*
2524
- run: scala-cli run scripts/PublishBenchmarkReport.sc -- "Java ${{ matrix.jvm}}" ${{ matrix.os }} out/j${{ matrix.jvm }}/benchmarks/test/jmhRun.dest/j${{ matrix.jvm }}-${{ matrix.os }}.json ${{ matrix.benchmark }} ${{ matrix.jit }} >> $GITHUB_STEP_SUMMARY
2625
- uses: actions/upload-artifact@v3
2726
with:

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ jobs:
1515
- uses: coursier/setup-action@v1.3.0
1616
with:
1717
jvm: temurin:1.17
18-
apps: mill
19-
- run: mill mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
18+
- run: ./mill mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
2019

2120
unit-tests:
2221
strategy:

core/src/fr/hammons/slinc/DescriptorOf.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ object DescriptorOf:
5858
given DescriptorOf[VarArgs] with
5959
val descriptor: TypeDescriptor { type Inner = VarArgs } = VaListDescriptor
6060

61+
given [A](using t: Transform[A, ?]): DescriptorOf[A] = t
62+
6163
def getDescriptorFor[A](using Quotes, Type[A]) =
6264
import quotes.reflect.*
6365
val expr = Expr

core/src/fr/hammons/slinc/Transform.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,3 @@ trait Transform[A, B](using val desc: DescriptorOf[B])(
1111
type Inner = A
1212
val transformFrom = _transformFrom
1313
val transformTo = _transformTo
14-
15-
object Transform:
16-
given Transform[Boolean, Byte](
17-
b => if b != (0: Byte) then true else false,
18-
b => if b then 1: Byte else 0: Byte
19-
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
package fr.hammons.slinc.types
22

3+
import fr.hammons.slinc.Transform
4+
35
type CChar = Byte
46
type CShort = Short
57
type CInt = Int
68
type CFloat = Float
79
type CDouble = Double
810
type CLongLong = Long
11+
12+
opaque type CBool >: Boolean <: Boolean = Boolean
13+
14+
object CBool:
15+
given Transform[CBool, Byte](
16+
b => if b != (0: Byte) then true else false,
17+
b => if b then 1: Byte else 0: Byte
18+
)
19+
20+
opaque type CBoolShort >: Boolean <: Boolean = Boolean
21+
22+
object CBoolShort:
23+
given Transform[CBoolShort, Short](
24+
s => if s != (0: Short) then true else false,
25+
b => if b then 1: Short else 0: Short
26+
)

core/test/native/test.c

Lines changed: 0 additions & 174 deletions
This file was deleted.

core/test/resources/native/test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ EXPORTED int* i180_test(int my_array[5]) {
147147
i++;
148148
}
149149
return my_array;
150+
}
151+
152+
EXPORTED char i213_test(char bool) {
153+
return bool;
150154
}

core/test/src/fr/hammons/slinc/BindingSpec.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ trait BindingSpec(val slinc: Slinc) extends ScalaCheckSuite:
6363
input: SetSizeArray[CInt, 5]
6464
): SetSizeArray[CInt, 5]
6565

66+
def i213_test(b: CBool): CBool
67+
6668
test("int_identity") {
6769
val test = FSet.instance[TestLib]
6870

@@ -198,3 +200,8 @@ trait BindingSpec(val slinc: Slinc) extends ScalaCheckSuite:
198200
val retArr = test.i180_test(arr)
199201

200202
retArr.zip(arr.map(_ * 2)).foreach(assertEquals(_, _))
203+
204+
property("issue 213 - can send and receive boolean values"):
205+
val test = FSet.instance[TestLib]
206+
forAll: (b: Boolean) =>
207+
assertEquals(test.i213_test(b), b)

core/test/src/fr/hammons/slinc/TypeDescriptorSpec.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ class TypeDescriptorSpec extends munit.FunSuite:
2525
)
2626
): TypeDescriptor
2727
)
28+
29+
test("Transforms work in place of DescriptorOfs"):
30+
val result = compileErrors(
31+
"""
32+
import fr.hammons.slinc.types.*
33+
34+
trait Test derives FSet{
35+
def test(a: CBool): CBool
36+
def test2(a: CBoolShort): CBoolShort
37+
}
38+
39+
val runtime: Slinc = ???
40+
41+
import runtime.{*,given}
42+
val test = FSet.instance[Test]
43+
44+
val bool: Boolean = test.test(true)
45+
val bool2: Boolean = test.test2(true)
46+
"""
47+
)
48+
49+
assertNoDiff(result, "")

0 commit comments

Comments
 (0)