From c1ed73871f4dad51ab7f3342ce85c67c9c5f3244 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Fri, 10 Jan 2025 22:40:32 +0000 Subject: [PATCH] jsondoclint: Support `//@ !has `. This was removed for not being used [1], but now we need it. [1]: https://github.com/rust-lang/rust/pull/133478#discussion_r1874358362 --- src/tools/jsondocck/src/main.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index b6a1d7dfa7a3a..c363a3b9533b7 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -65,6 +65,11 @@ enum CommandKind { /// Checks the path doesn't exist. HasNotPath, + /// `//@ !has ` + /// + /// Checks the path doesn't have the given value + HasNotValue { value: String }, + /// `//@ is ` /// /// Check the path is the given value. @@ -128,10 +133,11 @@ impl CommandKind { [_path, value] => Self::HasValue { value: value.clone() }, _ => panic!("`//@ has` must have 2 or 3 arguments, but got {args:?}"), }, - ("has", true) => { - assert_eq!(args.len(), 1, "args={args:?}"); - Self::HasNotPath - } + ("has", true) => match args { + [_path] => Self::HasNotPath, + [_path, value] => Self::HasNotValue { value: value.clone() }, + _ => panic!("`//@ !has` must have 2 or 3 arguments, but got {args:?}"), + }, (_, false) if KNOWN_DIRECTIVE_NAMES.contains(&command_name) => { return None; @@ -223,6 +229,19 @@ fn check_command(command: &Command, cache: &mut Cache) -> Result<(), String> { return Err(format!("matched to {matches:?}, which didn't contain {want_value:?}")); } } + CommandKind::HasNotValue { value } => { + let wantnt_value = string_to_value(value, cache); + if matches.contains(&wantnt_value.as_ref()) { + return Err(format!( + "matched to {matches:?}, which contains unwanted {wantnt_value:?}" + )); + } else if matches.is_empty() { + return Err(format!( + "got no matches, but expected some matched (not containing {wantnt_value:?}" + )); + } + } + CommandKind::Is { value } => { let want_value = string_to_value(value, cache); let matched = get_one(&matches)?;