Skip to content

Commit

Permalink
Convert badge to badges
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 24, 2024
1 parent f2d71f6 commit 153482f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 60 deletions.
4 changes: 2 additions & 2 deletions schema/v1/resources.schema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v1/resources.schema.json",
"title": "Source Control Repository",
"description": "An Extension is provided by a distribution.",
"title": "Resources",
"description": "Resources related to this distribution.",
"type": "object",
"properties": {
"homepage": {
Expand Down
29 changes: 0 additions & 29 deletions schema/v2/badge.schema.json

This file was deleted.

35 changes: 35 additions & 0 deletions schema/v2/badges.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v2/badges.schema.json",
"title": "Badges",
"description": "*Badges* represents links to a [Shields](https://github.com/badges/shields/blob/master/spec/SPECIFICATION.md \"Shields badge specification\")-conformant badges.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"src": {
"type": "string",
"format": "uri",
"description": "The URI for the badge."
},
"alt": {
"type": "string",
"minLength": 4,
"maxLength": 4048,
"description": "Alternate text for accessability."
}
},
"required": ["src", "alt"],
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false
},
"examples": [
[
{
"alt": "Test Status",
"src": "https://test.packages.postgresql.org/github.com/example/pair.svg"
}
]
]
}
76 changes: 47 additions & 29 deletions tests/v2_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ fn test_v2_platforms() -> Result<(), Box<dyn Error>> {
json!(["linux/amd64"]),
json!(["x86_64"]),
json!(["darwin_23.5.0_arm64"]),
json!([]),
json!([null]),
json!(["0"]),
json!([0]),
Expand Down Expand Up @@ -2169,26 +2170,37 @@ fn test_v2_variations() -> Result<(), Box<dyn Error>> {
}

#[test]
fn test_v2_badge() -> Result<(), Box<dyn Error>> {
fn test_v2_badges() -> Result<(), Box<dyn Error>> {
// Load the schemas and compile the maintainer schema.
let mut compiler = new_compiler("schema/v2")?;
let mut schemas = Schemas::new();
let id = id_for(SCHEMA_VERSION, "badge");
let id = id_for(SCHEMA_VERSION, "badges");
let idx = compiler.compile(&id, &mut schemas)?;

for valid in [
("short", json!({"src": "x:y", "alt": "food"})),
("short", json!([{"src": "x:y", "alt": "food"}])),
(
"long",
json!({
json!([{
"src": "https://github.com/theory/kv-pair/workflows/CI/badge.svg",
"alt": "CI/CD Test Status",
}),
}]),
),
(
"multi",
json!([
{"src": "x:y", "alt": "food"},
{"src": "a:b", "alt": "tests"},
{"src": "mailto:[email protected]", "alt": "Contact Me!"},
]),
),
(
"custom x_",
json!([{"src": "x:y", "alt": "food", "x_y": 1}]),
),
("custom x_", json!({"src": "x:y", "alt": "food", "x_y": 1})),
(
"custom X_",
json!({"src": "x:y", "alt": "food", "X_z": true}),
json!([{"src": "x:y", "alt": "food", "X_z": true}]),
),
] {
if let Err(e) = schemas.validate(&valid.1, idx) {
Expand All @@ -2197,35 +2209,41 @@ fn test_v2_badge() -> Result<(), Box<dyn Error>> {
}

for invalid in [
("array", json!([])),
("empty array", json!([])),
("string", json!("web")),
("empty string", json!("")),
("true", json!(true)),
("false", json!(false)),
("null", json!(null)),
("empty object", json!({})),
("only x_", json!({"x_y": 0})),
("only X_", json!({"X_y": 0})),
("bare x_", json!({"src": "x:y", "alt": "food", "x_": 0})),
("bare X_", json!({"src": "x:y", "alt": "food", "x_": 0})),
("unknown", json!({"src": "x:y", "alt": "food", "foo": 0})),
("object", json!({})),
("empty item", json!([{}])),
("array item", json!([[]])),
("string item", json!([""])),
("null item", json!([null])),
("number item", json!([42])),
("bool item", json!([true])),
("only x_", json!([{"x_y": 0}])),
("only X_", json!([{"X_y": 0}])),
("bare x_", json!([{"src": "x:y", "alt": "food", "x_": 0}])),
("bare X_", json!([{"src": "x:y", "alt": "food", "x_": 0}])),
("unknown", json!([{"src": "x:y", "alt": "food", "foo": 0}])),
// src
("src array", json!({"src": []})),
("src object", json!({"src": {}})),
("src empty", json!({"src": ""})),
("src bool", json!({"src": true})),
("src number", json!({"src": 42})),
("src null", json!({"src": null})),
("src invalid", json!({"src": "xyz"})),
("src invalid", json!({"src": "not a uri"})),
("src array", json!([{"alt": "abcd", "src": []}])),
("src object", json!([{"alt": "abcd", "src": {}}])),
("src empty", json!([{"alt": "abcd", "src": ""}])),
("src bool", json!([{"alt": "abcd", "src": true}])),
("src number", json!([{"alt": "abcd", "src": 42}])),
("src null", json!([{"alt": "abcd", "src": null}])),
("src invalid", json!([{"alt": "abcd", "src": "xyz"}])),
("src invalid", json!([{"alt": "abcd", "src": "not a uri"}])),
// alt
("alt array", json!({"alt": []})),
("alt object", json!({"alt": {}})),
("alt empty", json!({"alt": ""})),
("alt bool", json!({"alt": true})),
("alt number", json!({"alt": 42})),
("alt null", json!({"alt": null})),
("alt too short", json!({"alt": ["xyz"]})),
("alt array", json!([{"src": "x:y", "alt": []}])),
("alt object", json!([{"src": "x:y", "alt": {}}])),
("alt empty", json!([{"src": "x:y", "alt": ""}])),
("alt bool", json!([{"src": "x:y", "alt": true}])),
("alt number", json!([{"src": "x:y", "alt": 42}])),
("alt null", json!([{"src": "x:y", "alt": null}])),
("alt too short", json!([{"src": "x:y", "alt": ["xyz"]}])),
] {
if schemas.validate(&invalid.1, idx).is_ok() {
panic!("{} unexpectedly passed!", invalid.0)
Expand Down

0 comments on commit 153482f

Please sign in to comment.