Skip to content

Commit 9cca35a

Browse files
committed
Move test
1 parent 70bb110 commit 9cca35a

File tree

2 files changed

+176
-161
lines changed

2 files changed

+176
-161
lines changed

internal/core/api.rs

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,3 +1574,179 @@ impl StyledText {
15741574
Ok(styled_text)
15751575
}
15761576
}
1577+
1578+
#[cfg(feature = "experimental-rich-text")]
1579+
#[test]
1580+
fn markdown_parsing() {
1581+
assert_eq!(
1582+
StyledText::parse("hello *world*").unwrap().paragraphs,
1583+
[StyledTextParagraph {
1584+
text: "hello world".into(),
1585+
formatting: std::vec![FormattedSpan { range: 6..11, style: Style::Emphasis }],
1586+
links: std::vec![]
1587+
}]
1588+
);
1589+
1590+
assert_eq!(
1591+
StyledText::parse(
1592+
"
1593+
- line 1
1594+
- line 2
1595+
"
1596+
)
1597+
.unwrap()
1598+
.paragraphs,
1599+
[
1600+
StyledTextParagraph {
1601+
text: "• line 1".into(),
1602+
formatting: std::vec![],
1603+
links: std::vec![]
1604+
},
1605+
StyledTextParagraph {
1606+
text: "• line 2".into(),
1607+
formatting: std::vec![],
1608+
links: std::vec![]
1609+
}
1610+
]
1611+
);
1612+
1613+
assert_eq!(
1614+
StyledText::parse(
1615+
"
1616+
1. a
1617+
2. b
1618+
4. c
1619+
"
1620+
)
1621+
.unwrap()
1622+
.paragraphs,
1623+
[
1624+
StyledTextParagraph {
1625+
text: "1. a".into(),
1626+
formatting: std::vec![],
1627+
links: std::vec![]
1628+
},
1629+
StyledTextParagraph {
1630+
text: "2. b".into(),
1631+
formatting: std::vec![],
1632+
links: std::vec![]
1633+
},
1634+
StyledTextParagraph {
1635+
text: "3. c".into(),
1636+
formatting: std::vec![],
1637+
links: std::vec![]
1638+
}
1639+
]
1640+
);
1641+
1642+
assert_eq!(
1643+
StyledText::parse(
1644+
"
1645+
Normal _italic_ **strong** ~~strikethrough~~ `code`
1646+
new *line*
1647+
"
1648+
)
1649+
.unwrap()
1650+
.paragraphs,
1651+
[
1652+
StyledTextParagraph {
1653+
text: "Normal italic strong strikethrough code".into(),
1654+
formatting: std::vec![
1655+
FormattedSpan { range: 7..13, style: Style::Emphasis },
1656+
FormattedSpan { range: 14..20, style: Style::Strong },
1657+
FormattedSpan { range: 21..34, style: Style::Strikethrough },
1658+
FormattedSpan { range: 35..39, style: Style::Code }
1659+
],
1660+
links: std::vec![]
1661+
},
1662+
StyledTextParagraph {
1663+
text: "new line".into(),
1664+
formatting: std::vec![FormattedSpan { range: 4..8, style: Style::Emphasis },],
1665+
links: std::vec![]
1666+
}
1667+
]
1668+
);
1669+
1670+
assert_eq!(
1671+
StyledText::parse(
1672+
"
1673+
- root
1674+
- child
1675+
- grandchild
1676+
- great grandchild
1677+
"
1678+
)
1679+
.unwrap()
1680+
.paragraphs,
1681+
[
1682+
StyledTextParagraph {
1683+
text: "• root".into(),
1684+
formatting: std::vec![],
1685+
links: std::vec![]
1686+
},
1687+
StyledTextParagraph {
1688+
text: " ◦ child".into(),
1689+
formatting: std::vec![],
1690+
links: std::vec![]
1691+
},
1692+
StyledTextParagraph {
1693+
text: " ▪ grandchild".into(),
1694+
formatting: std::vec![],
1695+
links: std::vec![]
1696+
},
1697+
StyledTextParagraph {
1698+
text: " • great grandchild".into(),
1699+
formatting: std::vec![],
1700+
links: std::vec![]
1701+
},
1702+
]
1703+
);
1704+
1705+
assert_eq!(
1706+
StyledText::parse("hello [*world*](https://example.com)").unwrap().paragraphs,
1707+
[StyledTextParagraph {
1708+
text: "hello world".into(),
1709+
formatting: std::vec![
1710+
FormattedSpan { range: 6..11, style: Style::Emphasis },
1711+
FormattedSpan { range: 6..11, style: Style::Link }
1712+
],
1713+
links: std::vec![(6..11, "https://example.com".into())]
1714+
}]
1715+
);
1716+
1717+
assert_eq!(
1718+
StyledText::parse("<u>hello world</u>").unwrap().paragraphs,
1719+
[StyledTextParagraph {
1720+
text: "hello world".into(),
1721+
formatting: std::vec![FormattedSpan { range: 0..11, style: Style::Underline },],
1722+
links: std::vec![]
1723+
}]
1724+
);
1725+
1726+
assert_eq!(
1727+
StyledText::parse(r#"<font color="blue">hello world</font>"#).unwrap().paragraphs,
1728+
[StyledTextParagraph {
1729+
text: "hello world".into(),
1730+
formatting: std::vec![FormattedSpan {
1731+
range: 0..11,
1732+
style: Style::Color(crate::Color::from_rgb_u8(0, 0, 255))
1733+
},],
1734+
links: std::vec![]
1735+
}]
1736+
);
1737+
1738+
assert_eq!(
1739+
StyledText::parse(r#"<u><font color="red">hello world</font></u>"#).unwrap().paragraphs,
1740+
[StyledTextParagraph {
1741+
text: "hello world".into(),
1742+
formatting: std::vec![
1743+
FormattedSpan {
1744+
range: 0..11,
1745+
style: Style::Color(crate::Color::from_rgb_u8(255, 0, 0))
1746+
},
1747+
FormattedSpan { range: 0..11, style: Style::Underline },
1748+
],
1749+
links: std::vec![]
1750+
}]
1751+
);
1752+
}

internal/core/textlayout/sharedparley.rs

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -833,167 +833,6 @@ impl Layout {
833833
}
834834
}
835835

836-
#[cfg(feature = "experimental-rich-text")]
837-
#[test]
838-
fn markdown_parsing() {
839-
assert_eq!(
840-
parse_markdown("hello *world*").unwrap().paragraphs,
841-
[RichTextParagraph {
842-
text: "hello world".into(),
843-
formatting: std::vec![FormattedSpan { range: 6..11, style: Style::Emphasis }],
844-
links: std::vec![]
845-
}]
846-
);
847-
848-
assert_eq!(
849-
parse_markdown(
850-
"
851-
- line 1
852-
- line 2
853-
"
854-
)
855-
.unwrap()
856-
.paragraphs,
857-
[
858-
RichTextParagraph {
859-
text: "• line 1".into(),
860-
formatting: std::vec![],
861-
links: std::vec![]
862-
},
863-
RichTextParagraph {
864-
text: "• line 2".into(),
865-
formatting: std::vec![],
866-
links: std::vec![]
867-
}
868-
]
869-
);
870-
871-
assert_eq!(
872-
parse_markdown(
873-
"
874-
1. a
875-
2. b
876-
4. c
877-
"
878-
)
879-
.unwrap()
880-
.paragraphs,
881-
[
882-
RichTextParagraph { text: "1. a".into(), formatting: std::vec![], links: std::vec![] },
883-
RichTextParagraph { text: "2. b".into(), formatting: std::vec![], links: std::vec![] },
884-
RichTextParagraph { text: "3. c".into(), formatting: std::vec![], links: std::vec![] }
885-
]
886-
);
887-
888-
assert_eq!(
889-
parse_markdown(
890-
"
891-
Normal _italic_ **strong** ~~strikethrough~~ `code`
892-
new *line*
893-
"
894-
)
895-
.unwrap()
896-
.paragraphs,
897-
[
898-
RichTextParagraph {
899-
text: "Normal italic strong strikethrough code".into(),
900-
formatting: std::vec![
901-
FormattedSpan { range: 7..13, style: Style::Emphasis },
902-
FormattedSpan { range: 14..20, style: Style::Strong },
903-
FormattedSpan { range: 21..34, style: Style::Strikethrough },
904-
FormattedSpan { range: 35..39, style: Style::Code }
905-
],
906-
links: std::vec![]
907-
},
908-
RichTextParagraph {
909-
text: "new line".into(),
910-
formatting: std::vec![FormattedSpan { range: 4..8, style: Style::Emphasis },],
911-
links: std::vec![]
912-
}
913-
]
914-
);
915-
916-
assert_eq!(
917-
parse_markdown(
918-
"
919-
- root
920-
- child
921-
- grandchild
922-
- great grandchild
923-
"
924-
)
925-
.unwrap()
926-
.paragraphs,
927-
[
928-
RichTextParagraph {
929-
text: "• root".into(),
930-
formatting: std::vec![],
931-
links: std::vec![]
932-
},
933-
RichTextParagraph {
934-
text: " ◦ child".into(),
935-
formatting: std::vec![],
936-
links: std::vec![]
937-
},
938-
RichTextParagraph {
939-
text: " ▪ grandchild".into(),
940-
formatting: std::vec![],
941-
links: std::vec![]
942-
},
943-
RichTextParagraph {
944-
text: " • great grandchild".into(),
945-
formatting: std::vec![],
946-
links: std::vec![]
947-
},
948-
]
949-
);
950-
951-
assert_eq!(
952-
parse_markdown("hello [*world*](https://example.com)").unwrap().paragraphs,
953-
[RichTextParagraph {
954-
text: "hello world".into(),
955-
formatting: std::vec![
956-
FormattedSpan { range: 6..11, style: Style::Emphasis },
957-
FormattedSpan { range: 6..11, style: Style::Link }
958-
],
959-
links: std::vec![(6..11, pulldown_cmark::CowStr::Borrowed("https://example.com"))]
960-
}]
961-
);
962-
963-
assert_eq!(
964-
parse_markdown("<u>hello world</u>").unwrap().paragraphs,
965-
[RichTextParagraph {
966-
text: "hello world".into(),
967-
formatting: std::vec![FormattedSpan { range: 0..11, style: Style::Underline },],
968-
links: std::vec![]
969-
}]
970-
);
971-
972-
assert_eq!(
973-
parse_markdown(r#"<font color="blue">hello world</font>"#).unwrap().paragraphs,
974-
[RichTextParagraph {
975-
text: "hello world".into(),
976-
formatting: std::vec![FormattedSpan {
977-
range: 0..11,
978-
style: Style::Color(Color::from_rgb_u8(0, 0, 255))
979-
},],
980-
links: std::vec![]
981-
}]
982-
);
983-
984-
assert_eq!(
985-
parse_markdown(r#"<u><font color="red">hello world</font></u>"#).unwrap().paragraphs,
986-
[RichTextParagraph {
987-
text: "hello world".into(),
988-
formatting: std::vec![
989-
FormattedSpan { range: 0..11, style: Style::Color(Color::from_rgb_u8(255, 0, 0)) },
990-
FormattedSpan { range: 0..11, style: Style::Underline },
991-
],
992-
links: std::vec![]
993-
}]
994-
);
995-
}
996-
997836
pub fn draw_text(
998837
item_renderer: &mut impl GlyphRenderer,
999838
text: Pin<&dyn crate::item_rendering::RenderText>,

0 commit comments

Comments
 (0)