Skip to content

Commit 691200c

Browse files
Fix test for LLVM (assert, infixEq on Byte)
1 parent 28544c0 commit 691200c

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

examples/stdlib/binstream.effekt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,51 @@ import test
44

55
def main() = {
66
suite("Binstream", false){
7-
test("literal hex 10"){ assertEqual(x"10${()}", 16) }
8-
test("literal hex ff"){ assertEqual(x"ff${()}", 255) }
9-
test("literal char a"){ assertEqual(x"${'a'}", x"61${()}") }
10-
test("literal string ba"){ assertEqual(x"${"ba"}", x"62${()}" * 256 + x"61${()}") }
11-
test("int back-and-forth (17)"){ assertEqual(x"${17}", 17)}
12-
test("int back-and-forth (17), explicit BE"){ assertEqual(x"${17.BE}", 17) }
13-
test("int back-and-forth (17), explicit LE"){ assertEqual(x"${17.LE}", 17 * 256 * 256 * 256) }
7+
test("literal hex 10"){ assert(x"10${()}", 16) }
8+
test("literal hex ff"){ assert(x"ff${()}", 255) }
9+
test("literal char a"){ assert(x"${'a'}", x"61${()}") }
10+
test("literal string ba"){ assert(x"${"ba"}", x"62${()}" * 256 + x"61${()}") }
11+
test("int back-and-forth (17)"){ assert(x"${17}", 17)}
12+
test("int back-and-forth (17), explicit BE"){ assert(x"${17.BE}", 17) }
13+
test("int back-and-forth (17), explicit LE"){ assert(x"${17.LE}", 17 * 256 * 256 * 256) }
1414
test("byte 00101010"){
15-
with on[MissingValue].default{ assertEqual(true, false) }
16-
assertEqual(first[Byte]{groupBytes{ bit"00101010${()}" }}.toInt, 42)
15+
with on[MissingValue].default{ assert(true, false) }
16+
assert(first[Byte]{groupBytes{ bit"00101010${()}" }}.toInt, 42)
1717
}
1818
test("to bits and back"){
19-
with on[MissingValue].default{ assertEqual(true, false) }
19+
with on[MissingValue].default{ assert(true, false) }
2020
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
21-
assertEqual(first[Byte]{ groupBytes{ bits(v) } }, v)
21+
assert(first[Byte]{ groupBytes{ bits(v) } }, v)
2222
}
2323
}
2424
test("to bits and back LE bitorder"){
25-
with on[MissingValue].default{ assertEqual(true, false) }
25+
with on[MissingValue].default{ assert(true, false) }
2626
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
27-
assertEqual(first[Byte]{ groupBytesLE{ bitsLE(v) } }, v)
27+
assert(first[Byte]{ groupBytesLE{ bitsLE(v) } }, v)
2828
}
2929
}
3030
test("to bits and back BE bitorder"){
31-
with on[MissingValue].default{ assertEqual(true, false) }
31+
with on[MissingValue].default{ assert(true, false) }
3232
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
33-
assertEqual(first[Byte]{ groupBytesBE{ bitsBE(v) } }, v)
33+
assert(first[Byte]{ groupBytesBE{ bitsBE(v) } }, v)
3434
}
3535
}
3636
test("append 0 means *2"){
37-
with on[MissingValue].default{ assertEqual(true, false) }
37+
with on[MissingValue].default{ assert(true, false) }
3838
[42.toByte, 12.toByte, 127.toByte].foreach{ v =>
39-
assertEqual(nth[Byte](1){ groupBytes{ repeat(7){ do emit(B0()) }; bits(v); do emit(B0()) } }, (v.toInt * 2).toByte)
39+
assert(nth[Byte](1){ groupBytes{ repeat(7){ do emit(B0()) }; bits(v); do emit(B0()) } }, (v.toInt * 2).toByte)
4040
}
4141
}
4242
test("pow agrees with double one"){
43-
assertEqual(pow(2,5), pow(2.0,5).toInt)
43+
assert(pow(2,5), pow(2.0,5).toInt)
4444
}
4545
test("LE 2s-complement"){
46-
with on[MissingValue].default{ assertEqual(true, false) }
47-
assertEqual(first[Byte]{ groupBytesLE{ twoscomplementLE{ bitsLE(6.toByte) } } }, 250.toByte)
46+
with on[MissingValue].default{ assert(true, false) }
47+
assert(first[Byte]{ groupBytesLE{ twoscomplementLE{ bitsLE(6.toByte) } } }, 250.toByte)
4848
}
4949
test("BE 2s-complement"){
50-
with on[MissingValue].default{ assertEqual(true, false) }
51-
assertEqual(first[Byte]{ groupBytesBE{ bit"${-6.Signed.BE.OfWidth(8)}" } }, 250.toByte)
50+
with on[MissingValue].default{ assert(true, false) }
51+
assert(first[Byte]{ groupBytesBE{ bit"${-6.Signed.BE.OfWidth(8)}" } }, 250.toByte)
5252
}
5353
}
5454
()

libraries/common/effekt.effekt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ extern pure def infixNeq(x: Int, y: Int): Bool =
234234
"""
235235
vm "effekt::infixNeq(Int, Int)"
236236

237+
def infixEq(x: Byte, y: Byte): Bool = {
238+
x.toInt == y.toInt
239+
}
240+
237241
extern pure def infixEq(x: Char, y: Char): Bool =
238242
js "${x} === ${y}"
239243
chez "(equal? ${x} ${y})"

libraries/common/test.effekt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def assert(obtained: String, expected: String, msg: String): Unit / Assertion =
3333
def assert(obtained: Int, expected: Int): Unit / { Assertion, Formatted } =
3434
assertEqual(obtained, expected) { (x, y) => x == y } { x => show(x) }
3535

36+
def assert(obtained: Byte, expected: Byte): Unit / { Assertion, Formatted } =
37+
assertEqual(obtained, expected) { (x, y) => x == y } { x => show(x) }
38+
3639
def assert(obtained: Bool, expected: Bool): Unit / { Assertion, Formatted } =
3740
assertEqual(obtained, expected) { (x, y) => x == y } { x => show(x) }
3841

0 commit comments

Comments
 (0)