pos_lines

Crates.iopos_lines
lib.rspos_lines
version
sourcesrc
created_at2024-10-26 22:16:19.432423
updated_at2024-10-30 07:20:31.637292
descriptionpos_lines
homepagehttps://github.com/i18n-site/rust/tree/main/pos_lines
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1424186
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
i18n.site (i18nsite)

documentation

README

pos_lines

use pos_lines::PosLines;

#[test]
fn test_comment() {
  let text = "<!-- 这是\n多行注释\n-->没有内容<!---->";
  let lines: Vec<_> = PosLines::new(text).collect();

  assert_eq!(
    lines,
    [
      (0, "<!-- 这是",),
      (12, "多行注释",),
      (25, "-->没有内容<!---->",)
    ]
  );
}

#[test]
fn test_empty_text() {
  let text = "";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![]);
}

#[test]
fn test_single_line() {
  let text = "Hello World";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "Hello World")]);
}

#[test]
fn test_multiple_lines() {
  let text = "Line 1\nLine 2\nLine 3";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "Line 1"), (7, "Line 2"), (14, "Line 3"),]);
}

#[test]
fn test_empty_lines() {
  let text = "Line 1\n\nLine 3";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "Line 1"), (8, "Line 3"),]);
}

#[test]
fn test_mixed_line_endings() {
  let text = "Line 1\r\nLine 2\rLine 3\nLine 4";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(
    lines,
    vec![(0, "Line 1"), (8, "Line 2"), (15, "Line 3"), (22, "Line 4"),]
  );
}

#[test]
fn test_consecutive_line_endings() {
  let text = "Line 1\r\r\nLine 2\n\n\nLine 3";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "Line 1"), (9, "Line 2"), (18, "Line 3"),]);
}

#[test]
fn test_starting_with_newlines() {
  let text = "\n\r\nLine 1\nLine 2";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(3, "Line 1"), (10, "Line 2"),]);
}

#[test]
fn test_ending_with_newlines() {
  let text = "Line 1\nLine 2\n\r\n";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "Line 1"), (7, "Line 2"),]);
}

#[test]
fn test_chinese_characters() {
  let text = "你好\n世界\r\n测试";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![(0, "你好"), (7, "世界"), (15, "测试"),]);
}

#[test]
fn test_only_newlines() {
  let text = "\n\r\n\r\n";
  let lines: Vec<_> = PosLines::new(text).collect();
  assert_eq!(lines, vec![]);
}

#[test]
fn test() {
  let text = "前面的文字\n```\n这是代码块\n包含多行\n```\n后面的文字";
  for (pos, line) in PosLines::new(text) {
    println!("{}: >{}<", pos, line);
  }
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 22

cargo fmt