mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 13:05:32 +09:00
chore(repo): remove dead code and useless tests (#3375)
This commit is contained in:
1 parent
7e177a1c90
commit
1cd62eb661
1391 files changed
+783
-120415
No files matched your search
@@ -12,10 +12,6 @@ crate-type = ["cdylib", "rlib"]
|
||||
name = "parser"
|
||||
harness = false
|
||||
|
||||
[[bin]]
|
||||
name = "markdown-stress"
|
||||
path = "src/bin/stress.rs"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use fluxer_markdown_parser::{EmojiContext, MarkdownParser, ParserFlags};
|
||||
|
||||
fn main() {
|
||||
let cases = std::env::var("MARKDOWN_STRESS_CASES")
|
||||
.ok()
|
||||
.and_then(|value| value.parse::<usize>().ok())
|
||||
.unwrap_or(10_000);
|
||||
let mut seed = 0x5eed_c0de_u64;
|
||||
for _ in 0..cases {
|
||||
let input = generate_case(&mut seed);
|
||||
let mut parser = MarkdownParser::new(ParserFlags::ALL, EmojiContext::default());
|
||||
let nodes = parser.parse(&input).expect("stress parse should not fail");
|
||||
assert!(serde_json::to_string(&nodes).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_case(seed: &mut u64) -> String {
|
||||
const ATOMS: &[&str] = &[
|
||||
"plain",
|
||||
"# Heading",
|
||||
"||spoiler||",
|
||||
"**strong**",
|
||||
"*em*",
|
||||
"__under__",
|
||||
"`code`",
|
||||
"[same](https://example.com/path)",
|
||||
"https://example.com",
|
||||
"<https://example.com>",
|
||||
"<[email protected]>",
|
||||
"<@123>",
|
||||
"@everyone",
|
||||
"<t:1234567890:R>",
|
||||
":smile:",
|
||||
"😄",
|
||||
"<:blob:123456789012345678>",
|
||||
"| a | b |\n| - | - |\n| c | d |",
|
||||
];
|
||||
const SEPARATORS: &[&str] = &[" ", "\n", "\n\n", ".", "(", ")"];
|
||||
let count = 1 + (next(seed) as usize % 8);
|
||||
let mut input = String::new();
|
||||
for part in 0..count {
|
||||
if part > 0 {
|
||||
input.push_str(SEPARATORS[next(seed) as usize % SEPARATORS.len()]);
|
||||
}
|
||||
input.push_str(ATOMS[next(seed) as usize % ATOMS.len()]);
|
||||
}
|
||||
input
|
||||
}
|
||||
|
||||
fn next(seed: &mut u64) -> u64 {
|
||||
*seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
|
||||
*seed
|
||||
}
|
||||
@@ -9,14 +9,6 @@ fn parse(input: &str) -> serde_json::Value {
|
||||
serde_json::to_value(nodes).expect("serialize succeeds")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_after_fence_is_content_not_language() {
|
||||
assert_eq!(
|
||||
parse("``` hello\n```"),
|
||||
json!([{"type":"CodeBlock","content":" hello\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_after_fence_keeps_following_lines() {
|
||||
assert_eq!(
|
||||
@@ -25,102 +17,6 @@ fn space_after_fence_keeps_following_lines() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_after_fence_is_content_not_language() {
|
||||
assert_eq!(
|
||||
parse("```\thello\n```"),
|
||||
json!([{"type":"CodeBlock","content":"\thello\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_spaces_after_fence_are_preserved_as_content() {
|
||||
assert_eq!(
|
||||
parse("``` rust\nfn main() {}\n```"),
|
||||
json!([{"type":"CodeBlock","content":" rust\nfn main() {}\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_before_otherwise_valid_language_chars_is_content() {
|
||||
assert_eq!(
|
||||
parse("``` c++\nx\n```"),
|
||||
json!([{"type":"CodeBlock","content":" c++\nx\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_before_known_multi_token_language_is_content() {
|
||||
assert_eq!(
|
||||
parse("``` js code\n```"),
|
||||
json!([{"type":"CodeBlock","content":" js code\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_after_fence_disables_ansi_language() {
|
||||
assert_eq!(
|
||||
parse("``` ansi\n\u{1b}[31mhi\u{1b}[0m\n```"),
|
||||
json!([{"type":"CodeBlock","content":" ansi\n\u{1b}[31mhi\u{1b}[0m\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_after_longer_fence_is_content() {
|
||||
assert_eq!(
|
||||
parse("```` rust\ncode\n````"),
|
||||
json!([{"type":"CodeBlock","content":" rust\ncode\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn language_immediately_after_fence_is_detected() {
|
||||
assert_eq!(
|
||||
parse("```hello\n```"),
|
||||
json!([{"type":"Text","content":"```hello\n```"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn common_language_with_body_is_detected() {
|
||||
assert_eq!(
|
||||
parse("```js\ncode\n```"),
|
||||
json!([{"type":"CodeBlock","language":"js","content":"code\n"}])
|
||||
);
|
||||
assert_eq!(
|
||||
parse("```rust\nfn main() {}\n```"),
|
||||
json!([{"type":"CodeBlock","language":"rust","content":"fn main() {}\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn languages_with_special_characters_are_detected() {
|
||||
assert_eq!(
|
||||
parse("```c#\nx\n```"),
|
||||
json!([{"type":"CodeBlock","language":"c#","content":"x\n"}])
|
||||
);
|
||||
assert_eq!(
|
||||
parse("```c++\nx\n```"),
|
||||
json!([{"type":"CodeBlock","language":"c++","content":"x\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ansi_language_immediately_after_fence_is_detected() {
|
||||
assert_eq!(
|
||||
parse("```ansi\n\u{1b}[31mhi\u{1b}[0m\n```"),
|
||||
json!([{"type":"CodeBlock","language":"ansi","content":"\u{1b}[31mhi\u{1b}[0m\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn known_multi_token_language_without_leading_space_is_detected() {
|
||||
assert_eq!(
|
||||
parse("```js code\n```"),
|
||||
json!([{"type":"Text","content":"```js code\n```"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bare_fence_has_no_language() {
|
||||
assert_eq!(
|
||||
@@ -129,34 +25,6 @@ fn bare_fence_has_no_language() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_fenced_block_has_no_language_and_empty_body() {
|
||||
assert_eq!(
|
||||
parse("```\n```"),
|
||||
json!([{"type":"Text","content":"```\n```"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_multi_token_info_string_is_content() {
|
||||
assert_eq!(
|
||||
parse("```hello world\n```"),
|
||||
json!([{"type":"CodeBlock","content":"hello world\n"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitespace_only_info_string_is_content() {
|
||||
assert_eq!(
|
||||
parse("``` \nfoo\n```"),
|
||||
json!([{"type":"CodeBlock","content":" \nfoo\n"}])
|
||||
);
|
||||
assert_eq!(
|
||||
parse("``` \n```"),
|
||||
json!([{"type":"Text","content":"``` \n```"}])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_line_fence_with_space_is_content() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user