Skip to content

Commit

Permalink
test: test_two_headers_should_only_remove_the_first
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Mar 24, 2024
1 parent 614e153 commit 316ff82
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
32 changes: 32 additions & 0 deletions fmt/tests/content/two_headers.rs
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 15 additions & 5 deletions fmt/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"));
}
1 change: 1 addition & 0 deletions licenserc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ headerPath = "Apache-2.0.txt"

excludes = [
"*.txt",
"**/tests/content/**",
]

[properties]
Expand Down

0 comments on commit 316ff82

Please sign in to comment.