@@ -346,59 +346,4 @@ def bit{ body: => Unit / { literal, BitSplices } }: Unit / emit[Bit] = {
346
346
}.reverse.each
347
347
resume(())
348
348
}
349
- }
350
-
351
- // Simple usage examples
352
- // =====================
353
- namespace examples {
354
- def main() = {
355
- mainSuite("Simple literals"){
356
- test("literal hex 10"){ assertEqual(x"10${()}", 16) }
357
- test("literal hex ff"){ assertEqual(x"ff${()}", 255) }
358
- test("literal char a"){ assertEqual(x"${'a'}", x"61${()}") }
359
- test("literal string ba"){ assertEqual(x"${"ba"}", x"62${()}" * 256 + x"61${()}") }
360
- test("int back-and-forth (17)"){ assertEqual(x"${17}", 17)}
361
- test("int back-and-forth (17), explicit BE"){ assertEqual(x"${17.BE}", 17) }
362
- test("int back-and-forth (17), explicit LE"){ assertEqual(x"${17.LE}", 17 * 256 * 256 * 256) }
363
- test("byte 00101010"){
364
- with on[MissingValue].default{ assertEqual(true, false) }
365
- assertEqual(first[Byte]{groupBytes{ bit"00101010${()}" }}.toInt, 42)
366
- }
367
- test("to bits and back"){
368
- with on[MissingValue].default{ assertEqual(true, false) }
369
- [42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
370
- assertEqual(first[Byte]{ groupBytes{ bits(v) } }, v)
371
- }
372
- }
373
- test("to bits and back LE bitorder"){
374
- with on[MissingValue].default{ assertEqual(true, false) }
375
- [42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
376
- assertEqual(first[Byte]{ groupBytesLE{ bitsLE(v) } }, v)
377
- }
378
- }
379
- test("to bits and back BE bitorder"){
380
- with on[MissingValue].default{ assertEqual(true, false) }
381
- [42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
382
- assertEqual(first[Byte]{ groupBytesBE{ bitsBE(v) } }, v)
383
- }
384
- }
385
- test("append 0 means *2"){
386
- with on[MissingValue].default{ assertEqual(true, false) }
387
- [42.toByte, 12.toByte, 127.toByte].foreach{ v =>
388
- assertEqual(nth[Byte](1){ groupBytes{ repeat(7){ do emit(B0()) }; bits(v); do emit(B0()) } }, (v.toInt * 2).toByte)
389
- }
390
- }
391
- test("pow agrees with double one"){
392
- assertEqual(pow(2,5), pow(2.0,5).toInt)
393
- }
394
- test("LE 2s-complement"){
395
- with on[MissingValue].default{ assertEqual(true, false) }
396
- assertEqual(first[Byte]{ groupBytesLE{ twoscomplementLE{ bitsLE(6.toByte) } } }, 250.toByte)
397
- }
398
- test("BE 2s-complement"){
399
- with on[MissingValue].default{ assertEqual(true, false) }
400
- assertEqual(first[Byte]{ groupBytesBE{ bit"${-6.Signed.BE.OfWidth(8)}" } }, 250.toByte)
401
- }
402
- }
403
- }
404
349
}
0 commit comments