Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions meta/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,13 @@
"properties": {
"$id": false,
"$comment": {
"$ref": "#/$defs/clean-prose"
"$ref": "../schemas/misc/single-line-text.json"
},
"title": {
"$ref": "#/$defs/clean-prose"
"$ref": "../schemas/misc/single-line-text.json"
},
"description": {
"$ref": "#/$defs/clean-prose"
}
},
"$defs": {
"clean-prose": {
"type": "string",
"not": {
"anyOf": [
{
"pattern": "\\.$"
},
{
"pattern": " \\s"
},
{
"pattern": "[\\n\\r\\t]"
},
{
"pattern": "[\\x00-\\x1F\\x7F]"
}
]
},
"pattern": "^[^\\s].*[^\\s]$|^[^\\s]$"
"$ref": "../schemas/misc/single-line-text.json"
}
}
}
15 changes: 15 additions & 0 deletions schemas/misc/single-line-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Single-line Text",
"description": "A string representing a single line of clean text without leading or trailing whitespace, excessive internal spacing, non-printable characters, newlines, tabs, trailing periods, or other punctuation issues",
"examples": [
"This is a simple text",
"Multiple sentences work fine",
"Numbers and symbols: 123 $%&",
"Unicode characters are allowed: café, 日本語"
],
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
"x-links": [ "https://en.wikipedia.org/wiki/String_(computer_science)" ],
"type": "string",
"pattern": "^(?!.*\\.$)(?!.*(?<!\\.)\\.\\.(?!\\.))(?!.* [.,;:!?])(?![?!])(?!.*[?!])(?!.* )(?!.*\\(\\))(?!.*\\[\\])(?!.*--)(?!.*[\\n\\r\\t])(?!.*[\\x00-\\x1F\\x7F])[^\\s](?:.*[^\\s])?$"
}
341 changes: 341 additions & 0 deletions test/misc/single-line-text.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
{
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
"target": "../../schemas/misc/single-line-text.json",
"tests": [
{
"description": "Valid - simple text",
"data": "This is valid text",
"valid": true
},
{
"description": "Valid - single word",
"data": "Word",
"valid": true
},
{
"description": "Valid - single character",
"data": "a",
"valid": true
},
{
"description": "Valid - text with single spaces",
"data": "Multiple words with spaces",
"valid": true
},
{
"description": "Invalid - two consecutive spaces",
"data": "Two spaces",
"valid": false
},
{
"description": "Valid - numbers and symbols",
"data": "Text with 123 and $%& symbols",
"valid": true
},
{
"description": "Valid - Unicode characters",
"data": "café 日本語 emoji 🎉",
"valid": true
},
{
"description": "Valid - multiple sentences without trailing period",
"data": "First sentence. Second sentence. Third one",
"valid": true
},
{
"description": "Valid - text with period in middle",
"data": "Dr. Smith works here",
"valid": true
},
{
"description": "Valid - abbreviations",
"data": "U.S.A. and U.K. are countries",
"valid": true
},
{
"description": "Invalid - trailing period",
"data": "Text with trailing period.",
"valid": false
},
{
"description": "Invalid - just a period",
"data": ".",
"valid": false
},
{
"description": "Invalid - leading whitespace",
"data": " Leading space",
"valid": false
},
{
"description": "Invalid - trailing whitespace",
"data": "Trailing space ",
"valid": false
},
{
"description": "Invalid - leading tab",
"data": "\tTabbed text",
"valid": false
},
{
"description": "Invalid - trailing tab",
"data": "Text with tab\t",
"valid": false
},
{
"description": "Invalid - tab in middle",
"data": "Text with\ttab",
"valid": false
},
{
"description": "Invalid - newline in middle",
"data": "Text with\nnewline",
"valid": false
},
{
"description": "Invalid - carriage return in middle",
"data": "Text with\rcarriage return",
"valid": false
},
{
"description": "Invalid - multiple newlines",
"data": "Line one\nLine two\nLine three",
"valid": false
},
{
"description": "Invalid - three consecutive spaces",
"data": "Three spaces",
"valid": false
},
{
"description": "Invalid - four consecutive spaces",
"data": "Four spaces",
"valid": false
},
{
"description": "Invalid - many consecutive spaces",
"data": "Many spaces",
"valid": false
},
{
"description": "Invalid - null character",
"data": "Text with\u0000null",
"valid": false
},
{
"description": "Invalid - bell character",
"data": "Text with\u0007bell",
"valid": false
},
{
"description": "Invalid - backspace character",
"data": "Text with\bbackspace",
"valid": false
},
{
"description": "Invalid - form feed",
"data": "Text with\fform feed",
"valid": false
},
{
"description": "Invalid - vertical tab",
"data": "Text with\u000Bvertical tab",
"valid": false
},
{
"description": "Invalid - escape character",
"data": "Text with\u001Bescape",
"valid": false
},
{
"description": "Invalid - delete character",
"data": "Text withdelete",
"valid": false
},
{
"description": "Invalid - empty string",
"data": "",
"valid": false
},
{
"description": "Invalid - only whitespace",
"data": " ",
"valid": false
},
{
"description": "Invalid - only tab",
"data": "\t",
"valid": false
},
{
"description": "Invalid - only newline",
"data": "\n",
"valid": false
},
{
"description": "Invalid type - number",
"data": 123,
"valid": false
},
{
"description": "Invalid type - boolean",
"data": true,
"valid": false
},
{
"description": "Invalid type - null",
"data": null,
"valid": false
},
{
"description": "Invalid type - array",
"data": [],
"valid": false
},
{
"description": "Invalid type - object",
"data": {},
"valid": false
},
{
"description": "Invalid - double period",
"data": "Text with.. double period",
"valid": false
},
{
"description": "Invalid - double period at end",
"data": "Text ends here..",
"valid": false
},
{
"description": "Valid - proper ellipsis",
"data": "Text with... ellipsis",
"valid": true
},
{
"description": "Valid - ellipsis in parentheses",
"data": "The duration component accepts designator format (P...) and weeks format (PnW)",
"valid": true
},
{
"description": "Invalid - space before period",
"data": "Text with space .",
"valid": false
},
{
"description": "Invalid - space before comma",
"data": "Text with space ,",
"valid": false
},
{
"description": "Invalid - space before semicolon",
"data": "Text with space ;",
"valid": false
},
{
"description": "Invalid - space before colon",
"data": "Text with space :",
"valid": false
},
{
"description": "Invalid - space before exclamation",
"data": "Text with space !",
"valid": false
},
{
"description": "Invalid - space before question mark",
"data": "Text with space ?",
"valid": false
},
{
"description": "Invalid - question mark at start",
"data": "?This is a question",
"valid": false
},
{
"description": "Invalid - exclamation mark at start",
"data": "!This is excitement",
"valid": false
},
{
"description": "Invalid - question mark in middle",
"data": "Text with ? question mark",
"valid": false
},
{
"description": "Invalid - exclamation mark in middle",
"data": "Text with ! exclamation",
"valid": false
},
{
"description": "Invalid - question mark at end",
"data": "Is this a question?",
"valid": false
},
{
"description": "Invalid - exclamation mark at end",
"data": "This is exciting!",
"valid": false
},
{
"description": "Invalid - double exclamation",
"data": "Very exciting!!",
"valid": false
},
{
"description": "Invalid - double question mark",
"data": "Really??",
"valid": false
},
{
"description": "Invalid - empty parentheses",
"data": "Text with () empty parens",
"valid": false
},
{
"description": "Invalid - empty brackets",
"data": "Text with [] empty brackets",
"valid": false
},
{
"description": "Invalid - double hyphen",
"data": "Text with -- double hyphen",
"valid": false
},
{
"description": "Valid - em dash",
"data": "Text with — em dash",
"valid": true
},
{
"description": "Valid - single hyphen",
"data": "Text with single-hyphen word",
"valid": true
},
{
"description": "Valid - parentheses with content",
"data": "Text with (content) in parens",
"valid": true
},
{
"description": "Valid - brackets with content",
"data": "Text with [content] in brackets",
"valid": true
},
{
"description": "Valid - proper comma usage",
"data": "First item, second item, third item",
"valid": true
},
{
"description": "Valid - proper colon usage",
"data": "Title: Subtitle",
"valid": true
},
{
"description": "Valid - proper semicolon usage",
"data": "First clause; second clause",
"valid": true
}
]
}