Skip to content

Commit

Permalink
test: add big/little endian 16 bit tests
Browse files Browse the repository at this point in the history
Test that the exported lisp functions behave as expected
when writing and reading big and little endian 16 bit values
to and from lone lisp bytes objects.
  • Loading branch information
matheusmoreira committed Sep 11, 2024
1 parent 3e0e41b commit 4cc31f2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/lone/lisp/modules/intrinsic/bytes/write-then-read/16/input
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
(math /)
(bytes
new
read-u16 write-u16
read-s16 write-s16))
read-u16 write-u16
read-s16 write-s16
read-u16le write-u16le
read-s16le write-s16le
read-u16be write-u16be
read-s16be write-s16be))

(set max-bits 16)
(set memory (new (/ max-bits 8)))
Expand All @@ -16,3 +20,31 @@
(print (write-s16 memory 0 -30000))
(print (read-u16 memory 0))
(print (read-s16 memory 0))

(print (write-u16le memory 0 +60000))
(print memory)
(print (read-u16le memory 0))
(print (read-s16le memory 0))
(print (read-u16be memory 0))
(print (read-s16be memory 0))

(print (write-u16be memory 0 +60000))
(print memory)
(print (read-u16le memory 0))
(print (read-s16le memory 0))
(print (read-u16be memory 0))
(print (read-s16be memory 0))

(print (write-s16le memory 0 -30000))
(print memory)
(print (read-u16le memory 0))
(print (read-s16le memory 0))
(print (read-u16be memory 0))
(print (read-s16be memory 0))

(print (write-s16be memory 0 -30000))
(print memory)
(print (read-u16le memory 0))
(print (read-s16le memory 0))
(print (read-u16be memory 0))
(print (read-s16be memory 0))
24 changes: 24 additions & 0 deletions test/lone/lisp/modules/intrinsic/bytes/write-then-read/16/output
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@
-30000
35536
-30000
60000
bytes[0x60EA]
60000
-5536
24810
24810
60000
bytes[0xEA60]
24810
24810
60000
-5536
-30000
bytes[0xD08A]
35536
-30000
53386
-12150
-30000
bytes[0x8AD0]
53386
-12150
35536
-30000

0 comments on commit 4cc31f2

Please sign in to comment.