1 /* 2 * Copyright (C) 2025 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 use anyhow::Result; 18 use std::{collections::HashSet, io::Read}; 19 20 use crate::FlagId; 21 22 /// Read a list of flag names. The input is expected to be plain text, with each line containing 23 /// the name of a single flag. read_finalized_flags<R: Read>(mut reader: R) -> Result<HashSet<FlagId>>24pub(crate) fn read_finalized_flags<R: Read>(mut reader: R) -> Result<HashSet<FlagId>> { 25 let mut contents = String::new(); 26 reader.read_to_string(&mut contents)?; 27 let iter = contents.lines().map(|s| s.to_owned()); 28 Ok(HashSet::from_iter(iter)) 29 } 30 31 #[cfg(test)] 32 mod tests { 33 use super::*; 34 35 #[test] test()36 fn test() { 37 let input = include_bytes!("../tests/finalized-flags.txt"); 38 let flags = read_finalized_flags(&input[..]).unwrap(); 39 assert_eq!( 40 flags, 41 HashSet::from_iter(vec![ 42 "record_finalized_flags.test.bar".to_string(), 43 "record_finalized_flags.test.baz".to_string(), 44 ]) 45 ); 46 } 47 } 48