blob: 5414f0ea698a1c11f5a7b4b297adef5102150424 [file] [log] [blame]
Mårten Kongstad867a3492023-04-25 15:06:30 +02001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
18
Mårten Kongstad867a3492023-04-25 15:06:30 +020019use protobuf::text_format::{parse_from_str, ParseError};
20
Mårten Kongstadfe753f52023-04-26 09:13:03 +020021mod protos;
22use protos::Placeholder;
23
Mårten Kongstad867a3492023-04-25 15:06:30 +020024fn foo() -> Result<String, ParseError> {
25 let placeholder = parse_from_str::<Placeholder>(r#"name: "aconfig""#)?;
26 Ok(placeholder.name)
27}
28
29fn main() {
30 println!("{:?}", foo());
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_foo() {
39 assert_eq!("aconfig", foo().unwrap());
40 }
41
42 #[test]
43 fn test_binary_protobuf() {
44 use protobuf::Message;
45 let mut buffer = Vec::new();
46
47 let mut original = Placeholder::new();
48 original.name = "test".to_owned();
49 original.write_to_writer(&mut buffer).unwrap();
50
51 let copy = Placeholder::parse_from_reader(&mut buffer.as_slice()).unwrap();
52
53 assert_eq!(original, copy);
54 }
55}