iotdb/lib.rs
1//
2// Licensed to the Apache Software Foundation (ASF) under one
3// or more contributor license agreements. See the NOTICE file
4// distributed with this work for additional information
5// regarding copyright ownership. The ASF licenses this file
6// to you under the Apache License, Version 2.0 (the
7// "License"); you may not use this file except in compliance
8// with the License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing,
13// software distributed under the License is distributed on an
14// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15// KIND, either express or implied. See the License for the
16// specific language governing permissions and limitations
17// under the License.
18//
19pub mod client;
20pub mod protocal;
21
22#[cfg(test)]
23mod tests {
24 use crate::client::Value;
25 use std::vec::Vec;
26
27 #[test]
28 fn test_value_to_string() {
29 let values = vec![
30 Value::Bool(true),
31 Value::Int32(1),
32 Value::Int64(2),
33 Value::Float(3.1),
34 Value::Double(4.1),
35 Value::Text(String::from("iotdb")),
36 Value::Null,
37 ];
38
39 let strings = vec!["true", "1", "2", "3.1", "4.1", "iotdb", "null"];
40
41 for (v, s) in values.into_iter().zip(strings.into_iter()) {
42 assert_eq!(v.to_string(), s);
43 }
44 }
45
46 #[test]
47 fn test_value_into() {
48 let values = vec![
49 Value::Bool(true),
50 Value::Int32(1),
51 Value::Int64(2),
52 Value::Float(3.1),
53 Value::Double(4.1),
54 Value::Text(String::from("iotdb")),
55 ];
56
57 let bytes = vec![
58 vec![0u8, 1u8],
59 vec![vec![1u8], 1_i32.to_be_bytes().to_vec()]
60 .into_iter()
61 .flatten()
62 .collect(),
63 vec![vec![2u8], 2_i64.to_be_bytes().to_vec()]
64 .into_iter()
65 .flatten()
66 .collect(),
67 vec![vec![3u8], 3.1_f32.to_be_bytes().to_vec()]
68 .into_iter()
69 .flatten()
70 .collect(),
71 vec![vec![4u8], 4.1_f64.to_be_bytes().to_vec()]
72 .into_iter()
73 .flatten()
74 .collect(),
75 vec![
76 vec![5u8], //datatype text
77 5_i32.to_be_bytes().to_vec(), //len of iotdb
78 "iotdb".to_string().as_bytes().to_vec(),
79 ]
80 .into_iter()
81 .flatten()
82 .collect(),
83 ];
84
85 for (v, bys) in values.into_iter().zip(bytes.into_iter()) {
86 let value_bys: Vec<u8> = (&v).into();
87 assert_eq!(value_bys, bys);
88 }
89 }
90}