-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]), | ||
|
@@ -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) { | ||
|
@@ -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) | ||
|