diff --git a/fmt/tests/content/two_headers.rs b/fmt/tests/content/two_headers.rs new file mode 100644 index 0000000..e08923e --- /dev/null +++ b/fmt/tests/content/two_headers.rs @@ -0,0 +1,32 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file also contains some code from prometheus project. +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Implementations of `rate`, `increase` and `delta` functions in PromQL. + +use std::fmt::Display; +use std::sync::Arc; diff --git a/fmt/tests/tests.rs b/fmt/tests/tests.rs index 737698e..ee2e9c7 100644 --- a/fmt/tests/tests.rs +++ b/fmt/tests/tests.rs @@ -14,10 +14,7 @@ use std::path::Path; -use hawkeye_fmt::header::{ - model::default_headers, - parser::parse_header, -}; +use hawkeye_fmt::header::{model::default_headers, parser::parse_header}; #[test] fn test_remove_file_only_header() { @@ -26,8 +23,21 @@ fn test_remove_file_only_header() { let def = defs.get("script_style").unwrap().clone(); let keywords = vec!["copyright".to_string()]; - let document = parse_header(&file, def, &keywords).unwrap(); + let document = parse_header(file, def, &keywords).unwrap(); let end_pos = document.end_pos.unwrap(); let content = document.file_content.content(); assert!(content[end_pos..].trim().is_empty()); } + +#[test] +fn test_two_headers_should_only_remove_the_first() { + let file = Path::new("tests/content/two_headers.rs"); + let defs = default_headers().unwrap(); + let def = defs.get("doubleslash_style").unwrap().clone(); + let keywords = vec!["copyright".to_string()]; + + let document = parse_header(file, def, &keywords).unwrap(); + let end_pos = document.end_pos.unwrap(); + let content = document.file_content.content(); + assert!(content[end_pos..].contains("Copyright 2015 The Prometheus Authors")); +} diff --git a/licenserc.toml b/licenserc.toml index 7969989..36e579b 100644 --- a/licenserc.toml +++ b/licenserc.toml @@ -16,6 +16,7 @@ headerPath = "Apache-2.0.txt" excludes = [ "*.txt", + "**/tests/content/**", ] [properties]