tests: test the binary reading and writing
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 19 May 2015 01:07:20 +0000 (21:07 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 19 May 2015 16:24:08 +0000 (12:24 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

tests/sav/test_binary.res [new file with mode: 0644]
tests/sav/test_binary_alt1.res [new file with mode: 0644]
tests/sav/test_binary_alt2.res [new file with mode: 0644]
tests/sav/test_binary_alt3.res [new file with mode: 0644]
tests/test_binary.nit [new file with mode: 0644]

diff --git a/tests/sav/test_binary.res b/tests/sav/test_binary.res
new file mode 100644 (file)
index 0000000..f071d47
--- /dev/null
@@ -0,0 +1,7 @@
+no error
+hello
+77
+1.235
+1.235
+123456789
+no error
diff --git a/tests/sav/test_binary_alt1.res b/tests/sav/test_binary_alt1.res
new file mode 100644 (file)
index 0000000..eb0468f
--- /dev/null
@@ -0,0 +1,7 @@
+no error
+hello
+77
+144545136640.0
+0.0
+1571011930645069824
+no error
diff --git a/tests/sav/test_binary_alt2.res b/tests/sav/test_binary_alt2.res
new file mode 100644 (file)
index 0000000..eb0468f
--- /dev/null
@@ -0,0 +1,7 @@
+no error
+hello
+77
+144545136640.0
+0.0
+1571011930645069824
+no error
diff --git a/tests/sav/test_binary_alt3.res b/tests/sav/test_binary_alt3.res
new file mode 100644 (file)
index 0000000..f071d47
--- /dev/null
@@ -0,0 +1,7 @@
+no error
+hello
+77
+1.235
+1.235
+123456789
+no error
diff --git a/tests/test_binary.nit b/tests/test_binary.nit
new file mode 100644 (file)
index 0000000..a38619b
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT (http://www.nitlanguage.org).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import binary
+
+var path = "/tmp/bin"
+var writer = new FileWriter.open(path)
+#alt1# writer.big_endian = false
+#alt3# writer.big_endian = false
+writer.write "hello"
+writer.write_byte 77
+writer.write_float 1.23456789
+writer.write_double 1.23456789
+writer.write_int64 123456789
+print writer.last_error or else "no error"
+writer.close
+
+var reader = new FileReader.open(path)
+#alt2# reader.big_endian = false
+#alt3# reader.big_endian = false
+print reader.read(5)
+print reader.read_byte or else "null"
+print reader.read_float
+print reader.read_double
+print reader.read_int64
+print reader.last_error or else "no error"
+reader.close