Skip to content

Commit

Permalink
Spec-driven development: Lines (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten authored Dec 31, 2023
1 parent c193673 commit 70ac783
Showing 1 changed file with 115 additions and 37 deletions.
152 changes: 115 additions & 37 deletions src/tests/asciidoc_lang/root/document_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,43 +242,121 @@ mod documents {
}
}

// == Lines

// The line is a significant construct in AsciiDoc.
// A line is defined as text that's separated on either side by either a newline
// character or the boundary of the document. Many aspects of the syntax must
// occupy a whole line. That's why we say AsciiDoc is a line-oriented language.

// For example, a section title must be on a line by itself.
// The same is true for an attribute entry, a block title, a block attribute
// list, a block macro, a list item, a block delimiter, and so forth.

// .Example of a section title, which must occupy a single line
// [source]
// ----
// == Section Title
// ----

// .Example of an attribute entry, which must also occupy at least one line
// [source]
// -----
// :name: value
// -----

// .Example of an attribute entry that extends to two lines
// [source]
// -----
// :name: value \
// more value
// -----

// Empty lines can also be significant.
// A single empty line separates the header from the body.
// Many blocks are also separated by an empty line, as you saw in the two
// paragraph example earlier.

// In contrast, lines within paragraph content are insignificant.
// Keep these points in mind as you're learning about the AsciiDoc syntax.
mod lines {
use pretty_assertions_sorted::assert_eq;

use crate::{
document::Attribute,
primitives::line,
tests::fixtures::{
document::{TAttribute, TAttributeValue},
TSpan,
},
Span,
};

#[test]
fn section_title() {
// == Lines

// The line is a significant construct in AsciiDoc.
// A line is defined as text that's separated on either side by either a newline
// character or the boundary of the document. Many aspects of the syntax must
// occupy a whole line. That's why we say AsciiDoc is a line-oriented language.

// For example, a section title must be on a line by itself.
// The same is true for an attribute entry, a block title, a block attribute
// list, a block macro, a list item, a block delimiter, and so forth.

// .Example of a section title, which must occupy a single line
// [source]
// ----
// == Section Title
// ----

let (rem, line) = line(Span::new("== Section Title\n", true)).unwrap();

assert_eq!(
rem,
TSpan {
data: "",
line: 2,
col: 1,
offset: 17
}
);

assert_eq!(
line,
TSpan {
data: "== Section Title",
line: 1,
col: 1,
offset: 0
}
);
}

#[test]
fn one_line_attribute() {
// .Example of an attribute entry, which must also occupy at least one line
// [source]
// -----
// :name: value
// -----

let (rem, attr) = Attribute::parse(Span::new(":name: value\n", true)).unwrap();

assert_eq!(
rem,
TSpan {
data: "",
line: 2,
col: 1,
offset: 13
}
);

assert_eq!(
attr,
TAttribute {
name: TSpan {
data: "name",
line: 1,
col: 2,
offset: 1,
},
value: TAttributeValue::Value(TSpan {
data: "value",
line: 1,
col: 8,
offset: 7,
}),
source: TSpan {
data: ":name: value\n",
line: 1,
col: 1,
offset: 0,
}
}
);
}

// .Example of an attribute entry that extends to two lines
// [source]
// -----
// :name: value \
// more value
// -----

// Empty lines can also be significant.
// A single empty line separates the header from the body.
// Many blocks are also separated by an empty line, as you saw in the two
// paragraph example earlier.

// In contrast, lines within paragraph content are insignificant.
// Keep these points in mind as you're learning about the AsciiDoc syntax.
}

// == Blocks

Expand Down

0 comments on commit 70ac783

Please sign in to comment.