Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_binary.nit
1 # This file is part of NIT (http://www.nitlanguage.org).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import binary
16
17 var path = "/tmp/bin"
18 var writer = new FileWriter.open(path)
19 #alt1# writer.big_endian = false
20 #alt3# writer.big_endian = false
21 writer.write "hello"
22 writer.write_byte 77
23 writer.write_float 1.23456789
24 writer.write_double 1.23456789
25 writer.write_int64 123456789
26 print writer.last_error or else "no error"
27 writer.close
28
29 var reader = new FileReader.open(path)
30 #alt2# reader.big_endian = false
31 #alt3# reader.big_endian = false
32 print reader.read(5)
33 var b = reader.read_byte
34 if b >= 0 then
35 print b
36 else
37 print "null"
38 end
39 print reader.read_float
40 print reader.read_double
41 print reader.read_int64
42 print reader.last_error or else "no error"
43 reader.close