Skip to content

Commit

Permalink
Add tests for t-010
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 authored and acabal committed Jun 22, 2024
1 parent c60b1db commit db23ebe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2325,15 +2325,15 @@ def _lint_xhtml_typography_checks(filename: Path, dom: se.easy_xml.EasyXmlTree,
node.remove()

nodes = dom_copy.xpath("/html/body//p[re:test(., '[^=]\\s[0-9]{1,2}\\.[0-9]{2}(?![0-9′″°%]|\\.[0-9]|\\scubic|\\smetric|\\smeters|\\smiles|\\sfeet|\\sinches)')]")
matches = []
matches = set()
for node in nodes:
for time_match in regex.findall(r"(?<=[^=]\s)[0-9]{1,2}\.[0-9]{2}(?![0-9′″°%]|\.[0-9]|\scubic|\smetric|\smeters|\smiles|\sfeet|\sinches)", node.inner_text()):
time = time_match.split(".")
if not time[0].startswith("0") and int(time[0]) >= 1 and int(time[0]) <= 12 and int(time[1]) >= 0 and int(time[1]) <= 59:
matches.append(time_match)
matches.add(time_match)

if matches:
messages.append(LintMessage("t-010", "Time set with [text].[/] instead of [text]:[/].", se.MESSAGE_TYPE_WARNING, filename, set(matches)))
messages.append(LintMessage("t-010", "Time set with [text].[/] instead of [text]:[/].", se.MESSAGE_TYPE_WARNING, filename, natsorted(list(matches))))

# Check for missing punctuation before closing quotes
# Exclude signatures in footers as those are commonly quoted without ending punctuation
Expand Down
3 changes: 3 additions & 0 deletions tests/lint/typography/t-010/golden/t-010-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t-010 [Manual Review] chapter-1.xhtml Time set with `.` instead of `:`.
1.00
12.59
45 changes: 45 additions & 0 deletions tests/lint/typography/t-010/in/src/epub/text/chapter-1.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" epub:prefix="z3998: http://www.daisy.org/z3998/2012/vocab/structure/" xml:lang="en-GB">
<head>
<title>I</title>
<link href="../css/core.css" rel="stylesheet" type="text/css"/>
<link href="../css/local.css" rel="stylesheet" type="text/css"/>
</head>
<body epub:type="bodymatter z3998:fiction">
<section id="chapter-1" epub:type="chapter">
<h2 epub:type="ordinal z3998:roman">I</h2>
<!-- invalid -->
<p>It is 1.00.</p>
<p>It is 12.59.</p>

<!-- valid -->
<!-- correct use of : -->
<p>It is 1:00.</p>
<!-- preceded by 0 -->
<p>It is 02.00.</p>
<!-- preceded by = -->
<p>X = 3.00.</p>
<!-- hour component too large to be a time -->
<p>It is 13.00.</p>
<!-- not preceded by space -->
<p>It cost $12.00.</p>
<!-- too many digits in the minute component -->
<p>It is 4.001.</p>
<!-- minute component too large to be a time -->
<p>It is 4.60.</p>
<!-- succeeded by units -->
<p>It is 4.01 cubic.</p>
<p>It is 4.01 metric.</p>
<p>It is 4.01 meters.</p>
<p>It is 4.01 miles.</p>
<p>It is 4.01 feet.</p>
<p>It is 4.01 inches.</p>
<p>It is 4.01′.</p>
<p>It is 4.01″.</p>
<p>It is 4.01°.</p>
<p>It is 4.01%.</p>
<!-- inside anchor -->
<p>See <a href="#">section 4.02</a>.</p>
</section>
</body>
</html>

0 comments on commit db23ebe

Please sign in to comment.