blob: 2f7255edab3168eaf0827f54ed355110f266716a [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
19use aconfig_protos::aconfig::Placeholder;
20use protobuf::text_format::{parse_from_str, ParseError};
21
22fn foo() -> Result<String, ParseError> {
23 let placeholder = parse_from_str::<Placeholder>(r#"name: "aconfig""#)?;
24 Ok(placeholder.name)
25}
26
27fn main() {
28 println!("{:?}", foo());
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn test_foo() {
37 assert_eq!("aconfig", foo().unwrap());
38 }
39
40 #[test]
41 fn test_binary_protobuf() {
42 use protobuf::Message;
43 let mut buffer = Vec::new();
44
45 let mut original = Placeholder::new();
46 original.name = "test".to_owned();
47 original.write_to_writer(&mut buffer).unwrap();
48
49 let copy = Placeholder::parse_from_reader(&mut buffer.as_slice()).unwrap();
50
51 assert_eq!(original, copy);
52 }
53}