]> git.lizzy.rs Git - rust.git/blobdiff - rustfmt-core/tests/lib.rs
Update configuration tests
[rust.git] / rustfmt-core / tests / lib.rs
index f219cf3212b9b0d5065a7bfc01da55075eb32352..00988dc6fc5ce40d4e9d466770790c5e4b7fd773 100644 (file)
@@ -17,7 +17,7 @@
 extern crate rustfmt_core as rustfmt;
 extern crate term;
 
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
 use std::fs;
 use std::io::{self, BufRead, BufReader, Read};
 use std::iter::{Enumerate, Peekable};
@@ -795,6 +795,7 @@ fn formatted_is_idempotent(&self) -> bool {
     fn extract<I: Iterator<Item = String>>(
         file: &mut Enumerate<I>,
         prev: Option<&ConfigCodeBlock>,
+        hash_set: &mut HashSet<String>,
     ) -> Option<ConfigCodeBlock> {
         let mut code_block = ConfigCodeBlock::new();
         code_block.config_name = prev.and_then(|cb| cb.config_name.clone());
@@ -806,6 +807,16 @@ fn extract<I: Iterator<Item = String>>(
                     break;
                 }
                 Some(ConfigurationSection::ConfigName(name)) => {
+                    assert!(
+                        Config::is_valid_name(&name),
+                        "an unknown configuration option was found: {}",
+                        name
+                    );
+                    assert!(
+                        hash_set.remove(&name),
+                        "multiple configuration guides found for option {}",
+                        name
+                    );
                     code_block.set_config_name(Some(name));
                 }
                 Some(ConfigurationSection::ConfigValue(value)) => {
@@ -831,11 +842,20 @@ fn get_code_blocks() -> Vec<ConfigCodeBlock> {
             .map(|l| l.unwrap())
             .enumerate();
         let mut code_blocks: Vec<ConfigCodeBlock> = Vec::new();
+        let mut hash_set = Config::hash_set();
 
-        while let Some(cb) = ConfigCodeBlock::extract(&mut file_iter, code_blocks.last()) {
+        while let Some(cb) =
+            ConfigCodeBlock::extract(&mut file_iter, code_blocks.last(), &mut hash_set)
+        {
             code_blocks.push(cb);
         }
 
+        for name in hash_set {
+            if !Config::is_hidden_option(&name) {
+                panic!("{} does not have a configuration guide", name);
+            }
+        }
+
         code_blocks
     }