src/doc: introduce option --no-render in HTML phase.
[nit.git] / tests / test_binary_deserialization.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 test_deserialization
16 import binary::serialization
17 #alt1# import test_deserialization_serial
18
19 class NoSerializeClass
20 super Serializable
21
22 var some_attribute: String
23 end
24
25 var entities = new TestEntities
26
27 var tests = entities.without_generics#alt1##alt2#
28 #alt1#var tests = entities.with_generics
29 #alt2#var tests = [new NoSerializeClass("will not deserialize")]
30
31 var dir = "out/test_binary_deserialization"
32 if not dir.file_exists then dir.mkdir
33
34 var path = dir / "alt0"#alt1##alt2#
35 #alt1#var path = dir / "alt1"
36 #alt2#var path = dir / "alt2"
37
38 var writer = new FileWriter.open(path)
39 var serializer = new BinarySerializer(writer)
40 for o in tests do
41 serializer.serialize o
42 end
43 writer.close
44
45 var reader = new FileReader.open(path)
46 var deserializer = new BinaryDeserializer(reader)
47 for o in tests do
48 var dst = deserializer.deserialize
49
50 if deserializer.errors.not_empty then
51 print deserializer.errors.join(", ")
52 end
53
54 if dst != null then
55 assert o.is_same_type(dst)
56
57 print "# Src:\n{o}"
58 print "# Dst:\n{dst}\n"
59 end
60 end
61 reader.close