use crate::tests::prelude::*;
track_file!("ref/asciidoc-lang/docs/modules/tables/pages/assign-a-role.adoc");
fn parse_table(source: &str) -> crate::blocks::TableBlock<'_> {
let mut parser = Parser::default();
let mi = crate::blocks::Block::parse(crate::Span::new(source), &mut parser)
.unwrap_if_no_warnings()
.unwrap();
match mi.item {
crate::blocks::Block::Table(table) => table,
other => panic!("expected a table block, got {other:?}"),
}
}
const BASE: &str = "|===\n|Cell in column 1, row 1\n|Cell in column 2, row 1\n|===";
non_normative!(
r#"
= Assign a Role to a Table
"#
);
#[test]
fn role_attribute() {
verifies!(
r#"
Like with all blocks, you can add a role to a table using the `role` attribute.
"#
);
let src = format!("[role=name-of-role]\n{BASE}");
let table = parse_table(&src);
assert_eq!(table.roles(), vec!["name-of-role"]);
let src = format!("[role=\"role-one role-two\"]\n{BASE}");
let table = parse_table(&src);
assert_eq!(table.roles(), vec!["role-one", "role-two"]);
non_normative!(
r#"
The role attribute becomes a CSS class when converted to HTML.
"#
);
}
#[test]
fn role_shorthand() {
verifies!(
r#"
The preferred shorthand for assigning the role attribute is to put the role name in the first position of the block attribute list prefixed with a `.` character, as shown here:
[source]
----
[.name-of-role]
include::example$table.adoc[tag=base]
----
"#
);
let src = format!("[.name-of-role]\n{BASE}");
let table = parse_table(&src);
assert_eq!(table.roles(), vec!["name-of-role"]);
}